AudioHardwareOutput.cpp [plain text]
#include "AudioHardwareCommon.h"
#include "AudioHardwareOutput.h"
#include "AudioHardwareConstants.h"
#include "AppleOnboardAudio.h"
#define super IOAudioPort
OSDefineMetaClassAndStructors(AudioHardwareOutput, IOAudioPort)
AudioHardwareOutput *AudioHardwareOutput::create(AudioHardwareOutputInfo theInfo){
AudioHardwareOutput *myOutput;
myOutput = new AudioHardwareOutput;
if(myOutput) {
if(!(myOutput->init(theInfo))){
myOutput->release();
myOutput = 0;
}
}
return myOutput;
}
bool AudioHardwareOutput::init(AudioHardwareOutputInfo theInfo) {
if(!super::init())
return(false);
volumeLeft = 0;
volumeRight = 0;
mute = 0;
active = true;
deviceMask = theInfo.deviceMask;
oKind = theInfo.portType;
sndHWPort = theInfo.portConnection;
deviceMatch = theInfo.deviceMatch;
nameResID = theInfo.nameID;
iconResID = theInfo.iconID;
pluginRef = 0;
outputKind = theInfo.outputKind;
if (kOutputPortTypeProj5==outputKind)
invertMute = ((theInfo.param) !=0);
return(true);
}
void AudioHardwareOutput::free(){
super::free();
}
void AudioHardwareOutput::attachAudioPluginRef(AppleOnboardAudio *theAudioPlugin){
pluginRef = theAudioPlugin;
}
void AudioHardwareOutput::deviceIntService( UInt32 currentDevices ) {
UInt32 progOutputBits;
OSNumber * activeOutput;
switch(outputKind) {
case kOutputPortTypeClassic:
case kOutputPortTypeProj3:
active = (deviceMask & currentDevices) == deviceMatch;
if(active) {
pluginRef->sndHWSetActiveOutputExclusive(sndHWPort);
if (NULL != pluginRef->outputSelector) {
activeOutput = OSNumber::withNumber (kIOAudioOutputPortSubTypeHeadphones, 32);
pluginRef->outputSelector->hardwareValueChanged (activeOutput);
}
} else {
if (NULL != pluginRef->outputSelector) {
activeOutput = OSNumber::withNumber (kIOAudioOutputPortSubTypeInternalSpeaker, 32);
pluginRef->outputSelector->hardwareValueChanged (activeOutput);
}
}
break;
case kOutputPortTypeProj5:
if ((deviceMask & currentDevices) != 0) {
active = true;
pluginRef->sndHWSetActiveOutputExclusive (sndHWPort);
if ((kSndHWCPUHeadphone & currentDevices) == kSndHWCPUHeadphone) {
progOutputBits = pluginRef->sndHWGetProgOutput ();
if (invertMute) {
progOutputBits &= ~kSndHWProgOutput1;
} else {
progOutputBits |= kSndHWProgOutput1;
}
pluginRef->sndHWSetProgOutput (progOutputBits);
if (NULL != pluginRef->outputSelector) {
activeOutput = OSNumber::withNumber (kIOAudioOutputPortSubTypeHeadphones, 32);
pluginRef->outputSelector->hardwareValueChanged (activeOutput);
}
} else {
progOutputBits = pluginRef->sndHWGetProgOutput ();
if(invertMute) {
progOutputBits |= kSndHWProgOutput1;
} else {
progOutputBits &= ~kSndHWProgOutput1;
}
pluginRef->sndHWSetProgOutput (progOutputBits);
if (NULL != pluginRef->outputSelector) {
activeOutput = OSNumber::withNumber (kIOAudioOutputPortSubTypeInternalSpeaker, 32);
pluginRef->outputSelector->hardwareValueChanged (activeOutput);
}
}
} else { active = false;
if (NULL != pluginRef->outputSelector) {
activeOutput = OSNumber::withNumber (kIOAudioOutputPortSubTypeExternalSpeaker, 32);
pluginRef->outputSelector->hardwareValueChanged (activeOutput);
}
}
break;
default:
break;
}
if (NULL != pluginRef->headphoneConnection && (oKind == kIOAudioOutputPortSubTypeHeadphones || oKind == kIOAudioOutputPortSubTypeExternalSpeaker || oKind == kIOAudioOutputPortSubTypeLine)) {
OSNumber * headphoneState;
headphoneState = OSNumber::withNumber ((long long unsigned int)active, 32);
(void)pluginRef->headphoneConnection->hardwareValueChanged (headphoneState);
}
ioLog();
}
void AudioHardwareOutput::ioLog(){
switch (outputKind) {
case kOutputPortTypeUnknown:
debugIOLog("+ Info for output port : unknown");
break;
case kOutputPortTypeProj5:
debugIOLog("+ Info for output port : Proj5");
break;
case kOutputPortTypeProj3:
debugIOLog("+ Info for output port : Proj3");
break;
case kOutputPortTypeEQ:
debugIOLog("+ Info for output port : EQ");
break;
}
if(active) {
debug2IOLog(" The output is active of type %4.4s\n", (char*)&oKind);
} else {
debug2IOLog(" The output is inactive of type %4.4s\n", (char*)&oKind);
}
}
void AudioHardwareOutput::setMute(bool muteState ){
UInt32 progOutbits;
if(kOutputPortTypeProj3 == outputKind) {
progOutbits = pluginRef->sndHWGetProgOutput();
if(muteState)
progOutbits &= ~kSndHWProgOutput0;
else
progOutbits |= kSndHWProgOutput0;
pluginRef->sndHWSetProgOutput(progOutbits);
pluginRef->sndHWSetSystemMute(muteState);
} else {
pluginRef->sndHWSetSystemMute(muteState);
}
mute = muteState;
}
bool AudioHardwareOutput::getMute(void){
return(mute);
}
void AudioHardwareOutput::setVolume(UInt32 volLeft, UInt32 volRight){
pluginRef->sndHWSetSystemVolume(volLeft, volRight);
volumeLeft = volLeft;
volumeRight = volRight;
}
UInt32 AudioHardwareOutput::getVolume(short Channel){
switch (Channel) {
case 1:
return(volumeLeft);
break;
case 2:
return(volumeRight);
break;
default:
return 0;
break;
}
}