Mercurial > SDL_sound_CoreAudio
comparison decoders/coreaudio.c @ 581:2264b134b7ac
merged
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Tue, 23 Nov 2010 18:25:44 -0800 |
parents | 33a77ceaed26 6927c489964c |
children |
comparison
equal
deleted
inserted
replaced
580:33a77ceaed26 | 581:2264b134b7ac |
---|---|
718 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | 718 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
719 } | 719 } |
720 return(1); | 720 return(1); |
721 } /* CoreAudio_rewind */ | 721 } /* CoreAudio_rewind */ |
722 | 722 |
723 | 723 /* Note: I found this tech note: |
724 http://developer.apple.com/library/mac/#qa/qa2009/qa1678.html | |
725 I don't know if this applies to us. So far, I haven't noticed the problem, | |
726 so I haven't applied any of the techniques. | |
727 */ | |
724 static int CoreAudio_seek(Sound_Sample *sample, Uint32 ms) | 728 static int CoreAudio_seek(Sound_Sample *sample, Uint32 ms) |
725 { | 729 { |
726 OSStatus error_result = noErr; | 730 OSStatus error_result = noErr; |
727 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; | 731 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
728 CoreAudioFileContainer* core_audio_file_container = (CoreAudioFileContainer *) internal->decoder_private; | 732 CoreAudioFileContainer* core_audio_file_container = (CoreAudioFileContainer *) internal->decoder_private; |
729 SInt64 frame_offset = 0; | 733 SInt64 frame_offset = 0; |
730 AudioStreamBasicDescription actual_format; | 734 AudioStreamBasicDescription actual_format; |
731 UInt32 format_size; | 735 UInt32 format_size; |
732 | 736 |
737 | |
738 /* I'm confused. The Apple documentation says this: | |
739 "Seek position is specified in the sample rate and frame count of the file’s audio data format | |
740 — not your application’s audio data format." | |
741 My interpretation is that I want to get the "actual format of the file and compute the frame offset. | |
742 But when I try that, seeking goes to the wrong place. | |
743 When I use outputFormat, things seem to work correctly. | |
744 I must be misinterpreting the documentation or doing something wrong. | |
745 */ | |
746 #if 0 /* not working */ | |
733 format_size = sizeof(AudioStreamBasicDescription); | 747 format_size = sizeof(AudioStreamBasicDescription); |
734 error_result = AudioFileGetProperty( | 748 error_result = AudioFileGetProperty( |
735 *core_audio_file_container->audioFileID, | 749 *core_audio_file_container->audioFileID, |
736 kAudioFilePropertyDataFormat, | 750 kAudioFilePropertyDataFormat, |
737 &format_size, | 751 &format_size, |
742 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | 756 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
743 BAIL_MACRO("Core Audio: Could not GetProperty for kAudioFilePropertyDataFormat.", 0); | 757 BAIL_MACRO("Core Audio: Could not GetProperty for kAudioFilePropertyDataFormat.", 0); |
744 } /* if */ | 758 } /* if */ |
745 | 759 |
746 // packetIndex = (pos * sampleRate) / framesPerPacket | 760 // packetIndex = (pos * sampleRate) / framesPerPacket |
747 frame_offset = (SInt64)((ms/1000.0 * actual_format.mSampleRate) / actual_format.mFramesPerPacket); | 761 // frame_offset = (SInt64)((ms/1000.0 * actual_format.mSampleRate) / actual_format.mFramesPerPacket); |
762 #else /* seems to work, but I'm confused */ | |
763 // packetIndex = (pos * sampleRate) / framesPerPacket | |
764 frame_offset = (SInt64)((ms/1000.0 * core_audio_file_container->outputFormat->mSampleRate) / core_audio_file_container->outputFormat->mFramesPerPacket); | |
765 #endif | |
766 | |
748 // computed against actual format and not the client format | 767 // computed against actual format and not the client format |
749 error_result = ExtAudioFileSeek(core_audio_file_container->extAudioFileRef, frame_offset); | 768 error_result = ExtAudioFileSeek(core_audio_file_container->extAudioFileRef, frame_offset); |
750 if(error_result != noErr) | 769 if(error_result != noErr) |
751 { | 770 { |
752 sample->flags |= SOUND_SAMPLEFLAG_ERROR; | 771 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |