changeset 579:6927c489964c

Bug fix for CoreAudio seeking. Comments inline in code.
author Eric Wing <ewing@anscamobile.com>
date Mon, 08 Nov 2010 21:02:49 -0800
parents 7ff36153215a
children 2264b134b7ac fbb3f1abdd9e
files decoders/coreaudio.c
diffstat 1 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/decoders/coreaudio.c	Sat Nov 06 00:27:45 2010 -0700
+++ b/decoders/coreaudio.c	Mon Nov 08 21:02:49 2010 -0800
@@ -713,7 +713,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;	
@@ -723,6 +727,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,
@@ -737,7 +751,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)