// Original code...
IOAudioToggleControl *IOAudioToggleControl::create(bool initialValue,
                                               UInt32 channelID,
                                               const char *channelName,
                                               UInt32 cntrlID,
                                               UInt32 subType,
                                               UInt32 usage)
{
    IOAudioToggleControl *control;

    control = new IOAudioToggleControl;

    if (control) {
        if (!control->init(initialValue, channelID, channelName, cntrlID, subType, usage)) {
             control->release();
             control = 0;
        }
    }

    return control;
}
Beispiel #2
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;
}