如何在c#中的PSM wav文件中转换ADPCM wav文件

时间:2014-08-11 14:57:06

标签: c# converter wav

我有下一个代码在PCM wave中转换ADPCM wav如何在没有中间存储文件的情况下执行此操作 WaveFileWriter.CreateWaveFile("D:\\pcm16000.wav", upsampler);

public static byte [] ADPcmToPcm(string waveFileName,int bitRate = 128)         {

        using (var reader = new WaveFileReader(waveFileName))
        using (var converter = WaveFormatConversionStream.CreatePcmStream(reader))
        using (var upsampler = new WaveFormatConversionStream(new WaveFormat(16000, converter.WaveFormat.Channels), converter))
        {
            WaveFileWriter.CreateWaveFile("D:\\pcm16000.wav", upsampler);


            FileStream fs = new FileStream("d:\\pcm16000.wav", FileMode.Open, FileAccess.Read);

            byte [] bytes = new byte[fs.Length];
            int bytesToRead = (int)fs.Length;
            int bytesRead = 0;
            while (bytesToRead > 0)
            {
                int n = fs.Read(bytes, bytesRead, bytesToRead);
                if (n == 0) break;
                bytesRead += n;
                bytesToRead -= n;
            }
            bytesToRead = bytes.Length;

            return bytes;

        }

    }

0 个答案:

没有答案