Problem reading audio file recorded with AudioKit into an AVPlayer intsance











up vote
1
down vote

favorite












I'm in a situation where I need to export an audio file recorded with AudioKit, and then reimport it later for use some processing via AVAudioPCMBuffer.



Below is the code I'm using for exporting from AudioKit:



    tape = recorder.audioFile!
player.load(audioFile: tape)


if let _ = player.audioFile?.duration {
recorder.stop()
tape.exportAsynchronously(name: "TempTestFile",
baseDir: .documents,
exportFormat: .caf) {_, exportError in
if let error = exportError {
AKLog("Export Failed (error)")
} else {
AKLog("Export succeeded")
}
}

}


And here is where I'm trying to read back that audio file into my macOS app later, and fill an AVAudioPCMBuffer (where file is the audio file I'm trying to read):



            let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: Double(sampleRate), channels: AVAudioChannelCount(channels), interleaved: interleaved)

if let buffer = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: AVAudioFrameCount(file.length)){
if ((try? file.read(into: buffer)) != nil) {

let arraySize = Int(buffer.frameLength)

switch type {
case is Double.Type:
let doublePointer = UnsafeMutablePointer<Double>.allocate(capacity: arraySize)
vDSP_vspdp(buffer.floatChannelData![0], 1, doublePointer, 1, vDSP_Length(arraySize))
return Array(UnsafeBufferPointer(start: doublePointer, count:arraySize)) as? [T]
case is Float.Type:
return Array(UnsafeBufferPointer(start: buffer.floatChannelData![0], count:arraySize)) as? [T]
default: return nil
}
}
}


However, I'm consistently getting an error of the following:




EXCEPTION (-50): "wrong number of buffers"



[avae] AVAEInternal.h:103:_AVAE_CheckNoErr:
[AVAudioFile.mm:445:-[AVAudioFile readIntoBuffer:frameCount:error:]:
(ExtAudioFileRead(_imp->_extAudioFile, &ioFrames,
buffer.mutableAudioBufferList)): error -50




This is regardless of the file format used when exporting and importing the audio.



However, it does work fine if I'm using this .wav file that is read from directly inside the app.



Does anyone have any insights into why I can't seem to read the data from the audio file into an AVPCMBuffer.










share|improve this question




























    up vote
    1
    down vote

    favorite












    I'm in a situation where I need to export an audio file recorded with AudioKit, and then reimport it later for use some processing via AVAudioPCMBuffer.



    Below is the code I'm using for exporting from AudioKit:



        tape = recorder.audioFile!
    player.load(audioFile: tape)


    if let _ = player.audioFile?.duration {
    recorder.stop()
    tape.exportAsynchronously(name: "TempTestFile",
    baseDir: .documents,
    exportFormat: .caf) {_, exportError in
    if let error = exportError {
    AKLog("Export Failed (error)")
    } else {
    AKLog("Export succeeded")
    }
    }

    }


    And here is where I'm trying to read back that audio file into my macOS app later, and fill an AVAudioPCMBuffer (where file is the audio file I'm trying to read):



                let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: Double(sampleRate), channels: AVAudioChannelCount(channels), interleaved: interleaved)

    if let buffer = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: AVAudioFrameCount(file.length)){
    if ((try? file.read(into: buffer)) != nil) {

    let arraySize = Int(buffer.frameLength)

    switch type {
    case is Double.Type:
    let doublePointer = UnsafeMutablePointer<Double>.allocate(capacity: arraySize)
    vDSP_vspdp(buffer.floatChannelData![0], 1, doublePointer, 1, vDSP_Length(arraySize))
    return Array(UnsafeBufferPointer(start: doublePointer, count:arraySize)) as? [T]
    case is Float.Type:
    return Array(UnsafeBufferPointer(start: buffer.floatChannelData![0], count:arraySize)) as? [T]
    default: return nil
    }
    }
    }


    However, I'm consistently getting an error of the following:




    EXCEPTION (-50): "wrong number of buffers"



    [avae] AVAEInternal.h:103:_AVAE_CheckNoErr:
    [AVAudioFile.mm:445:-[AVAudioFile readIntoBuffer:frameCount:error:]:
    (ExtAudioFileRead(_imp->_extAudioFile, &ioFrames,
    buffer.mutableAudioBufferList)): error -50




    This is regardless of the file format used when exporting and importing the audio.



    However, it does work fine if I'm using this .wav file that is read from directly inside the app.



    Does anyone have any insights into why I can't seem to read the data from the audio file into an AVPCMBuffer.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I'm in a situation where I need to export an audio file recorded with AudioKit, and then reimport it later for use some processing via AVAudioPCMBuffer.



      Below is the code I'm using for exporting from AudioKit:



          tape = recorder.audioFile!
      player.load(audioFile: tape)


      if let _ = player.audioFile?.duration {
      recorder.stop()
      tape.exportAsynchronously(name: "TempTestFile",
      baseDir: .documents,
      exportFormat: .caf) {_, exportError in
      if let error = exportError {
      AKLog("Export Failed (error)")
      } else {
      AKLog("Export succeeded")
      }
      }

      }


      And here is where I'm trying to read back that audio file into my macOS app later, and fill an AVAudioPCMBuffer (where file is the audio file I'm trying to read):



                  let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: Double(sampleRate), channels: AVAudioChannelCount(channels), interleaved: interleaved)

      if let buffer = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: AVAudioFrameCount(file.length)){
      if ((try? file.read(into: buffer)) != nil) {

      let arraySize = Int(buffer.frameLength)

      switch type {
      case is Double.Type:
      let doublePointer = UnsafeMutablePointer<Double>.allocate(capacity: arraySize)
      vDSP_vspdp(buffer.floatChannelData![0], 1, doublePointer, 1, vDSP_Length(arraySize))
      return Array(UnsafeBufferPointer(start: doublePointer, count:arraySize)) as? [T]
      case is Float.Type:
      return Array(UnsafeBufferPointer(start: buffer.floatChannelData![0], count:arraySize)) as? [T]
      default: return nil
      }
      }
      }


      However, I'm consistently getting an error of the following:




      EXCEPTION (-50): "wrong number of buffers"



      [avae] AVAEInternal.h:103:_AVAE_CheckNoErr:
      [AVAudioFile.mm:445:-[AVAudioFile readIntoBuffer:frameCount:error:]:
      (ExtAudioFileRead(_imp->_extAudioFile, &ioFrames,
      buffer.mutableAudioBufferList)): error -50




      This is regardless of the file format used when exporting and importing the audio.



      However, it does work fine if I'm using this .wav file that is read from directly inside the app.



      Does anyone have any insights into why I can't seem to read the data from the audio file into an AVPCMBuffer.










      share|improve this question















      I'm in a situation where I need to export an audio file recorded with AudioKit, and then reimport it later for use some processing via AVAudioPCMBuffer.



      Below is the code I'm using for exporting from AudioKit:



          tape = recorder.audioFile!
      player.load(audioFile: tape)


      if let _ = player.audioFile?.duration {
      recorder.stop()
      tape.exportAsynchronously(name: "TempTestFile",
      baseDir: .documents,
      exportFormat: .caf) {_, exportError in
      if let error = exportError {
      AKLog("Export Failed (error)")
      } else {
      AKLog("Export succeeded")
      }
      }

      }


      And here is where I'm trying to read back that audio file into my macOS app later, and fill an AVAudioPCMBuffer (where file is the audio file I'm trying to read):



                  let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: Double(sampleRate), channels: AVAudioChannelCount(channels), interleaved: interleaved)

      if let buffer = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: AVAudioFrameCount(file.length)){
      if ((try? file.read(into: buffer)) != nil) {

      let arraySize = Int(buffer.frameLength)

      switch type {
      case is Double.Type:
      let doublePointer = UnsafeMutablePointer<Double>.allocate(capacity: arraySize)
      vDSP_vspdp(buffer.floatChannelData![0], 1, doublePointer, 1, vDSP_Length(arraySize))
      return Array(UnsafeBufferPointer(start: doublePointer, count:arraySize)) as? [T]
      case is Float.Type:
      return Array(UnsafeBufferPointer(start: buffer.floatChannelData![0], count:arraySize)) as? [T]
      default: return nil
      }
      }
      }


      However, I'm consistently getting an error of the following:




      EXCEPTION (-50): "wrong number of buffers"



      [avae] AVAEInternal.h:103:_AVAE_CheckNoErr:
      [AVAudioFile.mm:445:-[AVAudioFile readIntoBuffer:frameCount:error:]:
      (ExtAudioFileRead(_imp->_extAudioFile, &ioFrames,
      buffer.mutableAudioBufferList)): error -50




      This is regardless of the file format used when exporting and importing the audio.



      However, it does work fine if I'm using this .wav file that is read from directly inside the app.



      Does anyone have any insights into why I can't seem to read the data from the audio file into an AVPCMBuffer.







      swift avaudioplayer audiokit avaudiopcmbuffer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 16:44









      Daniel Larsson

      501416




      501416










      asked Nov 9 at 22:32









      narner

      1,55211647




      1,55211647





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234114%2fproblem-reading-audio-file-recorded-with-audiokit-into-an-avplayer-intsance%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234114%2fproblem-reading-audio-file-recorded-with-audiokit-into-an-avplayer-intsance%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          Bicuculline

          さくらももこ