简体   繁体   English

如何将 adpcm 数据保存到电话系统中的 wav、mp3 等文件中?

[英]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.中继器执行 tcp/ip 通信。

Receive adpcm data in bytes from user1 and user2, respectively.分别从 user1 和 user2 接收以字节为单位的 adpcm 数据。

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.收集来自一侧(user1)的数据并将其制成字节数组后,我使用 Naudio 创建了一个 wav 文件,但它失败了。

When I play it using the default playback app of window10, it plays for about 1 second and ends.当我使用window10的默认播放应用程序播放它时,它会播放大约1秒并结束。 However, the total playing time is longer, such as 6 seconds and 7 seconds.但总播放时间较长,如6秒和7秒。

The data below is a part from the beginning of the binary data of the wav file I created.下面的数据是我创建的wav文件的二进制数据开头的一部分。

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 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 0 010 07 00 0 0 0 010 07 00 0 0 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 8 77 68 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 A DB 9 02 A0 BA BB 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 1314 AB BB 9A 1 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 919 01 3 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 201 91 A9 19 339 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 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 1 9 1 91 1990 9 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):这是我实现的代码(音频数据是 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?如何将 adpcm 数据保存为音频文件?

And how do I save the voices of user1 and user2 in one file at the same time?以及如何将 user1 和 user2 的声音同时保存在一个文件中?

The headers of the file (from your data block above) look fine for 8kHz Mono ADPCM.文件的标题(来自上面的数据块)对于 8kHz Mono ADPCM 看起来很好。 All of these are written by NAudio so I expect them to match the code.所有这些都是由 NAudio 编写的,所以我希望它们与代码匹配。 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.这个特定文件总共有 51,908 个样本(约 6.5 秒),与数据块中 25,954 字节的数据相匹配。 So far, so good... if the data is in the Microsoft ADPCM format.到目前为止,一切都很好……如果数据是 Microsoft ADPCM 格式。

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.不幸的是,有许多 ADPCM 格式存在细微差别,无论是在编解码器使用的系数、每个样本的位数(从 2 到 6,尽管最常见的是 4)、支持的采样率和块编码。 G723 used to be common in telephony but you'll find all sorts. G723 曾经在电话中很常见,但你会发现各种各样的。

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. IMA/DVI ADPCM 生成带有 4 字节 header 的样本块,以纠正漂移并使解码器 state 恢复同步。

If I had to guess though I'd go with something like the Dialogic/OKI ADPCM format.如果我不得不猜测的话,我会使用Dialogic/OKI ADPCM格式的 go 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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