[Reprint] [Project Summary] using the soundtouch library in IOS

Source: Internet
Author: User

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:

  1. Msoundtouch. setsamplerate (samplerate );// Set the sound sampling frequency 
  2. Msoundtouch. setchannels (channels );// Set the sound Channel 
  3. M_soundtouch.settempochange (tempodelta );// This is the legendary variable speed. 
  4. M_soundtouch.setpitchsemitones (pitchdelta );// Set the sound pitch 
  5. Msoundtouch. setratechange (ratedelta );// Set the sound rate 
  6. // Quick is a bool variable. I am not sure what use_quickseek is. 
  7. Msoundtouch. setsetting (setting_use_quickseek, quick );
  8. // Noantialias is a bool variable. I am not quite sure what use_aa_filter is. 
  9. 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:

  1. # If! (Integer_samples | float_samples) 
  2. /// Choose either 32bit floating point or 16bit integer sampletype 
  3. /// By choosing one of the following defines, unless this selection 
  4. /// Has already been done in some other file. 
  5. //// 
  6. /// Notes: 
  7. ///-In Windows environment, choose the sample format with 
  8. /// Following defines. 
  9. ///-In GNU environment, the floating point samples are used 
  10. /// Default, but integer samples can be chosen by giving 
  11. /// Following switch to the configure script: 
  12. ///./Configure -- enable-integer-Samples 
  13. /// However, if you still prefer to select the sample format here 
  14. /// Also in GNU environment, then please # UNDEF the integer_sample 
  15. /// And float_sample defines first as in comments abve. 
  16. # Define integer_samples 1 // <16bit integer Samples 
  17. // # Define float_samples 1 // <32bit float Samples 
  18. # 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:

    1. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.