예제 #1
0
void	SMACscom::SetInfo(SoundSource inSourceID, OSType inSelector, void* inData)
{
    switch(inSelector)
    {
        case siCompressionParams:
            {
                //	process the the new params and produce an initialized
                //	AudioCodec instance
                ComponentInstance theEncoder = SetCompressionParams(inData);
                ThrowIf(theEncoder == NULL, badFormat, "SMACscom::SetInfo: siCompressionParams didn't generate an encoder");

                //	get rid of the input data
                mSourceData = NULL;
                mOutputData.desc.sampleCount = 0;
                mOutputData.bufferSize = 0;
                mOutputData.frameCount = 0;
                mOutputData.commonFrameSize = 0;

                //	close the old encoder if necessary
                if((mEncoder != NULL) && (theEncoder != mEncoder))
                {
                    CloseComponent(mEncoder);
                }
                
                //	use the new one
                mEncoder = theEncoder;
                
                //	get the number of frames in 1 packet of data
                UInt32 theSize = sizeof(UInt32);
                ComponentResult theError = AudioCodecGetProperty(mEncoder, kAudioCodecPropertyPacketFrameSize, &theSize, &mPacketFrameSize);
                ThrowIfError(theError, (CAException)theError, "SMACscom::SetInfo: siCompressionParams got an error from AudioCodecGetProperty while getting the packet frame size");
                
                //	get the maximum number of bytes in 1 packet of data
                theSize = sizeof(UInt32);
                theError = AudioCodecGetProperty(mEncoder, kAudioCodecPropertyMaximumPacketByteSize, &theSize, &mMaxPacketByteSize);
                ThrowIfError(theError, (CAException)theError, "SMACscom::SetInfo: siCompressionParams got an error from AudioCodecGetProperty while getting the maximum packet byte size");
                
                //	toss the old output buffer
                delete[] mOutputBuffer;
                
                //	allocate enough space for 1 packet of data, since that's
                //	that's all this component will produce per call to GetSourceData
                mOutputBuffer = new Byte[mMaxPacketByteSize];
            }
            break;
        
        case siSourceIsExhausted:
			// in this case it seems to be passed by value -- ugh!
            mSourceIsExhausted = (Boolean)((UInt32)inData);
            // Now pass this on, so no break!
        default:
            ThrowIf(mSourceComponent == NULL, siUnknownInfoType, "SMACscom::SetInfo: no source to pass request to")
            ComponentResult theError = SoundComponentSetInfo(mSourceComponent, inSourceID, inSelector, inData);
            ThrowIfError(theError, (CAException)theError, "SMACscom::SetInfo: got an error from SoundComponentSetInfo");
            break;
    };
}
예제 #2
0
pascal ComponentResult 
__SoundComponentSetInfo(void *dummy, SoundSource sourceID, OSType selector, void *infoPtr)
{
	ComponentResult result = noErr;
	int i, setvol=false;
#if DEBUG
	long sel[2]; sel[0] = selector; sel[1]=0;
	lprintf("SetInfo '%s'\n", (char*)sel);
#endif

	switch( selector ) {
	case siSampleSize: { /* set sample size */
		int sampleSize = (int) infoPtr;
		
		result = siInvalidSampleSize;
		for( i=kSampleSizesCount-1; i >= 0; --i ) {
			if( (HW_GLOBAL.sampleSizesActive[i]) &&
			    (HW_GLOBAL.sampleSizes[i] == sampleSize)) {
				HW_GLOBAL.sampleSize = sampleSize;
				HW_GLOBAL.dirty = true;
				result = noErr;
				break;
			}
		}
		break;
	}

	case siSampleRate: { /* set sample rate */
		UnsignedFixed sampleRate = (UnsignedFixed) infoPtr;

		result = siInvalidSampleRate;
		for( i=kSampleRatesCount-1; i >= 0; --i ) {
			if( (HW_GLOBAL.sampleRatesActive[i]) &&
			    (HW_GLOBAL.sampleRates[i] == sampleRate)) {
				HW_GLOBAL.sampleRate = sampleRate;
				HW_GLOBAL.dirty = true;
				result = noErr;
				break;
			}
		}
		break;
	}

	case siNumberChannels: { /* set no. channels */
		int numChannels = (int) infoPtr;

		result = notEnoughHardware;
		for( i=kChannelsCount-1; i >= 0; --i ) {
			if( (HW_GLOBAL.channelsActive[i]) &&
			    (HW_GLOBAL.channels[i] == numChannels)) {
				HW_GLOBAL.numChannels = numChannels;
				HW_GLOBAL.dirty = true;
				result = noErr;
				break;
			}
		}
		break;
	}

	case siHardwareVolume:
		HW_GLOBAL.volume = (long) infoPtr;
		HW_GLOBAL.speakerVolume = (long) infoPtr;				
		HW_GLOBAL.dirty = true;
		setvol=true;
		break;

	case siHardwareMute:
	case siSpeakerMute:
		HW_GLOBAL.hardwareMute = (int) infoPtr;
		HW_GLOBAL.dirty = true;
		setvol=true;
		break;

	/* if you do not handle this selector, then call up the chain */
	default:
		result = SoundComponentSetInfo( GLOBAL.sourceComponent, sourceID, selector, infoPtr );
		break;
	}

	if( setvol )
		OSI_SoundSetVolume( HW_GLOBAL.volume, HW_GLOBAL.speakerVolume, HW_GLOBAL.hardwareMute );
	return result;
}
예제 #3
0
void	SMACsdec::SetInfo(SoundSource inSourceID, OSType inSelector, void* inData)
{
    switch(inSelector)
	{
		case siDecompressionParams:
			{
			#if	TARGET_API_MAC_OSX
				// Lock the thread if we can as we are going to completely replace the decoder
				bool threadLocked;

				threadLocked = mThreadStateMutex->Lock();
			#endif

				//	process the the new params and produce an initialized
				//	AudioCodec instance
				ComponentInstance theDecoder = SetDecompressionParams(inData);
				ThrowIf(theDecoder == NULL, badFormat, "SMACsdec::SetInfo: siDecompressionParams didn't generate a decoder");

				//	get rid of the input data
				mSourceData = NULL;
				mOutputData.sampleCount = 0;
	
				//	close the old decoder if necessary
				if((mDecoder != NULL) && (theDecoder != mDecoder))
				{
#if USE_DIRECT_ADEC
					DirectAudioCodecClose(mDecoder);
#else
					CloseComponent(mDecoder);
#endif
				}
				
				//	use the new one
				mDecoder = theDecoder;
				
				//	get the number of frames in 1 packet of data
				UInt32 theSize = sizeof(UInt32);
				ComponentResult theError = AudioCodecGetProperty(mDecoder, kAudioCodecPropertyPacketFrameSize, &theSize, &mPacketFrameSize);
				ThrowIfError(theError, (CAException)theError, "SMACsdec::SetInfo: siDecompressionParams got an error from AudioCodecGetProperty");
				
				//	toss the old output buffer
				delete[] mOutputBuffer;
				delete[] mFloatBuffer;
				
				//	allocate enough space for 1 packet of data, since that's
				//	that's all this component will produce per call to GetSourceData
				//	note that this is going to be 16 bit integer
				mOutputBuffer = new Byte[mPacketFrameSize * 2 * mOutputData.numChannels];
                mFloatBuffer = new float[mPacketFrameSize * mOutputData.numChannels];
				
			#if	TARGET_API_MAC_OSX
				// If we need to, unlock the thread
				if(threadLocked)
				{
					mThreadStateMutex->Unlock();
				}
			#endif
			}
			break;

		default:
			ThrowIf(mSourceComponent == NULL, siUnknownInfoType, "SMACsdec::SetInfo: no source to pass request to")
			ComponentResult theError = SoundComponentSetInfo(mSourceComponent, inSourceID, inSelector, inData);
			throw theError;
			break;
	};
}