1

我仍在寻找计算 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());
   }
4

0 回答 0