This articleArticleSummary of the project.
After a project was completed for a while, I encountered a lot of trouble in the process, but fortunately it was finally solved. Here is the summary of the project after the project, and we have encountered the same problem, I hope I can refer to it, but my memory may not be very good. If you have any questions in practice, please leave a message for me or go to weibo.com/yarinto find me.
To implement a sound change technology in iOS, and to be able to run on iPhone 3G, some of the APIs that come with it are quite troublesome, so I decided to use the soundtouch open-source library, this library can realize the sound changing effect, including adjusting the sound frequency without changing the sound length. You can use openal to try it. After changing the frequency, the sound will become shorter.
Well, with this database, we can actually copy a talkingtom. Remember that I didn't ask everyone to go to the cottage. Here I just want to talk about the learning technology. It is better to innovate.
Soundtouch is an open-source audio processing library that provides three function modules: Variable Speed, variable adjustment, and simultaneous variable adjustment. It can operate media streams in real time and audio files. 32-bit floating point or 16-Bit fixed point. Single or dual channels are supported. The sampling rate ranges from 8 KB to 8 KB ~ 48 k.
The process is as follows:
First download soundtouch open source, which can be found on the official website, http://www.surina.net/soundtouch /.
After downloading, decompress the package and copy all the files in "soundtouch/source/soundtouch" to the IOS project to be added. Do you want to modify other parameters, if there are any errors, you are welcome to discuss them. It should be compiled directly. After adding them, as shown in.
Soundtouch is an open-source library written in C ++. To use it in IOS, You need to mix it with object-C. You should change the suffix.
The following functions are used to modify the audio file:
- Msoundtouch. setsamplerate (samplerate );// Set the sound sampling frequency
-
- Msoundtouch. setchannels (channels );// Set the sound Channel
-
- M_soundtouch.settempochange (tempodelta );// This is the legendary variable speed.
-
- M_soundtouch.setpitchsemitones (pitchdelta );// Set the sound pitch
-
- Msoundtouch. setratechange (ratedelta );// Set the sound rate
-
- // Quick is a bool variable. I am not sure what use_quickseek is.
-
- Msoundtouch. setsetting (setting_use_quickseek, quick );
- // Noantialias is a bool variable. I am not quite sure what use_aa_filter is.
-
- Msoundtouch. setsetting (setting_use_aa_filter ,! (Noantialias ));
Msoundtouch is a soundtouch object. As for how to change it, it depends on how you adjust the parameters. soundtouch is characterized by sound becoming cartoon. Choose according to your own needs, there are also some other open-source libraries.
At the end of the article, we will provide you with an example of soundtouch integrating the speakhere provided by the iPhone. The ranking list of the latest American TV series in 2013 does not know whether it can be uploaded. It seems a bit big. If it cannot be uploaded, go to http://weibo.
Note the following two issues:
I started to compile it, and the sound was strange and noisy. It took me a lot of time to find the reason, but it was fruitless. I suddenly remembered what we said before, it supports 32-bit floating point and 16-Bit fixed point at the same time. The default 32-bit floating point is used. I changed it to 16-Bit fixed point. Haha, by the way, the effect is very good. The change method is in sttypes. find the float_samples macro in the H file, comment it out, and open the integer_samples macro, as shown below:
-
- # If! (Integer_samples | float_samples)
-
- /// Choose either 32bit floating point or 16bit integer sampletype
-
- /// By choosing one of the following defines, unless this selection
-
- /// Has already been done in some other file.
-
- ////
-
- /// Notes:
- ///-In Windows environment, choose the sample format with
-
- /// Following defines.
-
- ///-In GNU environment, the floating point samples are used
-
- /// Default, but integer samples can be chosen by giving
- /// Following switch to the configure script:
-
- ///./Configure -- enable-integer-Samples
-
- /// However, if you still prefer to select the sample format here
-
- /// Also in GNU environment, then please # UNDEF the integer_sample
- /// And float_sample defines first as in comments abve.
-
- # Define integer_samples 1 // <16bit integer Samples
-
- // # Define float_samples 1 // <32bit float Samples
-
-
- # Endif
Another problem is that the test on the simulator is completely correct. Put it on the real machine device at this time, directly report an error and exit.ProgramAnother problem that took me a lot of time eventually found that the sound channel needs to be changed to a single channel on the real machine, as shown in the following:
- Msoundtouch. setchannels (2 );// 1 is a single channel
Success, of course, if you want to continue to understand the soundtouch library, then here (http://blog.csdn.net/leilu2008/article/details/6540575) a series of references.
The attachment has been uploaded. After downloading the attachment, remove the zip suffix ,! The correct one should be".Tar.gz ".
Attachment download:
Speakhere
This article is from"Yarin's blog"Blog, please be sure to keep this sourceHttp://yarin.blog.51cto.com/1130898/640398