Speex On iPhone Explained

I neglected to point out that you should un comment #define _USE_SSE in the config.h as mentioned below. This preproc directive will allow you to run on device. It was also mentioned that you could get more speed out of Speex if you #define FIXED_POINT instead of FLOATING_POINT. I have not verified this and Speex runs acceptable in my implementation without it but its worth mentioning.

I get a lot of questions on how I implemented Speex on iPhone. So I’m going to take this time to do a quick tutorial series. This is part 1, which will show you how to import the speex source into XCode and get a clean compile.

First download and explode the Speex source to any location. Run “./configure” in the exploded folder and create an iPhone subfolder within the speex in this same location. Now we’ll begin creating an XCode project inside the iPhone subfolder. I use a static lib project so that I can reused my work in several other projects, but if you’re new to XCode and iPhone you may forego static libs and just create a typical view based project. I start out being anal about my project structure. I prefer to have only the project folder and a single src folder at my project root. I realize this is non standard iPhone but it makes perfect sense from a build perspective. (I see: build description + src = build output) So a little refactoring and adjusting my target settings to find the new location of the plist and pch files.

  • Drag/drop the libspeex and include/speex folders into your XCode project.
  • Drag/drop the config.h file from the unpackaged speex tar into your project.
  • Add the include folder to your header search path
  • Double click the project in the left hand tree and add the following user defined setting: GCC_PREPROCESSOR_DEFINITIONS = HAVE_CONFIG_H
  • (User defined settings can be added by clicking the little wrench in the lower left corner.)
  • Finally, you need to take “libspeex/echo_diagnostic.m” out of the compile loop. Either uncheck the target membership box next to the left hand “Groups & Files” tree pane on the left or open and drill into your Application (or static lib) target and select the “Compile Sources” branch. Find the file under there and delete it.

By now your compiles should be squeaky clean. Stay tuned to the next parts of the series where I’ll discuss how to import ogg and wave container formats into XCode and perform Speex decompression in an app. I’ve upoaded my source (SpeexLib) to my box.net account so you can click here to download it or find it in the Box widget to the right of this post.

13 thoughts on “Speex On iPhone Explained

    1. Check out part II. It took a while but Im now ready to start running with part 3. Eventually we’ll have Core Audio integration and then move onto encoding.

  1. The method mentioned here let you build libspeex for mac or iphone simulator only, not for real iphone/ipad. In order to make it working or real device (or even compile for target device on mac) you’ll need to edit config.h and comment out #define _USE_SSE. You can also comment out #define FLATING_POINT and uncomment #define FIXED_POINT – can be a bit faster.

    1. Docent,

      These are all good points and a clear oversight on my part. In an effort to recreate a demo voice application I forgot to run a smoke test on the device. I was in a rush to throw this tutorial together as I had been getting feedback from a few on exactly how all of this comes together. I will update my post accordingly.

  2. Hi, Cliff, Thanks for your tutorial. I succeeded to compile the speed library following your tutorial, but should I always create the project inside the speex folder?

      1. Thank you. I shall try it. For now, I kinda meet a more serious problem. I don’t have to pass AudioQueen buffer to the speex_preprocess_run function.

  3. “I don’t have to pass AudioQueen buffer to the speex_preprocess_run function.” –> I don’t know how to pass AudioQueen buffer to the speex_preprocess_run function.

  4. Hi cliff, In my Speex folder it is showing config.h.in file. is this same as you are talking about. And plz tel me how to run this config.h.in, so that i wuld be able to proceed. Plz help me !!

  5. Hi cliff, i did the same as u mentioned. But when i run the command it is showing this log:Shobhit-Mac-mini:~ shobhitgupta$ /Users/shobhitgupta/Desktop/speex-1.2rc1/configure ; exit;
    checking for a BSD-compatible install… /usr/bin/install -c
    checking whether build environment is sane… yes
    checking for gawk… no
    checking for mawk… no
    checking for nawk… no
    checking for awk… awk
    checking whether make sets $(MAKE)… no
    checking whether to enable maintainer-specific portions of Makefiles… no
    checking build system type… i386-apple-darwin11.4.0
    checking host system type… i386-apple-darwin11.4.0
    checking for style of include used by make… none
    checking for gcc… no
    checking for cc… no
    checking for cl.exe… no
    configure: error: no acceptable C compiler found in $PATH
    See `config.log’ for more details.

    [Process completed]

    I guess some thing is missing in this. Cn you guide me how to make right?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s