Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soundtouch for iPhone

Has someone been able to make http://www.surina.net/soundtouch/ work for iPhone?

Simple Xcode Demo would be helpful.

I'd just like to play a soundeffect with some pitch manipulation.

thx chris

like image 519
christian Muller Avatar asked Nov 05 '22 16:11

christian Muller


1 Answers

The best way to implement audio effects using SoundTouch is using also SoundStretch.

You can download the source code of both from here http://www.surina.net/soundtouch/sourcecode.html

SoundStretch is a command-line program that performs SoundTouch library effects on WAV audio files. The program is a source code example how SoundTouch library routines can be used to process sound in other programs, but it can be used as a stand-alone audio processing tool as well.

SoundStretch features:

  • Reads & writes .wav audio files
  • Allows very broad parameter adjustment ranges:
  • Tempo & Playback Rate adjustable in range -95% .. +5000%
  • The sound Pitch (key) adjustable in range -60 .. +60 semitones (+- 5 octaves).
  • Beats-Per-Second (BPM) detection that can adjust tempo to match with the desired BPM rate.
  • Full source codes available
  • Command-line interface allows using the SoundStretch utility for processing .wav audio files in batch mode
  • Supports processing .wav audio streams through standard input/output pipes
  • SoundStretch uses the SoundTouch library routines for the audio procesing.

Example of use:

NSArray *effects = [NSArray arrayWithObjects:@"-rate=-22", nil];
NSURL *audio = [self base:input output:output effects:effects];

Where base:output:effects is defined as:

- (NSURL *)base:(NSURL *)input output:(NSURL *)output effects:(NSArray *)effects{
    int _argc = 3 + (int)[effects count];
    
    const char *_argv[]={"createWavWithEffect",[[input path] UTF8String], [[output path] UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String]};
    
    for (int i=0; i<[effects count]; i++) {
        _argv[i+3] = [effects[i] UTF8String];
    }
    createWavWithEffect(_argc, _argv);

    // IMPORTANT! Check the file size, maybe you will need to set by yourself

    return output;
}

If you don't want to compile by yourself SoundTouch, I have shared a GitHub repository with that libraries compiled for armv7, armv7s, arm64, i386 and x86_64

https://github.com/enrimr/soundtouch-ios-library

And if you want to use SoundTouch by yourself without using SoundStretch, you have to add SoundTouch directory (which includes libSoundTouch.a and the directory with headers) in your Xcode project.

For SWIFT projects:

Programming with SWIFT you can't import a .h so you will need to create a .h file named <Your-Project-Name>-Bridging-Header-File.h Then reference it in your projects build settings (under "Swift Compiler" look for "Objective C Bridging Header") with:

$(SRCROOT)/<Your-Project-Name>-Bridging-Header.h

And now you must be able to use SoundTouch class.

For Objective-C projects:

Include the following line

#include "SoundTouch.h" 

in your controller file.

Implementation of createWavWithEffect:

int createWavWithEffect(const int nParams, const char * const paramStr[])
{
    WavInFile *inFile;
    WavOutFile *outFile;
    RunParameters *params;
    SoundTouch soundTouch;

    fprintf(stderr, _helloText, SoundTouch::getVersionString());

    try 
    {
        // Parse command line parameters
        params = new RunParameters(nParams, paramStr);

        // Open input & output files
        openFiles(&inFile, &outFile, params);

        if (params->detectBPM == TRUE)
        {
            // detect sound BPM (and adjust processing parameters
            //  accordingly if necessary)
            detectBPM(inFile, params);
        }

        // Setup the 'SoundTouch' object for processing the sound
        setup(&soundTouch, inFile, params);

        // clock_t cs = clock();    // for benchmarking processing duration
        // Process the sound
        process(&soundTouch, inFile, outFile);
        // clock_t ce = clock();    // for benchmarking processing duration
        // printf("duration: %lf\n", (double)(ce-cs)/CLOCKS_PER_SEC);

        // Close WAV file handles & dispose of the objects
        delete inFile;
        delete outFile;
        delete params;

        fprintf(stderr, "Done!\n");
    } 
    catch (const runtime_error &e) 
    {
        // An exception occurred during processing, display an error message
        fprintf(stderr, "%s\n", e.what());
        return -1;
    }

    return 0;
}
like image 169
EnriMR Avatar answered Nov 15 '22 12:11

EnriMR