3

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!

Community
  • 1
  • 1
Alex van Rijs
  • 803
  • 5
  • 17
  • 39

1 Answers1

4

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

sergio
  • 68,819
  • 11
  • 102
  • 123
  • That seemed to work! For what architectures do you have this project set? I have armv64 armv7 and armv7s. It wouldn't build on armv64 so I removed that one – Alex van Rijs Jun 03 '14 at 08:36
  • I did not touch the architectures setting and I assume that it was only building for the current platform (debug mode), so I did not get the error. Possibly the issue lies with sound touch not being built for arm64... – sergio Jun 03 '14 at 10:40
  • 1
    Hi Sergio, when compiling and running the code the program exists on EXC_BAD_ACCESS on line: soundtouch::SAMPLETYPE sampleBuffer[len]. What could be the reason for this error. It only happens when running on the iphone. When running in the simulator it does not crash but the BPM is always 0. – Alex van Rijs Jun 05 '14 at 12:08
  • @AlexvanRijs bpm always return 0 in soundtouch . please give me any idea how to resolve problem – Bajaj Jul 14 '16 at 07:24