BPM detection in iOS using soundtouch library

2k views Asked by At

I am trying to implement beatdetection within an iOS application. I found a fairly simple framework called SoundTouch and tried to implement this according to

iOS SoundTouch framework BPM Detection example

Unfortunately none of my following efforts seem to work and am currently in a deadlock state hence my post to Stackoverflow.

I took the following steps:

  1. Create single-view-based project
  2. Imported the
  3. Renamed mainViewController.m to ViewController.mm to make it compatible with c++
  4. Instructed the UIViewController class of the ViewController to conform to the AVFoundationPlayerDelegate protocols.
  5. Copy/Pasted the solution @MrHappyAsthma posted to his question
  6. Refactored

    player =[[AVAudioPlayer alloc] initWithData:data error:NULL];
    

to

    AVAudioPlayer *player =[[AVAudioPlayer alloc] initWithData:data error:NULL];

Now the compiler is complaining on:

soundtouch::SAMPLETYPE sampleBuffer[len]; (use of undeclared variable soundtouch)

soundtouch::BPMDetect BPM(player.numberOfChannels, [[player.settings valueForKey:@"AVSampleRateKey"] longValue]); (use of undeclared variable soundtouch)

BPM.inputSamples(sampleBuffer, len/player.numberOfChannels); (use of undeclared variable BPM)

NSLog(@"Beats Per Minute = %f", BPM.getBpm()); (use of undeclared variable BPM)

I think my knowledge on C++ isn't what it should be and the objects soundtouch and BPM should be declared/initialized.

Thanks folks!

1

There are 1 answers

4
sergio On BEST ANSWER

You need do the following in order to compile th project:

  1. add #import <SoundTouch/BPMDetect.h> to your ViewController.mm;

  2. add AVFoundation framework to your target (see picture);

  3. set the language settings as shown in picture (specifically, use GNU C++ libstdc++).

I haven't tried to run the program, but it builds at least.

enter image description here enter image description here