简体   繁体   中英

How to save adpcm data to file like wav, mp3 in phone system?

There are telephone communication systems as follows.

系统

Among these, I am going to develop a repeater. The repeater performs tcp/ip communication.

Receive adpcm data in bytes from user1 and user2, respectively.

I want to save the data received from the repeater as an audio file.

Once the data from one side (user1) was collected and made into a byte array, I created a wav file using Naudio, but it failed.

When I play it using the default playback app of window10, it plays for about 1 second and ends. However, the total playing time is longer, such as 6 seconds and 7 seconds.

The data below is a part from the beginning of the binary data of the wav file I created.

52 49 46 46 B4 65 00 00 57 41 56 45 66 6D 74 20 32 00 00 00 02 00 01 00 40 1F 00 00 00 10 00 00 00 01 04 00 20 00 F4 01 07 00 00 01 00 00 00 02 00 FF 00 00 00 00 C0 00 40 00 F0 00 00 00 CC 01 30 FF 88 01 18 FF 66 61 63 74 04 00 00 00 C4 CA 00 00 64 61 74 61 62 65 00 00 77 77 77 68 08 08 08 08 08 08 08 08 08 08 80 08 08 9A 99 99 90 01 21 21 12 25 53 40 9A B9 91 24 34 11 8A BC AA 80 13 17 43 42 12 09 8A AB DB BB BA 9A 88 12 02 A0 BA BB DB A9 8A 01 33 33 31 10 1A 0B BB BA A0 91 22 32 11 90 A9 BB BB 9B 11 23 33 41 11 19 9B AB B9 11 22 13 35 11 08 99 AA BC A1 A1 00 31 31 11 A9 0A AB BB 9A 10 13 14 12 91 90 9B 9B B9 A0 11 13 41 29 29 09 9B AB B9 09 10 13 33 11 A9 BB BB CA 09 00 12 33 33 39 39 1A AA B9 B1 91 22 33 40 01 90 A9 BC A9 99 01 31 41 01 9A 9B 9C 9A 9A 90 01 33 33 21 01 09 9B A9 90 11 11 33 33 21 01 0A 9B 9A 99 01 03 14 10 19 99 B9 BB BA B0 90 12 33 11 20 91 A9 99 9A 01 02 11 33 01 10 09 99 B0 A0 10 12 13 31 29 99 9B 9A B0 99 90 01 11 21 90 91 09 19 09 10 90 12 03 19 19 19 09 99 19 9 9 00 11 13 10 90 99 BA B9 B0 99 00 01 91 00 99 11 99 00 11 01 11 11 11 19 99 11 91 91 11 00 10 01 20 01 90 99 AA 9A 99 01 91 99 9A 9A 99 19 01 10 11 11 21 11 3A 09 99 90 00 31 11 19 10 91 91 11 01 9A

Here is the code I implemented(audiodata is byte array of adpcmdata):

        var adpcmWaveFormat = new AdpcmWaveFormat(8000, 1);

        using (WaveFileWriter writer = new WaveFileWriter("D:\\test.wav", adpcmWaveFormat))
        { 
            writer.Write(audiodata, 0, audiodata.Length);
        }

How can I save adpcm data as an audio file?

And how do I save the voices of user1 and user2 in one file at the same time?

The headers of the file (from your data block above) look fine for 8kHz Mono ADPCM. All of these are written by NAudio so I expect them to match the code. This particular file has 51,908 total samples (~6.5 seconds), which matches with the 25,954 bytes worth of data in the data chunk. So far, so good... if the data is in the Microsoft ADPCM format.

Unfortunately there are numerous ADPCM formats with subtle differences, whether in the coefficients used by the codec, the number of bits per sample (anywhere from 2 to 6, although 4 is most common), supported sample rates and block encoding. G723 used to be common in telephony but you'll find all sorts.

Apart from differences in supported features (bits per sample, channel counts, sample frequency, etc) different formats use different block structures. IMA/DVI ADPCM produce blocks of samples with a 4-byte header to correct drift and get the decoder state back in sync.

If I had to guess though I'd go with something like the Dialogic/OKI ADPCM format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM