iOS SoundTouch framework song BPM Detection example

444 Views Asked by At

I am still looking for a working code which calculates BPM, did any of you solve this code? Appreciate any help.

This is the code I have and it returns either 0 value or wrong value (compared with BPM value online)

-(void) calcBPM {

   NSString *path = [[NSBundle mainBundle] pathForResource:@"song_test" ofType:@"mp3"];
   NSData *data = [NSData dataWithContentsOfFile:path];

   AVAudioPlayer *player =[[AVAudioPlayer alloc] initWithData:data error:NULL];
   NSUInteger len = [player.data length];

   soundtouch::SAMPLETYPE sampleBuffer[len];

   [player.data getBytes:sampleBuffer length:len];

   soundtouch::BPMDetect BPM(player.numberOfChannels, [[player.settings valueForKey:@"AVSampleRateKey"] longValue]);
   BPM.inputSamples(sampleBuffer, len/player.numberOfChannels);
   NSLog(@"Beats Per Minute = %f", BPM.getBpm());
   }
0

There are 0 best solutions below