iphone - iPhone 版 Soundtouch

标签 iphone audio core-audio

有人能做到吗 http://www.surina.net/soundtouch/ 适用于 iPhone?

简单的 Xcode 演示会很有帮助。

我只想通过一些音调操作来播放音效。

谢谢 克里斯

最佳答案

使用 SoundTouch 实现音频效果的最佳方法是同时使用 SoundStretch。

您可以从这里下载两者的源代码 http://www.surina.net/soundtouch/sourcecode.html

SoundStretch is a command-line program that performs SoundTouch library effects on WAV audio files. The program is a source code example how SoundTouch library routines can be used to process sound in other programs, but it can be used as a stand-alone audio processing tool as well.

SoundStretch features:

  • Reads & writes .wav audio files
  • Allows very broad parameter adjustment ranges:
  • Tempo & Playback Rate adjustable in range -95% .. +5000%
  • The sound Pitch (key) adjustable in range -60 .. +60 semitones (+- 5 octaves).
  • Beats-Per-Second (BPM) detection that can adjust tempo to match with the desired BPM rate.
  • Full source codes available
  • Command-line interface allows using the SoundStretch utility for processing .wav audio files in batch mode
  • Supports processing .wav audio streams through standard input/output pipes
  • SoundStretch uses the SoundTouch library routines for the audio procesing.

使用示例:

NSArray *effects = [NSArray arrayWithObjects:@"-rate=-22", nil];
NSURL *audio = [self base:input output:output effects:effects];

哪里base:output:effects定义为:

- (NSURL *)base:(NSURL *)input output:(NSURL *)output effects:(NSArray *)effects{
    int _argc = 3 + (int)[effects count];
    
    const char *_argv[]={"createWavWithEffect",[[input path] UTF8String], [[output path] UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String],[@"" UTF8String]};
    
    for (int i=0; i<[effects count]; i++) {
        _argv[i+3] = [effects[i] UTF8String];
    }
    createWavWithEffect(_argc, _argv);

    // IMPORTANT! Check the file size, maybe you will need to set by yourself

    return output;
}

如果您不想自己编译 SoundTouch,我已经共享了一个 GitHub 存储库,其中包含为 armv7 编译的库。 , armv7s , arm64 , i386x86_64

https://github.com/enrimr/soundtouch-ios-library

如果你想自己使用SoundTouch而不使用SoundStretch,你必须在你的Xcode项目中添加SoundTouch目录(其中包括libSoundTouch.a和带有头文件的目录)。

对于 SWIFT 项目:

使用 SWIFT 编程时,您无法导入 .h,因此您需要创建一个名为 <Your-Project-Name>-Bridging-Header-File.h 的 .h 文件。 然后在项目build设置中引用它(在“Swift Compiler”下查找“Objective C Bridging Header”):

$(SRCROOT)/<Your-Project-Name>-Bridging-Header.h

现在您必须能够使用 SoundTouch 类。

对于 Objective-C 项目:

包含以下行

#include "SoundTouch.h" 

在你的 Controller 文件中。

实现createWavWithEffect :

int createWavWithEffect(const int nParams, const char * const paramStr[])
{
    WavInFile *inFile;
    WavOutFile *outFile;
    RunParameters *params;
    SoundTouch soundTouch;

    fprintf(stderr, _helloText, SoundTouch::getVersionString());

    try 
    {
        // Parse command line parameters
        params = new RunParameters(nParams, paramStr);

        // Open input & output files
        openFiles(&inFile, &outFile, params);

        if (params->detectBPM == TRUE)
        {
            // detect sound BPM (and adjust processing parameters
            //  accordingly if necessary)
            detectBPM(inFile, params);
        }

        // Setup the 'SoundTouch' object for processing the sound
        setup(&soundTouch, inFile, params);

        // clock_t cs = clock();    // for benchmarking processing duration
        // Process the sound
        process(&soundTouch, inFile, outFile);
        // clock_t ce = clock();    // for benchmarking processing duration
        // printf("duration: %lf\n", (double)(ce-cs)/CLOCKS_PER_SEC);

        // Close WAV file handles & dispose of the objects
        delete inFile;
        delete outFile;
        delete params;

        fprintf(stderr, "Done!\n");
    } 
    catch (const runtime_error &e) 
    {
        // An exception occurred during processing, display an error message
        fprintf(stderr, "%s\n", e.what());
        return -1;
    }

    return 0;
}

关于iphone - iPhone 版 Soundtouch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2258113/

相关文章:

javascript - ASP Net Core FileContentResult音频文件到Safari

ios - 音频录制和播放同时进行

ios7 - AVAudioSession 输出选择

iphone - 这个警告是什么意思 : "setting the first responder view of the collection view but we don' t know its type (cell/header/footer)"

iphone - "Add"iOS 按钮图标

iphone - 视网膜设备的应用程序图标

ios - 每 10 秒重复 UILocalNotification 的间隔

javascript - 如何将 HTMLAudioElement 当前播放位置重置为 0?

当用户/选项卡/浏览器处于非事件状态时 JavaScript 播放声音

xcode - 找不到Xcode音频组件符号,并且某种程度上无法使用方法