gpt4 book ai didi

ios - 读入声音文件,添加回声并写入新的声音文件

转载 作者:行者123 更新时间:2023-12-03 02:13:25 24 4
gpt4 key购买 nike

我正在尝试完成以下任务:

  • 将声音文件读入内存
  • 将其分成多个块,并以预定义的偏移量(2个可能的偏移量值)添加回波。
  • 另存为新文件

  • 我有以下代码将声音文件读入内存:
    NSURL   *urlToCAF = [NSURL URLWithString:@"simple-drum-beat.caf"];

    ExtAudioFileRef caf;
    OSStatus status;

    status = ExtAudioFileOpenURL((__bridge CFURLRef)urlToCAF, &caf);
    if(noErr == status) {
    // request float format
    const UInt32 NumFrames = 1024;
    const int ChannelsPerFrame = 1; // Mono, 2 for Stereo

    // request float format
    AudioStreamBasicDescription clientFormat;
    clientFormat.mChannelsPerFrame = ChannelsPerFrame;
    clientFormat.mSampleRate = 44100;

    clientFormat.mFormatID = kAudioFormatLinearPCM;
    clientFormat.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsNonInterleaved; // float
    int cmpSize = sizeof(float);
    int frameSize = cmpSize*ChannelsPerFrame;
    clientFormat.mBitsPerChannel = cmpSize*8;
    clientFormat.mBytesPerPacket = frameSize;
    clientFormat.mFramesPerPacket = 1;
    clientFormat.mBytesPerFrame = frameSize;

    status = ExtAudioFileSetProperty(caf, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat);
    if(noErr != status) { /* handle it */ }

    while(1) {
    float buf[ChannelsPerFrame*NumFrames];
    AudioBuffer ab = { ChannelsPerFrame, sizeof(buf), buf };
    AudioBufferList abl;
    abl.mNumberBuffers = 1;
    abl.mBuffers[0] = ab;

    UInt32 ioNumFrames = NumFrames;
    status = ExtAudioFileRead(caf, &ioNumFrames, &abl);

    if(noErr == status) {
    // do something here
    }
    }

    // later
    status = ExtAudioFileDispose(caf);
    if(noErr != status) { /* hmm */ }
    }

    您能否为我提供必要的代码,以便将回声添加到每个块中,然后将声音另存为新文件?

    我很感激。

    最佳答案

    这与“请为我编写代码”接壤

    如果您在缓冲器中有声波,则回声很简单:

    out[k] = in[k] + in[k-30]

    保存到文件我很确定您可以在Google上找到它。尝试让您的问题询问一件事。

    我建议研究 http://theamazingaudioengine.com/-它使生活变得更加轻松!

    关于ios - 读入声音文件,添加回声并写入新的声音文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22252902/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com