[soundflower] r115 committed - simplifying code / reducing complexity that wasn't actually doing anyt...

6 views
Skip to first unread message

sound...@googlecode.com

unread,
Mar 12, 2010, 2:56:22 PM3/12/10
to soundfl...@googlegroups.com
Revision: 115
Author: t...@electrotap.com
Date: Fri Mar 12 10:31:14 2010
Log: simplifying code / reducing complexity that wasn't actually doing
anything -- for example options for separate input and output buffers which
were not settable from anywhere.
http://code.google.com/p/soundflower/source/detail?r=115

Modified:
/trunk/Source/SoundflowerDevice.cpp
/trunk/Source/SoundflowerEngine.cpp
/trunk/Source/SoundflowerEngine.h

=======================================
--- /trunk/Source/SoundflowerDevice.cpp Fri Mar 12 10:30:51 2010
+++ /trunk/Source/SoundflowerDevice.cpp Fri Mar 12 10:31:14 2010
@@ -26,7 +26,7 @@
timer's inconsistencies.

Soundflower basically copies the mixbuffer and presents it to clients
- as an input buffer, allowing a applications to send audio one another.
+ as an input buffer, allowing applications to send audio one another.
*/

#include "SoundflowerDevice.h"
@@ -52,18 +52,15 @@

//IOLog("SoundflowerDevice[%p]::initHardware(%p)\n", this, provider);

- if (!super::initHardware(provider)) {
+ if (!super::initHardware(provider))
goto Done;
- }
-

setDeviceName("Soundflower");
setDeviceShortName("Soundflower");
setManufacturerName("ma++ ingalls for Cycling '74");

- if (!createAudioEngines()) {
+ if (!createAudioEngines())
goto Done;
- }

result = true;

@@ -93,14 +90,14 @@
while (audioEngineDict =
(OSDictionary*)audioEngineIterator->getNextObject()) {
SoundflowerEngine* audioEngine = NULL;

- if(OSDynamicCast(OSDictionary, audioEngineDict) == NULL)
+ if (OSDynamicCast(OSDictionary, audioEngineDict) == NULL)
continue;

audioEngine = new SoundflowerEngine;
- if(!audioEngine)
+ if (!audioEngine)
continue;

- if(!audioEngine->init(audioEngineDict))
+ if (!audioEngine->init(audioEngineDict))
continue;

initControls(audioEngine);
@@ -131,13 +128,14 @@
mMuteOut[channel] = mMuteIn[channel] = false;
}

- char *channelNameMap[17] = {kIOAudioControlChannelNameAll,
- kIOAudioControlChannelNameLeft,
- kIOAudioControlChannelNameRight,
- kIOAudioControlChannelNameCenter,
- kIOAudioControlChannelNameLeftRear,
- kIOAudioControlChannelNameRightRear,
- kIOAudioControlChannelNameSub};
+ const char *channelNameMap[17] = { kIOAudioControlChannelNameAll,
+ kIOAudioControlChannelNameLeft,
+ kIOAudioControlChannelNameRight,
+ kIOAudioControlChannelNameCenter,
+ kIOAudioControlChannelNameLeftRear,
+ kIOAudioControlChannelNameRightRear,
+ kIOAudioControlChannelNameSub };
+
for (UInt32 channel=7; channel <= 16; channel++)
channelNameMap[channel] = "Unknown Channel";

@@ -204,40 +202,27 @@

IOReturn SoundflowerDevice::volumeChanged(IOAudioControl *volumeControl,
SInt32 oldValue, SInt32 newValue)
{
- //IOLog("SoundflowerDevice[%p]::volumeChanged(%p, %d, %d)\n", this,
volumeControl, (int)oldValue, (int)newValue);
-
- if (volumeControl) {
- //IOLog("\t-> Channel %ld\n", volumeControl->getChannelID());
+ if (volumeControl)
mVolume[volumeControl->getChannelID()] = newValue;
- }
-
return kIOReturnSuccess;
}


IOReturn SoundflowerDevice::outputMuteChangeHandler(IOService *target,
IOAudioControl *muteControl, SInt32 oldValue, SInt32 newValue)
{
- IOReturn result = kIOReturnBadArgument;
- SoundflowerDevice *audioDevice;
-
- audioDevice = (SoundflowerDevice *)target;
- if (audioDevice) {
+ IOReturn result = kIOReturnBadArgument;
+ SoundflowerDevice* audioDevice = (SoundflowerDevice*)target;
+
+ if (audioDevice)
result = audioDevice->outputMuteChanged(muteControl, oldValue,
newValue);
- }
-
return result;
}


IOReturn SoundflowerDevice::outputMuteChanged(IOAudioControl *muteControl,
SInt32 oldValue, SInt32 newValue)
{
- //IOLog("SoundflowerDevice[%p]::outputMuteChanged(%p, %ld, %ld)\n",
this, muteControl, oldValue, newValue);
-
- if (muteControl) {
- //IOLog("\t-> Channel %ld\n", muteControl->getChannelID());
+ if (muteControl)
mMuteOut[muteControl->getChannelID()] = newValue;
- }
-
return kIOReturnSuccess;
}

@@ -255,39 +240,26 @@

IOReturn SoundflowerDevice::gainChanged(IOAudioControl *gainControl,
SInt32 oldValue, SInt32 newValue)
{
- //IOLog("SoundflowerDevice[%p]::gainChanged(%p, %d, %d)\n", this,
gainControl, (int)oldValue, (int)newValue);
-
- if (gainControl) {
- //IOLog("\t-> Channel %ld\n", gainControl->getChannelID());
- mGain[gainControl->getChannelID()] = newValue;
- }
-
+ if (gainControl)
+ mGain[gainControl->getChannelID()] = newValue;
return kIOReturnSuccess;
}


IOReturn SoundflowerDevice::inputMuteChangeHandler(IOService *target,
IOAudioControl *muteControl, SInt32 oldValue, SInt32 newValue)
{
- IOReturn result = kIOReturnBadArgument;
- SoundflowerDevice *audioDevice;
-
- audioDevice = (SoundflowerDevice *)target;
- if (audioDevice) {
+ IOReturn result = kIOReturnBadArgument;
+ SoundflowerDevice* audioDevice = (SoundflowerDevice*)target;
+
+ if (audioDevice)
result = audioDevice->inputMuteChanged(muteControl, oldValue,
newValue);
- }
-
return result;
}


IOReturn SoundflowerDevice::inputMuteChanged(IOAudioControl *muteControl,
SInt32 oldValue, SInt32 newValue)
{
- //IOLog("SoundflowerDevice[%p]::inputMuteChanged(%p, %ld, %ld)\n",
this, muteControl, oldValue, newValue);
-
- if (muteControl) {
- //IOLog("\t-> Channel %ld\n", muteControl->getChannelID());
+ if (muteControl)
mMuteIn[muteControl->getChannelID()] = newValue;
- }
-
return kIOReturnSuccess;
}
=======================================
--- /trunk/Source/SoundflowerEngine.cpp Fri Mar 12 10:31:06 2010
+++ /trunk/Source/SoundflowerEngine.cpp Fri Mar 12 10:31:14 2010
@@ -146,21 +146,16 @@
OSArray* sampleRateArray = NULL;
UInt32 startingChannelID = 1;
OSString* desc;
- bool separateStreamBuffers = FALSE;
- bool separateInputBuffers = FALSE;

desc = OSDynamicCast(OSString, getProperty(DESCRIPTION_KEY));
- if (desc) {
+ if (desc)
setDescription(desc->getCStringNoCopy());
- }

number = OSDynamicCast(OSNumber, getProperty(NUM_STREAMS_KEY));
- if (number) {
+ if (number)
numStreams = number->unsigned32BitValue();
- }
- else {
+ else
numStreams = NUM_STREAMS;
- }

formatArray = OSDynamicCast(OSArray, getProperty(FORMATS_KEY));
if (formatArray == NULL) {
@@ -186,7 +181,6 @@
UInt32 channelID;
char outputStreamName[64];
char inputStreamName[64];
- UInt32 streamBufferSize;

initialFormatSet = false;

@@ -270,62 +264,31 @@
}
}

- streamBufferSize = blockSize * numBlocks * maxNumChannels *
maxBitWidth / 8;
- //IOLog("Soundflower streamBufferSize: %ld\n", streamBufferSize);
-
- if (outputBuffer == NULL) {
- if (separateStreamBuffers) {
- outputBufferSize = streamBufferSize * numStreams;
- }
- else {
- outputBufferSize = streamBufferSize;
- }
-
- outputBuffer = (void *)IOMalloc(outputBufferSize);
-
- if (!outputBuffer) {
- IOLog("Soundflower: Error allocating output buffer - %lu
bytes.\n", (unsigned long)outputBufferSize);
+ mBufferSize = blockSize * numBlocks * maxNumChannels * maxBitWidth
/ 8;
+ //IOLog("Soundflower streamBufferSize: %ld\n", mBufferSize);
+
+ if (mBuffer == NULL) {
+ mBuffer = (void *)IOMalloc(mBufferSize);
+ if (!mBuffer) {
+ IOLog("Soundflower: Error allocating output buffer - %lu
bytes.\n", (unsigned long)mBufferSize);
goto Error;
}
-
- // create our thru buffer
- thruBufferSize = outputBufferSize;
- thruBuffer = (float *)IOMalloc(thruBufferSize);
- if (!thruBuffer) {
- IOLog("Soundflower: Error allocating thru buffer - %lu
bytes.\n", (unsigned long)thruBufferSize);
+
+ mThruBuffer = (float*)IOMalloc(mBufferSize);
+ if (!mThruBuffer) {
+ IOLog("Soundflower: Error allocating thru buffer - %lu
bytes.\n", (unsigned long)mBufferSize);
goto Error;
}
- memset ((UInt8 *)thruBuffer, 0, thruBufferSize);
-
-
- inputBufferSize = outputBufferSize;
-
- if (separateInputBuffers) {
- inputBuffer = (void *)IOMalloc(inputBufferSize);
- if (!inputBuffer) {
- IOLog("Soundflower: Error allocating input buffer
- %lu bytes.\n", (unsigned long )inputBufferSize);
- goto Error;
- }
- } else {
- inputBuffer = outputBuffer;
- }
-
+ memset((UInt8*)mThruBuffer, 0, mBufferSize);
}

inputStream->setFormat(&initialFormat);
- outputStream->setFormat(&initialFormat);
-
- if (separateStreamBuffers) {
- inputStream->setSampleBuffer(&((UInt8
*)inputBuffer)[streamBufferSize * streamNum], streamBufferSize);
- outputStream->setSampleBuffer(&((UInt8
*)outputBuffer)[streamBufferSize * streamNum], streamBufferSize);
- }
- else {
- inputStream->setSampleBuffer(inputBuffer, streamBufferSize);
- outputStream->setSampleBuffer(outputBuffer, streamBufferSize);
- }
+ inputStream->setSampleBuffer(mBuffer, mBufferSize);
addAudioStream(inputStream);
inputStream->release();
-
+
+ outputStream->setFormat(&initialFormat);
+ outputStream->setSampleBuffer(mBuffer, mBufferSize);
addAudioStream(outputStream);
outputStream->release();

@@ -343,35 +306,23 @@
continue;

Error:
-
IOLog("SoundflowerEngine[%p]::createAudioStreams() - ERROR\n",
this);

- if (inputStream) {
+ if (inputStream)
inputStream->release();
- }
-
- if (outputStream) {
+ if (outputStream)
outputStream->release();
- }
-
- if (formatIterator) {
+ if (formatIterator)
formatIterator->release();
- }
-
- if (sampleRateIterator) {
+ if (sampleRateIterator)
sampleRateIterator->release();
- }
-
goto Done;
}
- result = true;
+ result = true;

Done:
-
- if (!result) {
+ if (!result)
IOLog("SoundflowerEngine[%p]::createAudioStreams() - failed!\n",
this);
- }
-
return result;
}

@@ -380,30 +331,18 @@
{
//IOLog("SoundflowerEngine[%p]::free()\n", this);

- // We need to free our resources when we're going away
-
- if (inputBuffer != NULL) {
- // We only need to free the input buffer if it was allocated
independently of the output buffer
- if (inputBuffer != outputBuffer) {
- IOFree(inputBuffer, inputBufferSize);
- }
-
- inputBuffer = NULL;
- }
-
- if (outputBuffer != NULL) {
- IOFree(outputBuffer, outputBufferSize);
- outputBuffer = NULL;
- }
-
- if (thruBuffer != NULL) {
- IOFree(thruBuffer, thruBufferSize);
- thruBuffer = NULL;
- }
+ if (mBuffer) {
+ IOFree(mBuffer, mBufferSize);
+ mBuffer = NULL;
+ }
+ if (mThruBuffer) {
+ IOFree(mThruBuffer, mBufferSize);
+ mThruBuffer = NULL;
+ }
super::free();
}

-
+
void SoundflowerEngine::stop(IOService *provider)
{
//IOLog("SoundflowerEngine[%p]::stop(%p)\n", this, provider);
@@ -511,7 +450,7 @@
IOAudioStream *outStream =
audioEngine->getAudioStream(kIOAudioStreamDirectionOutput, 1);
if (outStream->numClients == 0) {
// it has, so clean the buffer
- memset((UInt8 *)audioEngine->thruBuffer, 0,
audioEngine->thruBufferSize);
+ memset((UInt8*)audioEngine->mThruBuffer, 0,
audioEngine->mBufferSize);
}

audioEngine->currentBlock++;
@@ -562,10 +501,10 @@
// TODO: why is the reading always trailing by at least 512 frames? (when
512 is the input framesize)?

if (device->mMuteIn[0]) {
- memset((UInt8 *)thruBuffer + byteOffset, 0, numBytes);
+ memset((UInt8*)mThruBuffer + byteOffset, 0, numBytes);
}
else {
- memcpy((UInt8 *)thruBuffer + byteOffset, (UInt8 *)mixBuf + byteOffset,
numBytes);
+ memcpy((UInt8*)mThruBuffer + byteOffset, (UInt8 *)mixBuf + byteOffset,
numBytes);

float masterGain = device->mGain[0] /
((float)SoundflowerDevice::kGainMax);
float masterVolume = device->mVolume[0] /
((float)SoundflowerDevice::kVolumeMax);
@@ -578,9 +517,9 @@

for (UInt32 channelBufferIterator = 0; channelBufferIterator <
numSampleFrames; channelBufferIterator++) {
if (channelMute)
- thruBuffer[offset + channelBufferIterator*channelCount + channel] = 0;
+ mThruBuffer[offset + channelBufferIterator*channelCount + channel] =
0;
else
- thruBuffer[offset + channelBufferIterator*channelCount + channel] *=
adjustment;
+ mThruBuffer[offset + channelBufferIterator*channelCount + channel] *=
adjustment;
}
}
}
@@ -603,9 +542,9 @@
#endif

if (device->mMuteOut[0])
- memset((UInt8 *)destBuf, 0, numSampleFrames * frameSize);
+ memset((UInt8*)destBuf, 0, numSampleFrames * frameSize);
else
- memcpy((UInt8 *)destBuf, (UInt8 *)thruBuffer + offset,
numSampleFrames * frameSize);
+ memcpy((UInt8*)destBuf, (UInt8*)mThruBuffer + offset,
numSampleFrames * frameSize);

return kIOReturnSuccess;
}
=======================================
--- /trunk/Source/SoundflowerEngine.h Fri Mar 12 10:31:06 2010
+++ /trunk/Source/SoundflowerEngine.h Fri Mar 12 10:31:14 2010
@@ -31,27 +31,23 @@
{
OSDeclareDefaultStructors(SoundflowerEngine)

- UInt32 outputBufferSize;
- UInt32 inputBufferSize;
-
+ UInt32 mBufferSize;
+ void* mBuffer; // input/output buffer
+ float* mThruBuffer; // intermediate buffer to pass in-->out
+
IOAudioStream* outputStream;
IOAudioStream* inputStream;
-
- void* outputBuffer;
- void* inputBuffer;
+
UInt32 mLastValidSampleFrame;

- UInt32 thruBufferSize;
- float* thruBuffer; // intermediate buffer to pass in-->out
-
IOTimerEventSource* timerEventSource;

- UInt32 blockSize; // In sample frames
+ UInt32 blockSize; // In sample frames
UInt32 numBlocks;
UInt32 currentBlock;

UInt64 blockTimeoutNS;
- UInt64 nextTime; // the estimated time the timer will fire next
+ UInt64 nextTime; // the estimated time the timer will fire next

bool duringHardwareInit;

Reply all
Reply to author
Forward
0 new messages