如何实时将帧添加到音频流以时间拉伸音频

时间:2018-07-31 18:41:58

标签: swift audio spotify core-audio

在这种情况下,我需要从Spotify iOS SDK访问指向音频缓冲区的unsafeRawPointer。然后我想将帧添加到该缓冲区,并按预期方式将其返回给super.method。结果应该是时间伸缩(减慢)的音频,且没有音调失真。我似乎无法使其工作。我注释了一些尝试...我想进入数组并将添加项添加到数组中可以做到这一点...但是当我尝试将其返回给该方法时。 。音频损坏。请帮忙。我已经经历了数周的审讯和出错。 :-(

class CoreAudioController: SPTCoreAudioController {

  override func attempt(toDeliverAudioFrames audioFrames: UnsafeRawPointer!, ofCount frameCount: Int, streamDescription audioDescription: AudioStreamBasicDescription) -> Int {
  print("attempt to deliver audio frames")


  var pointer: UnsafePointer<Int16> = audioFrames.bindMemory(to: Int16.self, capacity: byteCount)

  // Attemping to add empty frames to space out the audio frames then return the expected pointer below...

  // let framePointer = UnsafeRawBufferPointer(start: pointer, count: byteCount)
  // var framePointer = UnsafeBufferPointer(start: pointer, count: frameCount)
  // var frames = Array(framePointer)

  // withUnsafePointer(to: &frames) { bytes in
  //
  //    }


    return super.attempt(toDeliverAudioFrames: pointer, ofCount: frameCount, streamDescription: audioDescription)
  }

}

1 个答案:

答案 0 :(得分:0)

我不确定如何手动轻松地完成此操作,但是Superpowered.com之类的库提供了几种工具来实时更改音频馈送。我已经在我的应用程序(Piti Piti Pa)中使用它来进行多达20种乐器的现场音频混合。

特别是,您将对使用SuperpoweredTimeStretching类感兴趣:https://superpowered.com/docs/class_superpowered_time_stretching.html

希望有人可以提供有用的信息,而所需的集成工作较少,但我希望以上信息对您或其他人有用。

祝你好运!