Use speex for iOS

Source: Internet
Author: User
Tags tmp folder

Two demos are provided to implement similar walkie talkie functions. One is implemented using the Lib-Amr library in the AMR format. The other is the speex library. There are a lot of people mentioned here, but there are not many tutorials. There are many unknown places for everyone. The new users have implemented similar walkie talkie functions, we made two demos. One is implemented using the Lib-Amr library in the AMR format. Another example is the speex library. There are a lot of people mentioned here, but there are not many tutorials. There are many unknown places for everyone, and new users are confused about this.

After three days on the internet, I finally got a decent demo. In the demo, I encoded a. CAF format PCM audio into the speex format and then converted it back to the PCM format. Of course, the demo only implements audio encoding and decoding, and does not add many functions.
I tested the 60-second recording (8 kHz, single-channel) and converted it into a minimum Amr (39 kb in size), which is about the same size as the one-minute recording file. The speex format is the smallest (18 K in size) But fuzzy. The acceptable size is 30 K, so it is still smaller than the AMR format. In addition, the speex library can reduce noise, gain, and mute noise. However, considering that android supports audio in Amr format and WP, we finally chose to convert the audio into AMR format. Unfortunately, Apple does not support AMR now, so transcoding is required. Next, let's take a step-by-step demo with you.

Compile the static Library:
This really makes me puzzled for a day. In fact, it should be very easy for C/C ++ programmers in Linux to do this, but all of them are returned to the teacher, according to the tutorial on the Internet, it has been a long time.
First download the source file you need. Because speex depends on the Ogg library, download the Ogg Library first. Here I package and upload it together. You can also download it from the official website.
Source file:

Libogg-1.3.0.zip
(496 K )speex-1.2rc1.tar
(3890 K)

Compilation is performed in command line mode. Open the terminal and first enter the folder where Ogg is located. Compile Ogg first. I use xcode4.4.1, and you need to adjust it slightly according to your own xcode commands. The 4.2 compilation tutorials are available on the Internet and I will not repeat them here.
Enter the following content on the terminal:
1.ogg-i386 Library
. /Configure-Prefix =/users/your computer username/desktop/speexlibrary/libogg-1.3.0/i386-host = i386-apple-darwin-build = x86_64-apple-darwin11.3.0 cc = "/applications/xcode. APP/contents/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99-arch i386-isysroot/applications/xcode. APP/contents/developer/platforms/iphonesimulator. platform/developer/sdks/iphonesimulator5.1.sdk /"

Make
Make install
Make clean (Be sure to be clean, otherwise the first compiled content will be compiled later)

2. Library of ogg-armv6
. /Configure-Prefix =/users/your computer username/desktop/speexlibrary/libogg-1.3.0/armv6-host = armv6-apple-darwin-build = x86_64-apple-darwin11.3.0 cc = "/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99
-Arch armv6-isysroot/applications/xcode. APP/contents/developer/platforms/iphoneos. Platform/developer/sdks/iphoneos5.1.sdk /"

Make
Make install
Make clean

3. Library of ogg-armv7
. /Configure-Prefix =/users/your computer username/desktop/speexlibrary/libogg-1.3.0/armv7-host = armv7-apple-darwin-build = x86_64-apple-darwin11.3.0 cc = "/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99
-Arch armv7-isysroot/applications/xcode. APP/contents/developer/platforms/iphoneos. Platform/developer/sdks/iphoneos5.1.sdk /"

Make
Make install
Make clean

Then compile the speex Library:
1. Library of speex-i386
. /Configure-Prefix =/users/your computer username/desktop/speexlibrary/speex-1.2rc1/i386-host = i386-apple-darwin-Disable-shared-enable-static-Disable-oggtest-Disable-fixed -Point-enable-float-API-build = x86_64-apple-darwin11.3.0-with-Ogg =/users/your computer username/desktop/speexlibrary/libogg-1.3.0/i386
Cc = "/applications/xcode. APP/contents/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99-arch i386-isysroot/applications/xcode. APP/contents/developer/platforms/iphonesimulator. platform/developer/sdks/iphonesimulator5.1.sdk /"

Make
Make install
Make clean

2. Library of speex-armv6
. /Configure-Prefix =/users/your computer username/desktop/speexlibrary/speex-1.2rc1/armv6-host = armv6-apple-darwin-Disable-shared-enable-static-Disable-oggtest-enable-fixed -Point-Disable-float-API-build = x86_64-apple-darwin11.3.0-with-Ogg =/users/your computer username/desktop/speexlibrary/libogg-1.3.0/armv6
Cc = "/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99-arch armv6-isysroot/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/sdks/iphoneos5.1.sdk /"

Make
Make install
Make clean

3. Library of speex-armv7
. /Configure-Prefix =/users/your computer username/desktop/speexlibrary/speex-1.2rc1/armv7-host = armv7-apple-darwin-Disable-shared-enable-static-Disable-oggtest-enable-fixed -Point-Disable-float-API-build = x86_64-apple-darwin11.3.0-with-Ogg =/users/your computer username/desktop/speexlibrary/libogg-1.3.0/armv7
Cc = "/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2-STD = c99-arch armv7-isysroot/applications/xcode. APP/contents/developer/platforms/iphoneos. platform/developer/sdks/iphoneos5.1.sdk /"

Make
Make install
Make clean

Finally, merge the static library, enter the speexlibrary folder, and enter the terminal:
Lipo-create i386/lib/libogg. A armv6/lib/libogg. A armv7/lib/libogg. A-output libogg.
Lipo-create i386/lib/libspeex. A armv6/lib/libspeex. A armv7/lib/libspeex. A-output libspeex.
Lipo-create i386/lib/libspeexdsp. A armv6/lib/libspeexdsp. A armv7/lib/libspeexdsp. A-output libspeexdsp.

Now the compilation is complete. If the static library cannot be merged, check the preceding steps (I forgot to make clean at the time, and the i386. A file is compiled ). You can use the lipo-Info XXX. A file to display the platform information used by files in the library. Normally, the file is displayed as i386, armv6, and armv7. The packaged library is uploaded to facilitate download.
The packaged speex Library:

_Speex.zip (821
K) start our project below:
Create a new project and import our static library. I dragged the package directly to the project. Remember to set the path for searching the static library. At that time, I forgot to set the path. The result was that the header files could not be found. After the import, the topic is displayed.

For convenience, I have recorded a 60-Second. CAF file.
I will not explain the detailed demo explanation. Here I will explain the steps.
1. We need to remove the file header from the. CAF file to obtain pure PCM data.
2. encode pure PCM data into pure speex format
3. Add a file header for data in pure speex format
4. Decode speex format data (with file headers) to pure PCM format
5. Add a WAV format file header
6. Write WAV data into the file and export the caf file (the exported file can be found in the TMP folder of the simulated project. A caf file can be played by clicking it ).

The following is my demo. Please compare it with the official speex User Manual. The user manual contains the C language sample code for encoding and decoding, which must be carefully studied.
My demo: test_speex_001.zip
(1585 K)

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.