changeset 581:2264b134b7ac

merged
author Eric Wing <ewing . public |-at-| gmail . com>
date Tue, 23 Nov 2010 18:25:44 -0800
parents 33a77ceaed26 (current diff) 6927c489964c (diff)
children eba7b2e13740
files decoders/coreaudio.c
diffstat 1 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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)