Train of thought: To do a network phone, basically follow the following steps
1, one side real-time recording, converts the analog signal into the digital signal;
2, the sound real-time compression;
3, through the network protocol to the compressed data transmission to the receiving side;
4, the receiving party to extract the audio data received;
5, real-time to receive the digital signal into analog signals and play out.
Let's look at the challenges and solutions that each step faces.
1, the first step, real-time recording, Directxsound has a recording aspect of the API, Managed classes are microsoft.directx.directsound.capturedevicescollection,microsoft.directx.directsound.capture and Microsoft.DirectX.Dir, respectively. Ectsound.capturebuffer,capturedevicescollection is used to enumerate the available recording devices for this machine, capture represents a recording device, Capturebuffer is a buffer for storing the recorded data, and after we start recording, the audio data is constantly Write to the annular stream buffer, and then we periodically remove the recording data from the buffer and return it to the upper application layer. With regard to the annular flow buffer, see the Reference link section.
2, sound compression is a difficult choice of steps, the default DirectSound can only play and record the PCM format (WAV) audio data, but this sound format is particularly large. Commonly used sound compression format has h.7231,gsm,amr,h.711 and so on, all kinds of compression algorithms have their own rate and scope of application. Because what we do is the voice phone on the internet, regardless of the slow network and wireless connection under the situation, also do not consider the terminal equipment CPU can support our choice of compression algorithm, we do voice phone both sides are PC, what should be decompression algorithm will not cause any performance problems, so as long as the network faster, Choose which compression algorithm does not matter, the Internet has a h.711 compression algorithm, I intend to use this, his code rate is 64Kbps, than the PCM 1.544Mbps and 2.048Mbps is much smaller. Then we have the audio data compression, but also for the byte stream gzip or 7ZIP compression, the former with Sharpzip, the latter 7zip of the official use of C # code, we can test the performance of these two algorithms after making the right decision. For a variety of compression format features can refer to my ppt and provide reference links.
3, the network calls attention to the real time sex, and the sound from the network transmission will go IP network, and IP network is not a waiting system, so we should try to simulate real-time voice transmission, mentioned real-time, certainly UDP than TCP to real-time, because TCP to ensure transmission reliability, order, etc., and dedicated to real-time transmission there is an application layer protocol is RTP, this protocol is generally based on the UDP, which in each header provides some serial numbers, timestamps and other information, but UDP itself does not use this information, At this time there is a RTCP protocol to use this information for traffic control and congestion control, such as RTCP detection network congestion, will tell the sender to transform a low bit rate speech compression algorithm to transfer data. Most of these need to achieve their own, the source of this article is not to achieve these, on the RTP and RTCP can refer to the relevant information or I do ppt.
4, each compression algorithm has the corresponding decompression algorithm, hehe.