我在網上搜索了所有內容,找不到關於如何使用SoundTouch library進行節拍檢測的教程。iOS SoundTouch框架BPM檢測示例
(注:。我必須在此之前沒有C++的經驗,我知道C,Objective-C的,和Java這樣我就可以搞砸了一些這件事,但它編譯)
我增加了framework到我的項目,並設法得到如下編譯:
NSString *path = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"wav"];
NSData *data = [NSData dataWithContentsOfFile:path];
player =[[AVAudioPlayer alloc] initWithData:data error:NULL];
player.volume = 1.0;
player.delegate = self;
[player prepareToPlay];
[player play];
NSUInteger len = [player.data length]; // Get the length of the data
soundtouch::SAMPLETYPE sampleBuffer[len]; // Create buffer array
[player.data getBytes:sampleBuffer length:len]; // Copy the bytes into the buffer
soundtouch::BPMDetect *BPM = new soundtouch::BPMDetect(player.numberOfChannels, [[player.settings valueForKey:@"AVSampleRateKey"] longValue]); // This is working (tested)
BPM->inputSamples(sampleBuffer, len); // Send the samples to the BPM class
NSLog(@"Beats Per Minute = %f", BPM->getBpm()); // Print out the BPM - currently returns 0.00 for errors per documentation
的歌曲字節的信息讓我困惑。
如何從歌曲文件中獲取這些信息?
我試過使用memcpy()
,但它似乎沒有工作。
任何人有任何想法?
很酷,你能告訴你如何將SoundTouch庫添加到xcode項目? – otakuProgrammer
您只需下載框架並將其導入到您的項目中。 – MrHappyAsthma
好吧,我已經設法將它包括到xcode項目中,上面的代碼不會工作,有時候應用程序崩潰,我嘗試了wav和mp3文件,我甚至使用了來自soundtouch網站的原始音頻樣本,它給了我一個崩潰問題或nan結果(使用原始樣本音頻時) – otakuProgrammer