使用Soundtouch库在iOS中进行BPM检测

3

我想在iOS应用程序中实现节拍检测。我找到了一个相当简单的框架叫做SoundTouch,并尝试按照iOS SoundTouch framework BPM Detection example的说明实施。

不幸的是,我的所有努力似乎都没有奏效,目前陷入了僵局状态,因此我发布了这篇文章到Stackoverflow上。

我采取了以下步骤:

  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];

现在编译器报错了:

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)

我认为我的C ++知识不如应该,并且需要声明/初始化对象soundtouch和BPM。

谢谢大家!


似乎您没有包含Sound Touch头文件 - 尽管您说您已经包含了... 您能否发布更多的代码?甚至是您的完整项目... - sergio
当然:http://www.ski-inndronten.nl/TestProject.zip - Alex van Rijs
感谢您的努力! - Alex van Rijs
@AlexvanRijs:别忘了颁发悬赏(绿色勾选框下面的小蓝盒子!) - Goz
1个回答

4
为了编译这个项目,您需要执行以下操作:
  1. 在您的 ViewController.mm 中添加 #import <SoundTouch/BPMDetect.h>

  2. 将 AVFoundation 框架添加到您的目标中(参见图片);

  3. 按照图片中所示的语言设置(具体来说,使用 GNU C++ libstdc++)。

我还没有尝试运行该程序,但至少已经构建成功。

enter image description here enter image description here


看起来好像可以了!你的项目是为哪些架构设置的?我有armv64、armv7和armv7s。它在armv64上无法构建,所以我将其移除了。 - Alex van Rijs
我没有触碰架构设置,我假设它只是为当前平台(调试模式)构建,所以我没有收到错误。可能问题在于Sound Touch没有为arm64构建... - sergio
1
嗨Sergio,编译和运行代码时,程序在soundtouch :: SAMPLETYPE sampleBuffer [len]的行上出现EXC_BAD_ACCESS错误。这个错误的原因是什么?只有在iPhone上运行时才会发生。在模拟器中运行时不会崩溃,但BPM始终为0。 - Alex van Rijs
@AlexvanRijs 在 soundtouch 中 bpm 总是返回 0。请给我任何解决问题的想法。 - Bajaj

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接