this repo has no description
at fixPythonPipStalling 165 lines 6.4 kB view raw
1/* Copyright: � Copyright 2005 Apple Computer, Inc. All rights reserved. 2 3 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. 4 ("Apple") in consideration of your agreement to the following terms, and your 5 use, installation, modification or redistribution of this Apple software 6 constitutes acceptance of these terms. If you do not agree with these terms, 7 please do not use, install, modify or redistribute this Apple software. 8 9 In consideration of your agreement to abide by the following terms, and subject 10 to these terms, Apple grants you a personal, non-exclusive license, under Apple�s 11 copyrights in this original Apple software (the "Apple Software"), to use, 12 reproduce, modify and redistribute the Apple Software, with or without 13 modifications, in source and/or binary forms; provided that if you redistribute 14 the Apple Software in its entirety and without modifications, you must retain 15 this notice and the following text and disclaimers in all such redistributions of 16 the Apple Software. Neither the name, trademarks, service marks or logos of 17 Apple Computer, Inc. may be used to endorse or promote products derived from the 18 Apple Software without specific prior written permission from Apple. Except as 19 expressly stated in this notice, no other rights or licenses, express or implied, 20 are granted by Apple herein, including but not limited to any patent rights that 21 may be infringed by your derivative works or by other works in which the Apple 22 Software may be incorporated. 23 24 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO 25 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 26 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 28 COMBINATION WITH YOUR PRODUCTS. 29 30 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 32 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION 34 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT 35 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN 36 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37*/ 38/*============================================================================= 39 CAChannelMappingPlayer.cpp 40 41=============================================================================*/ 42 43#include "CAChannelMappingPlayer.h" 44#include "CAXException.h" 45 46#if DEBUG 47 #define VERBOSE 1 48#endif 49 50CAChannelMappingPlayer::CAChannelMappingPlayer(int nBuffers, UInt32 bufferSizeFrames) : 51 CAAudioFilePlayer(nBuffers, bufferSizeFrames), 52 mMapper(NULL) 53{ 54} 55 56CAChannelMappingPlayer::~CAChannelMappingPlayer() 57{ 58 delete mMapper; 59} 60 61void CAChannelMappingPlayer::SetupChannelMapping() 62{ 63 delete mMapper; 64 mMapper = NULL; 65 66 const CAStreamBasicDescription &fileFormat = GetFile().GetClientDataFormat(); 67 CAStreamBasicDescription deviceFormat; 68 UInt32 propertySize = sizeof(AudioStreamBasicDescription); 69 70 XThrowIfError(AudioUnitGetProperty( 71 GetOutputUnit(), 72 kAudioUnitProperty_StreamFormat, 73 kAudioUnitScope_Output, 74 0, 75 (void *)&deviceFormat, 76 &propertySize), "get output device's format"); 77 78#if VERBOSE 79 printf("CAChannelMappingPlayer::SetupChannelMapping: %ld-ch file, %ld-ch device\n", 80 fileFormat.mChannelsPerFrame, deviceFormat.mChannelsPerFrame); 81#endif 82 83 if (fileFormat.mChannelsPerFrame <= deviceFormat.mChannelsPerFrame) { 84 // no mapping needed, use output unit's default behavior 85 // (default stereo pair and speaker config from AMS) 86#if VERBOSE 87 printf(" using output unit's channel mapping\n"); 88#endif 89 CAAudioFilePlayer::SetupChannelMapping(); 90 } else { 91 // fewer device than file channels, mapping needed 92 CAAudioChannelLayout fileLayout, deviceLayout; 93 94#if VERBOSE 95 printf(" using our own channel mapping\n"); 96#endif 97 deviceFormat.mSampleRate = fileFormat.mSampleRate; 98 deviceFormat.SetCanonical(deviceFormat.mChannelsPerFrame, false); // force deinterleaved 99 100 fileLayout = GetFile().GetFileChannelLayout(); 101 102 UInt32 layoutSize; 103 Boolean writable; 104 OSStatus err = AudioUnitGetPropertyInfo( 105 GetOutputUnit(), 106 kAudioUnitProperty_AudioChannelLayout, 107 kAudioUnitScope_Input, 108 0, 109 &layoutSize, 110 &writable); 111 if (!err) { 112 char *buf = (char *)malloc(layoutSize); 113 err = AudioUnitGetProperty( 114 GetOutputUnit(), 115 kAudioUnitProperty_AudioChannelLayout, 116 kAudioUnitScope_Input, 117 0, 118 buf, 119 &layoutSize); 120 deviceLayout = CAAudioChannelLayout(reinterpret_cast<AudioChannelLayout *>(buf)); 121 free(buf); 122 } 123 mMapper = new CAChannelMapper(fileFormat, deviceFormat, &fileLayout, &deviceLayout); 124 125 // give the output unit the same number of channels as in the device, 126 // since we'll be doing the mapping ourselves 127 XThrowIfError(AudioUnitSetProperty( 128 GetOutputUnit(), 129 kAudioUnitProperty_StreamFormat, 130 kAudioUnitScope_Input, 131 0, 132 (void *)&deviceFormat, 133 sizeof(AudioStreamBasicDescription)), "set audio output format"); 134 135 XThrowIfError(mMapper->OpenMixer(fileFormat.mSampleRate), "open mixer"); 136 XThrowIfError(mMapper->ConfigureDownmix(), "configure downmix"); 137 138 AudioUnitConnection conn; 139 conn.sourceAudioUnit = mMapper->GetMixer(); 140 conn.sourceOutputNumber = 0; 141 conn.destInputNumber = 0; 142 143 XThrowIfError(AudioUnitSetProperty( 144 GetOutputUnit(), 145 kAudioUnitProperty_MakeConnection, 146 kAudioUnitScope_Global, 147 0, 148 (void *)&conn, 149 sizeof(AudioUnitConnection)), "connect mixer to output unit"); 150 151 AURenderCallbackStruct input; 152 input.inputProc = InputProc; 153 input.inputProcRefCon = this; 154 XThrowIfError(AudioUnitSetProperty( 155 conn.sourceAudioUnit, 156 kAudioUnitProperty_SetRenderCallback, 157 kAudioUnitScope_Global, 158 0, 159 &input, 160 sizeof(input)), "connect input proc to mixer"); 161 // provide NO channel layout 162// mReadBuf = CABufferList::New("", fileFormat); 163// mReadBuf->AllocateBuffers( 164 } 165}