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
.
swift avaudioplayer audiokit avaudiopcmbuffer
add a comment |
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
.
swift avaudioplayer audiokit avaudiopcmbuffer
add a comment |
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
.
swift avaudioplayer audiokit avaudiopcmbuffer
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
swift avaudioplayer audiokit avaudiopcmbuffer
edited Nov 10 at 16:44
Daniel Larsson
501416
501416
asked Nov 9 at 22:32
narner
1,55211647
1,55211647
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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