Exemplo n.º 1
0
IOAudioPort *IOAudioPort::withAttributes(UInt32 portType, const char *portName, UInt32 subType, OSDictionary *properties)
{
    IOAudioPort *port;

    port = new IOAudioPort;
    if (port) {
        if (!port->initWithAttributes(portType, portName, subType, properties)) {
            port->release();
            port = 0;
        }
    }

    return port;
}
Exemplo n.º 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;
}