iOS SoundTouch框架歌曲BPM Detection示例

时间:2014-06-06 02:20:12

标签: ios objective-c soundtouch

我仍然在寻找计算BPM的工作代码,你们中的任何人都解决了这个问题吗?感谢任何帮助。

这是我的代码,它返回0值或错误值(与在线BPM值相比)

-(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 个答案:

没有答案