diff options
author | Taybin Rutkin <taybin@taybin.com> | 2006-03-14 21:35:55 +0000 |
---|---|---|
committer | Taybin Rutkin <taybin@taybin.com> | 2006-03-14 21:35:55 +0000 |
commit | ee873ee8969fa9d0d3da24923c2b690ff7fa0460 (patch) | |
tree | fd009b3431dba09c00501901d8b8c64db7609599 /libs/ardour/coreaudio_source.cc | |
parent | ec461de3a8fce8de51da56aa4f5f69224abc3dce (diff) |
Pointer fix from essej.
git-svn-id: svn://localhost/trunk/ardour2@394 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/coreaudio_source.cc')
-rw-r--r-- | libs/ardour/coreaudio_source.cc | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/libs/ardour/coreaudio_source.cc b/libs/ardour/coreaudio_source.cc index 0f5f049be8..3f786a2b14 100644 --- a/libs/ardour/coreaudio_source.cc +++ b/libs/ardour/coreaudio_source.cc @@ -23,6 +23,8 @@ #include "i18n.h" +#include <AudioToolbox/AudioFormat.h> + using namespace ARDOUR; CoreAudioSource::CoreAudioSource (const XMLNode& node) @@ -67,32 +69,28 @@ CoreAudioSource::init (const string& idstr, bool build_peak) FSRef ref; err = FSPathMakeRef ((UInt8*)file.c_str(), &ref, 0); if (err != noErr) { - error << err << endmsg; throw failed_constructor(); } err = ExtAudioFileOpen (&ref, &af); if (err != noErr) { - error << err << endmsg; ExtAudioFileDispose (af); throw failed_constructor(); } - AudioStreamBasicDescription absd; - memset(&absd, 0, sizeof(absd)); - size_t absd_size = sizeof(absd); + AudioStreamBasicDescription file_asbd; + memset(&file_asbd, 0, sizeof(file_asbd)); + size_t asbd_size = sizeof(file_asbd); err = ExtAudioFileGetProperty(af, - kExtAudioFileProperty_FileDataFormat, &absd_size, &absd); + kExtAudioFileProperty_FileDataFormat, &asbd_size, &file_asbd); if (err != noErr) { - error << err << endmsg; ExtAudioFileDispose (af); throw failed_constructor(); } - n_channels = absd.mChannelsPerFrame; + n_channels = file_asbd.mChannelsPerFrame; if (channel >= n_channels) { error << string_compose(_("CoreAudioSource: file only contains %1 channels; %2 is invalid as a channel number"), n_channels, channel) << endmsg; - error << err << endmsg; ExtAudioFileDispose (af); throw failed_constructor(); } @@ -102,7 +100,6 @@ CoreAudioSource::init (const string& idstr, bool build_peak) err = ExtAudioFileGetProperty(af, kExtAudioFileProperty_FileLengthFrames, &prop_size, &ca_frames); if (err != noErr) { - error << err << endmsg; ExtAudioFileDispose (af); throw failed_constructor(); } @@ -117,6 +114,24 @@ CoreAudioSource::init (const string& idstr, bool build_peak) throw failed_constructor (); } } + + AudioStreamBasicDescription client_asbd; + memset(&client_asbd, 0, sizeof(client_asbd)); + client_asbd.mFormatID = kAudioFormatLinearPCM; + client_asbd.mFormatFlags = kLinearPCMFormatFlagIsFloat; + client_asbd.mSampleRate = file_asbd.mSampleRate; + + err = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &asbd_size, &client_asbd); + if (err != noErr) { + ExtAudioFileDispose (af); + throw failed_constructor (); + } + + err = ExtAudioFileSetProperty (af, kExtAudioFileProperty_ClientDataFormat, asbd_size, &client_asbd); + if (err != noErr) { + ExtAudioFileDispose (af); + throw failed_constructor (); + } } CoreAudioSource::~CoreAudioSource () @@ -146,7 +161,7 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, ch AudioBufferList abl; abl.mNumberBuffers = 1; abl.mBuffers[0].mNumberChannels = n_channels; - abl.mBuffers[0].mDataByteSize = cnt; + abl.mBuffers[0].mDataByteSize = cnt * sizeof(Sample); abl.mBuffers[0].mData = dst; if (n_channels == 1) { @@ -169,7 +184,7 @@ CoreAudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, ch tmpbuf = new float[tmpbufsize]; } - abl.mBuffers[0].mDataByteSize = real_cnt; + abl.mBuffers[0].mDataByteSize = real_cnt * sizeof(Sample); abl.mBuffers[0].mData = tmpbuf; err = ExtAudioFileRead(af, (UInt32*) &real_cnt, &abl); |