# HG changeset patch # User Eric Wing # Date 1290565544 28800 # Node ID 2264b134b7ac3e182f63443a84d2fc987aeedc39 # Parent 33a77ceaed261b9bf02bcb584438f264df28f44a# Parent 6927c489964ce3c608e6044fd9c6e836fef81b23 merged diff -r 33a77ceaed26 -r 2264b134b7ac decoders/coreaudio.c --- a/decoders/coreaudio.c Tue Nov 23 18:23:32 2010 -0800 +++ b/decoders/coreaudio.c Tue Nov 23 18:25:44 2010 -0800 @@ -720,7 +720,11 @@ return(1); } /* CoreAudio_rewind */ - +/* Note: I found this tech note: + http://developer.apple.com/library/mac/#qa/qa2009/qa1678.html + I don't know if this applies to us. So far, I haven't noticed the problem, + so I haven't applied any of the techniques. + */ static int CoreAudio_seek(Sound_Sample *sample, Uint32 ms) { OSStatus error_result = noErr; @@ -730,6 +734,16 @@ AudioStreamBasicDescription actual_format; UInt32 format_size; + + /* I'm confused. The Apple documentation says this: + "Seek position is specified in the sample rate and frame count of the file’s audio data format + — not your application’s audio data format." + My interpretation is that I want to get the "actual format of the file and compute the frame offset. + But when I try that, seeking goes to the wrong place. + When I use outputFormat, things seem to work correctly. + I must be misinterpreting the documentation or doing something wrong. + */ +#if 0 /* not working */ format_size = sizeof(AudioStreamBasicDescription); error_result = AudioFileGetProperty( *core_audio_file_container->audioFileID, @@ -744,7 +758,12 @@ } /* if */ // packetIndex = (pos * sampleRate) / framesPerPacket - frame_offset = (SInt64)((ms/1000.0 * actual_format.mSampleRate) / actual_format.mFramesPerPacket); + // frame_offset = (SInt64)((ms/1000.0 * actual_format.mSampleRate) / actual_format.mFramesPerPacket); +#else /* seems to work, but I'm confused */ + // packetIndex = (pos * sampleRate) / framesPerPacket + frame_offset = (SInt64)((ms/1000.0 * core_audio_file_container->outputFormat->mSampleRate) / core_audio_file_container->outputFormat->mFramesPerPacket); +#endif + // computed against actual format and not the client format error_result = ExtAudioFileSeek(core_audio_file_container->extAudioFileRef, frame_offset); if(error_result != noErr)