// Original code...
IOAudioSelectorControl *IOAudioSelectorControl::create(SInt32 initialValue,
                                                        UInt32 channelID,
                                                        const char *channelName,
                                                        UInt32 cntrlID,
                                                        UInt32 subType,
                                                        UInt32 usage)
{
    IOAudioSelectorControl *control;
    
    control = new IOAudioSelectorControl;
    
    if (control) {
        if (!control->init(initialValue,
                            channelID,
                            channelName,
                            cntrlID,
                            subType,
                            usage)) {
            control->release();
            control = NULL;
        }
    }
    
    return control;
}
IOAudioSelectorControl *IOAudioSelectorControl::createInputClockSelector(SInt32 initialValue,
                                                                    UInt32 channelID,
																	UInt32 clockSource,
                                                                    const char *channelName,
                                                                    UInt32 cntrlID)
{
	IOAudioSelectorControl *clockControl;

	if ((clockControl = create (initialValue, 
                    channelID, 
                    channelName, 
                    cntrlID, 
                    kIOAudioSelectorControlSubTypeClockSource, 
                    kIOAudioControlUsageInput))) {
        clockControl->setProperty(kIOAudioSelectorControlClockSourceKey, clockSource);
	}

	return clockControl;
}
示例#3
0
bool AppleIntelAC97AudioDriver::createAudioPorts()
{
    IOAudioPort *            outputPort    = 0;
    IOAudioPort *            inputPort     = 0;
    IOAudioLevelControl *    outVolLeft    = 0;
    IOAudioLevelControl *    outVolRight   = 0;
    IOAudioLevelControl *    inGainLeft    = 0;
    IOAudioLevelControl *    inGainRight   = 0;
    IOAudioToggleControl *   outMute       = 0;
    IOAudioSelectorControl * inputSelector = 0;
    bool                     success       = false;
    UInt32                   initialVolume;

    DebugLog("%s::%s\n", getName(), __FUNCTION__);

    do {
        // Master output port.

        outputPort = IOAudioPort::withAttributes( kIOAudioPortTypeOutput,
                     "Master Output port" );
        if ( outputPort == 0 ) break;

        initialVolume = _audioCodec->getOutputVolumeMax() * 3 / 4;

        // Left master output volume.

        outVolLeft = IOAudioLevelControl::createVolumeControl(
                         /* initialValue */   initialVolume,
                         /* minValue     */   _audioCodec->getOutputVolumeMin(),
                         /* maxValue     */   _audioCodec->getOutputVolumeMax(),
                         /* minDB        */   _audioCodec->getOutputVolumeMinDB(),
                         /* maxDB        */   _audioCodec->getOutputVolumeMaxDB(),
                         /* channelID    */   kIOAudioControlChannelIDDefaultLeft,
                         /* channelName  */   kIOAudioControlChannelNameLeft,
                         /* cntrlID      */   kControlOutputVolumeL,
                         /* usage        */   kIOAudioControlUsageOutput );

        if ( outVolLeft == 0 ) break;

        outVolLeft->setValueChangeHandler( audioControlChangeHandler, this );
        _audioEngine->addDefaultAudioControl( outVolLeft );

        // Right master output volume.

        outVolRight = IOAudioLevelControl::createVolumeControl(
                          /* initialValue */   initialVolume,
                          /* minValue     */   _audioCodec->getOutputVolumeMin(),
                          /* maxValue     */   _audioCodec->getOutputVolumeMax(),
                          /* minDB        */   _audioCodec->getOutputVolumeMinDB(),
                          /* maxDB        */   _audioCodec->getOutputVolumeMaxDB(),
                          /* channelID    */   kIOAudioControlChannelIDDefaultRight,
                          /* channelName  */   kIOAudioControlChannelNameRight,
                          /* cntrlID      */   kControlOutputVolumeR,
                          /* usage        */   kIOAudioControlUsageOutput );

        if ( outVolRight == 0 ) break;

        outVolRight->setValueChangeHandler( audioControlChangeHandler, this );
        _audioEngine->addDefaultAudioControl( outVolRight );

        // Mute master output.

        outMute = IOAudioToggleControl::createMuteControl(
                      /* initialValue */    false,
                      /* channelID    */    kIOAudioControlChannelIDAll,
                      /* channelName  */    kIOAudioControlChannelNameAll,
                      /* cntrlID      */    kControlOutputMute,
                      /* usage        */    kIOAudioControlUsageOutput);

        if ( outMute == 0 ) break;

        outMute->setValueChangeHandler( audioControlChangeHandler, this );
        _audioEngine->addDefaultAudioControl( outMute );

        // Attach audio port to audio topology.

        attachAudioPort( outputPort, _audioEngine, 0 );

        // Create input port and attach it to audio topology.

        inputPort = IOAudioPort::withAttributes( kIOAudioPortTypeInput,
                    "Main Input Port" );
        if ( inputPort == 0 ) break;

        // Left input gain.

        initialVolume = 0x17;

        inGainLeft = IOAudioLevelControl::createVolumeControl(
                         /* initialValue */   initialVolume,
                         /* minValue     */   _audioCodec->getInputGainMin(),
                         /* maxValue     */   _audioCodec->getInputGainMax(),
                         /* minDB        */   _audioCodec->getInputGainMinDB(),
                         /* maxDB        */   _audioCodec->getInputGainMaxDB(),
                         /* channelID    */   kIOAudioControlChannelIDDefaultLeft,
                         /* channelName  */   kIOAudioControlChannelNameLeft,
                         /* cntrlID      */   kControlInputGainL,
                         /* usage        */   kIOAudioControlUsageInput );

        if ( inGainLeft == 0 ) break;

        inGainLeft->setValueChangeHandler( audioControlChangeHandler, this );
        _audioEngine->addDefaultAudioControl( inGainLeft );

        // Right input gain.

        inGainRight = IOAudioLevelControl::createVolumeControl(
                          /* initialValue */   initialVolume,
                          /* minValue     */   _audioCodec->getInputGainMin(),
                          /* maxValue     */   _audioCodec->getInputGainMax(),
                          /* minDB        */   _audioCodec->getInputGainMinDB(),
                          /* maxDB        */   _audioCodec->getInputGainMaxDB(),
                          /* channelID    */   kIOAudioControlChannelIDDefaultRight,
                          /* channelName  */   kIOAudioControlChannelNameRight,
                          /* cntrlID      */   kControlInputGainR,
                          /* usage        */   kIOAudioControlUsageInput );

        if ( inGainRight == 0 ) break;

        inGainRight->setValueChangeHandler( audioControlChangeHandler, this );
        _audioEngine->addDefaultAudioControl( inGainRight );

        // Create input source selector.

        inputSelector = IOAudioSelectorControl::createInputSelector(
                            /* initialValue */      kInputSourceMic1,
                            /* channelID    */      kIOAudioControlChannelIDAll,
                            /* channelName  */      kIOAudioControlChannelNameAll,
                            /* cntrlID      */      kControlInputSelector );

        if ( inputSelector == 0 ) break;

        inputSelector->addAvailableSelection( kInputSourceMic1, "Microphone" );
        inputSelector->addAvailableSelection( kInputSourceLine, "Line In" );
        inputSelector->setValueChangeHandler( audioControlChangeHandler, this );
        _audioEngine->addDefaultAudioControl( inputSelector );

        // Attach input port.

        attachAudioPort( inputPort, 0, _audioEngine );

        success = true;
    }
    while ( false );

    if ( inputPort     ) inputPort->release();
    if ( outputPort    ) outputPort->release();
    if ( outVolLeft    ) outVolLeft->release();
    if ( outVolRight   ) outVolRight->release();
    if ( inGainLeft    ) inGainLeft->release();
    if ( inGainRight   ) inGainRight->release();
    if ( outMute       ) outMute->release();
    if ( inputSelector ) inputSelector->release();

    return success;
}
示例#4
0
void	AREngine::CreateControls(UInt32 inNumberChannels)
{
	for(UInt32 theChannelID = 0; theChannelID <= inNumberChannels; ++theChannelID)
	{
		IOAudioControl* theControl;
		IOAudioSelectorControl* theSelectorControl;
		char theChannelName[32];
		if(theChannelID > 0)
		{
			snprintf(theChannelName, 32, "Channel %lu", theChannelID);
		}
		else
		{
			strncpy(theChannelName, kIOAudioControlChannelNameAll, 32);
		}
		
		//	clock source selector
		if(theChannelID == 0)
		{
			theSelectorControl = IOAudioSelectorControl::create(0, theChannelID, theChannelName, 0, kIOAudioSelectorControlSubTypeClockSource, kIOAudioControlUsageInput);
			if(theSelectorControl != NULL)
			{
				theSelectorControl->addAvailableSelection(0, "Internal");
				theSelectorControl->addAvailableSelection(1, "External 1");
				theSelectorControl->addAvailableSelection(2, "External 2");
				theSelectorControl->addAvailableSelection(3, "External 3");
				theSelectorControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theSelectorControl);
				theSelectorControl->release();
				theSelectorControl = NULL;
			}
		}
		
		//	output volume
		theControl = IOAudioLevelControl::createVolumeControl(65535, 0, 65535, (-22 << 16) + (32768), 0, theChannelID, theChannelName, 0, kIOAudioControlUsageOutput);
		if(theControl != NULL)
		{
			theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
			addDefaultAudioControl(theControl);
			theControl->release();
			theControl = NULL;
		}
		
		//	output mute
		theControl = IOAudioToggleControl::createMuteControl(false, theChannelID, theChannelName, 0, kIOAudioControlUsageOutput);
		if(theControl != NULL)
		{
			theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
			addDefaultAudioControl(theControl);
			theControl->release();
			theControl = NULL;
		}
		
		//	output solo
		if(theChannelID != 0)
		{
			theControl = IOAudioToggleControl::create(false, theChannelID, theChannelName, 0, kIOAudioToggleControlSubTypeSolo, kIOAudioControlUsageOutput);
			if(theControl != NULL)
			{
				theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theControl);
				theControl->release();
				theControl = NULL;
			}
		}
		
		//	output data source
		if(theChannelID != 0)
		{
			theSelectorControl = IOAudioSelectorControl::create(0, theChannelID, theChannelName, 0, kIOAudioSelectorControlSubTypeOutput, kIOAudioControlUsageOutput);
			if(theSelectorControl != NULL)
			{
				theSelectorControl->addAvailableSelection(0, "Source 1");
				theSelectorControl->addAvailableSelection(1, "Source 2");
				theSelectorControl->addAvailableSelection(2, "Source 3");
				theSelectorControl->addAvailableSelection(3, "Source 4");
				theSelectorControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theSelectorControl);
				theSelectorControl->release();
				theSelectorControl = NULL;
			}
		}

		//	output line level
		if(theChannelID != 0)
		{
			theSelectorControl = IOAudioSelectorControl::create(kIOAudioSelectorControlSubTypeChannelLevelMinus10dBV, theChannelID, theChannelName, 0, kIOAudioSelectorControlSubTypeChannelNominalLineLevel, kIOAudioControlUsageOutput);
			if(theSelectorControl != NULL)
			{
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelPlus4dBu, "+4dBu");
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelMinus10dBV, "-10dBV");
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelMinus20dBV, "-20dBV");
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelMicLevel, "Mic");
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelInstrumentLevel, "Instrument");
				theSelectorControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theSelectorControl);
				theSelectorControl->release();
				theSelectorControl = NULL;
			}
		}
		
		//	input volume
		theControl = IOAudioLevelControl::createVolumeControl(65535, 0, 65535, (-22 << 16) + (32768), 0, theChannelID, theChannelName, 0, kIOAudioControlUsageInput);
		if(theControl != NULL)
		{
			theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
			addDefaultAudioControl(theControl);
			theControl->release();
			theControl = NULL;
		}

		//	input mute
		theControl = IOAudioToggleControl::createMuteControl(false, theChannelID, theChannelName, 0, kIOAudioControlUsageInput);
		if(theControl != NULL)
		{
			theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
			addDefaultAudioControl(theControl);
			theControl->release();
			theControl = NULL;
		}
		
		//	input solo
		if(theChannelID != 0)
		{
			theControl = IOAudioToggleControl::create(false, theChannelID, theChannelName, 0, kIOAudioToggleControlSubTypeSolo, kIOAudioControlUsageInput);
			if(theControl != NULL)
			{
				theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theControl);
				theControl->release();
				theControl = NULL;
			}
		}
		
		//	input data source
		if(theChannelID != 0)
		{
			theSelectorControl = IOAudioSelectorControl::create(0, theChannelID, theChannelName, 0, kIOAudioSelectorControlSubTypeInput, kIOAudioControlUsageInput);
			if(theSelectorControl != NULL)
			{
				theSelectorControl->addAvailableSelection(0, "Source 1");
				theSelectorControl->addAvailableSelection(1, "Source 2");
				theSelectorControl->addAvailableSelection(2, "Source 3");
				theSelectorControl->addAvailableSelection(3, "Source 4");
				theSelectorControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theSelectorControl);
				theSelectorControl->release();
				theSelectorControl = NULL;
			}
		}

		//	input line level
		if(theChannelID != 0)
		{
			theSelectorControl = IOAudioSelectorControl::create(kIOAudioSelectorControlSubTypeChannelLevelMinus10dBV, theChannelID, theChannelName, 0, kIOAudioSelectorControlSubTypeChannelNominalLineLevel, kIOAudioControlUsageInput);
			if(theSelectorControl != NULL)
			{
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelPlus4dBu, "+4dBu");
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelMinus10dBV, "-10dBV");
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelMinus20dBV, "-20dBV");
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelMicLevel, "Mic");
				theSelectorControl->addAvailableSelection(kIOAudioSelectorControlSubTypeChannelLevelInstrumentLevel, "Instrument");
				theSelectorControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theSelectorControl);
				theSelectorControl->release();
				theSelectorControl = NULL;
			}
		}

		//	play through volume
		theControl = IOAudioLevelControl::createVolumeControl(65535, 0, 65535, (-22 << 16) + (32768), 0, theChannelID, theChannelName, 0, kIOAudioControlUsagePassThru);
		if(theControl != NULL)
		{
			theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
			addDefaultAudioControl(theControl);
			theControl->release();
			theControl = NULL;
		}

		//	play through on/off
		theControl = IOAudioToggleControl::createMuteControl(true, theChannelID, theChannelName, 0, kIOAudioControlUsagePassThru);
		if(theControl != NULL)
		{
			theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
			addDefaultAudioControl(theControl);
			theControl->release();
			theControl = NULL;
		}
		
		//	play through solo
		if(theChannelID != 0)
		{
			theControl = IOAudioToggleControl::create(false, theChannelID, theChannelName, 0, kIOAudioToggleControlSubTypeSolo, kIOAudioControlUsagePassThru);
			if(theControl != NULL)
			{
				theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theControl);
				theControl->release();
				theControl = NULL;
			}
		}
		
		//	play through data destination
		if(theChannelID != 0)
		{
			theSelectorControl = IOAudioSelectorControl::create(0, theChannelID, theChannelName, 0, kIOAudioSelectorControlSubTypeDestination, kIOAudioControlUsagePassThru);
			if(theSelectorControl != NULL)
			{
				theSelectorControl->addAvailableSelection(0, "Destination 1");
				theSelectorControl->addAvailableSelection(1, "Destination 2");
				theSelectorControl->addAvailableSelection(2, "Destination 3");
				theSelectorControl->addAvailableSelection(3, "Destination 4");
				theSelectorControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theSelectorControl);
				theSelectorControl->release();
				theSelectorControl = NULL;
			}
		}

		//	play through stereo pan
		if((inNumberChannels > 2) && (theChannelID != 0))
		{
			theControl = ARStereoPanControl::create(0, -128, 0, 128, 1, 2, theChannelID, theChannelName, 0, ARStereoPanControl::kIOAudioControlSubTypeStereoPan, kIOAudioControlUsagePassThru);
			if(theControl != NULL)
			{
				theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theControl);
				theControl->release();
				theControl = NULL;
			}
		}

		//	LFE volume
		if(theChannelID == 0)
		{
			theControl = IOAudioLevelControl::create(65535, 0, 65535, (-22 << 16) + (32768), 0, theChannelID, theChannelName, 0, kIOAudioLevelControlSubTypeLFEVolume, kIOAudioControlUsageOutput);
			if(theControl != NULL)
			{
				theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theControl);
				theControl->release();
				theControl = NULL;
			}
		}

		//	LFE mute
		if(theChannelID == 0)
		{
			theControl = IOAudioToggleControl::create(false, theChannelID, theChannelName, 0, kIOAudioToggleControlSubTypeLFEMute, kIOAudioControlUsageOutput);
			if(theControl != NULL)
			{
				theControl->setValueChangeHandler((IOAudioControl::IntValueChangeHandler)IntegerControlChangeHandler, this);
				addDefaultAudioControl(theControl);
				theControl->release();
				theControl = NULL;
			}
		}
	}
}