First of all, in this era, do a imapp, absolutely no less voice communication this function, if there is no voice communication function I believe in the present is not an IM anymore.
This module has been delayed for one months as a result of a new project that was busy during the previous period. Finally, after another project was launched today, I started the study of this module.
Before the start of the study, I first went to the market to download a few of the current more popular IM, and then through the powerful anti-compilation and file search ability, found that even the Mo Mo this app, their voice transmission is not a relatively large compression (Mewow similarly did not go through a large compression), But it is through its own powerful algorithm, the audio file compression processing, the audio into WAV format audio files, about 60 seconds of audio files, the size of about 70K, and WAV format files other machines can directly use the API to play, such as on the Web page.
Before you begin to really use Speex for encoding compression, let's look at the audio features.
First audio has several basic features: sample rate, channel, bit rate.
The higher the sampling rate, the closer the sound is to reality.
The higher the bit rate, the more data is processed per frame, and the faster the transfer rate.
It's better to get to know the meaning of narrowband and broadband and some other audio terms, and here I don't have to explain it, so please do it yourself.
After a good understanding of the terminology, the thing to look for now is to find a way back to reference. Since our IM client is both iOS and Android, I'm going to look for the two system's to come back.
1.ios Chestnut
2.android Chestnut
First, both chestnuts can be used, and both are recorded, encoded, decoded, and played. However, the question is, can the Speex processed audio above iOS play on Android? The answer is: No, of course, is the above two chestnut audio files can not be decoded to the other system playback. What is it you get!
In order to solve this problem, we must study the difference between coding and decoding in more depth.
1. Check the Android encoding process first.
1.1 Edge Recording Edge coding
1.2 recorded after Ogg again compressed format
1.3 Processing 160 bytes per frame, 160 bytes encoded into 20 bytes.
1.4 Adding header information
2. Go over the iOS encoding process.
2.1 When recording is complete, extract the audio source data from the ACF recording file PCM
2.2 Encode PCM data per frame, 160 bytes per frame.
2.3 160 source data per frame, encoded as 38 bytes
2.4 Add the number 38 to the data header
2.5 after OGG compression format.
From the above, the two pest on the recording of a relatively different processing, it is this difference between the two systems out of the recording can not give each other to decode playback.
To get rid of this discrepancy, I started out with a plan: Make a library that makes Android and iOS audio processing the same.
Such a library should be based on the source of the chestnut above the iOS and then write out a jni file, and then to the Android side to call.
However, the first step here has already made me difficult, the type of char in the iOS system is different from the byte in Java (specifically Baidu itself). After a day of research, I decided to give up, but I'm sure it would be a bit more uniform, so the two systems would be consistent with the way audio is processed. (The programme will be studied later)
Can actually look at the following paragraph of iOS pest code discovery, iOS processing is to divide a piece of data into each frame to encode.
Since iOS is also a source PCM data, split into 160 bytes per frame to encode, then I just put the two systems coding process to unify.
Scenario Two: Unified coding process, decoding process.
It is seen that the length of SPX encrypted data obtained by iOS and Android after a frame is not the same. The encrypted length of the data is the length of each frame of the SPX file. For example: 38 SPX length data encrypts 160ios audio PCM data, so when decoding, 160 audio PCM data must be restored with 38 SPX to be played by the player. Therefore, when decoding playback, 38 of the data length of each frame after encryption must inform the decoding end, otherwise playback fails.
Therefore, the process of encoding and decoding is unified according to the situation of the Android side:
1. Sound input
2. The recorder is processed at each frame to obtain the audio PCM data for each frame.
3. Pass each frame of audio PCM data to the Speex encoder.
4. The Speex encoder compresses each frame of PCM data, overflows the noise, and outputs the SPX data after each frame is encoded.
5. Save each frame of SPX data.
6. When the recording is finished, add the data header before all SPX data to indicate what sample rate, bit law, channel, etc. are used for recording audio.
7. Save the SPX data to the. spx file.
Speex processes such as:
1. Transfer process
2. Coding process
According to the above description, you can clearly know the whole process of Speex coding, about the code aspect, "Tomorrow on the new."
Ps:
由于本人确实很少时间维护博客,因为平时除了上班,下班还要买菜煮饭拖地喂奶溜狗踢球跑步诳街,所以难得更新一会,不过最近时间多了,就开始更新吧。
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Use of Android and IOS under Speex