Mercurial > sdl-ios-xcode
comparison src/cdrom/macosx/CDPlayer.cpp @ 935:f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 21 Aug 2004 02:06:30 +0000 |
parents | 08b7fc2b5225 |
children |
comparison
equal
deleted
inserted
replaced
934:af585d6efec8 | 935:f8d5ddc7aef1 |
---|---|
65 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ | 65 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ |
66 | 66 |
67 #pragma mark -- Prototypes -- | 67 #pragma mark -- Prototypes -- |
68 | 68 |
69 static OSStatus CheckInit (); | 69 static OSStatus CheckInit (); |
70 | |
71 static OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus); | |
72 | 70 |
73 static void FilePlayNotificationHandler (void* inRefCon, OSStatus inStatus); | 71 static void FilePlayNotificationHandler (void* inRefCon, OSStatus inStatus); |
74 | 72 |
75 static int RunCallBackThread (void* inRefCon); | 73 static int RunCallBackThread (void* inRefCon); |
76 | 74 |
421 if (thePlayer == NULL) { | 419 if (thePlayer == NULL) { |
422 SDL_SetError ("LoadFile: Could not create player"); | 420 SDL_SetError ("LoadFile: Could not create player"); |
423 throw (-3); | 421 throw (-3); |
424 } | 422 } |
425 | 423 |
426 thePlayer->SetDestination(theUnit, 0); | 424 thePlayer->SetDestination(theUnit); |
427 | 425 |
428 if (startFrame >= 0) | 426 if (startFrame >= 0) |
429 thePlayer->SetStartFrame (startFrame); | 427 thePlayer->SetStartFrame (startFrame); |
430 | 428 |
431 if (stopFrame >= 0 && stopFrame > startFrame) | 429 if (stopFrame >= 0 && stopFrame > startFrame) |
603 // you need to initialize the output unit before you set it as a destination | 601 // you need to initialize the output unit before you set it as a destination |
604 result = AudioUnitInitialize (theUnit); | 602 result = AudioUnitInitialize (theUnit); |
605 THROW_RESULT("CheckInit: AudioUnitInitialize") | 603 THROW_RESULT("CheckInit: AudioUnitInitialize") |
606 | 604 |
607 | 605 |
608 // In this case we first want to get the output format of the OutputUnit | |
609 // Then we set that as the input format. Why? | |
610 // So that only a single conversion process is done | |
611 // when SetDestination is called it will get the input format of the | |
612 // unit its supplying data to. This defaults to 44.1K, stereo, so if | |
613 // the device is not that, then we lose a possibly rendering of data | |
614 | |
615 result = MatchAUFormats (theUnit, 0); | |
616 THROW_RESULT("CheckInit: MatchAUFormats") | |
617 | |
618 playBackWasInit = true; | 606 playBackWasInit = true; |
619 } | 607 } |
620 catch (...) | 608 catch (...) |
621 { | 609 { |
622 return -1; | 610 return -1; |
623 } | 611 } |
624 | 612 |
625 return 0; | 613 return 0; |
626 } | |
627 | |
628 | |
629 static OSStatus MatchAUFormats (AudioUnit theUnit, UInt32 theInputBus) | |
630 { | |
631 AudioStreamBasicDescription theDesc; | |
632 UInt32 size = sizeof (theDesc); | |
633 OSStatus result = AudioUnitGetProperty (theUnit, | |
634 kAudioUnitProperty_StreamFormat, | |
635 kAudioUnitScope_Output, | |
636 0, | |
637 &theDesc, | |
638 &size); | |
639 THROW_RESULT("MatchAUFormats: AudioUnitGetProperty") | |
640 | |
641 result = AudioUnitSetProperty (theUnit, | |
642 kAudioUnitProperty_StreamFormat, | |
643 kAudioUnitScope_Input, | |
644 theInputBus, | |
645 &theDesc, | |
646 size); | |
647 | |
648 return result; | |
649 } | 614 } |
650 | 615 |
651 static void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus) | 616 static void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus) |
652 { | 617 { |
653 if (inStatus == kAudioFilePlay_FileIsFinished) { | 618 if (inStatus == kAudioFilePlay_FileIsFinished) { |