Modified by: [EMAIL PROTECTED]
Date: 30 Aug 06
Synopsis:
This change sets the Helix audio device sound volume only, not the
entire Mac system volume.
Overview:
My original implementation incorrectly set audio device volume by
adjusting the Mac's system volume. Correct behavior is to adjust the volume
only of the (Helix) audio device being used.
Since the CoreAudio implementation needs to have its data converted from
UINT16 (0-65535) to float (0.0-1.0) anyway, adding a scalar multiplier to
the conversion to edit the volume is straightforward and has no noticeable
performance impact.
Files Modified:
audio/device/platform/mac/osxaudio.cpp
audio/device/pub/platform/mac/osxaudio.h
Image Size and Heap Use impact (Client -Only):
Negligible
Platforms and Profiles Affected:
OS X
Distribution Libraries Affected:
None
Platforms and Profiles Build Verified:
OS X
Platforms and Profiles Functionality verified:
OS X
Branch:
HEAD
150Cay
Copyright assignment: I am a RealNetworks employee
Index: device/platform/mac/osxaudio.cpp
===================================================================
RCS file: /cvsroot/audio/device/platform/mac/osxaudio.cpp,v
retrieving revision 1.1.2.2
diff -u -w -r1.1.2.2 osxaudio.cpp
--- device/platform/mac/osxaudio.cpp 3 Aug 2006 22:47:26 -0000 1.1.2.2
+++ device/platform/mac/osxaudio.cpp 30 Aug 2006 20:10:46 -0000
@@ -60,6 +60,7 @@
, mResetTimeNanos(0)
, mElapsedNanos(0)
, mElapsedNanosAtPause(0)
+ , mCurrentVolume(75.0)
{
OSStatus err = noErr;
UInt32 dataSize;
@@ -267,32 +268,22 @@
UINT16
CAudioOutOSX::_Imp_GetVolume(void)
{
- OSStatus err = noErr;
- UINT16 uVol = 50;
- Float32 scalarVolume = 0.0;
- UInt32 dataSize = sizeof(scalarVolume);
-
- err = ::AudioDeviceGetProperty(mAudioDevice, 0, false,
kAudioDevicePropertyVolumeScalar, &dataSize, &scalarVolume);
-
- if (err == noErr)
- {
- uVol = (UINT16)(100.0 * scalarVolume + 0.5);
- }
-
- return uVol;
+ return (UINT16)(mCurrentVolume * 100.0 + 0.5);
}
HX_RESULT
CAudioOutOSX::_Imp_SetVolume(const UINT16 uVolume)
{
- OSStatus err = noErr;
- Float32 scalarVolume = (Float32)(uVolume) / 100.0;
- UInt32 dataSize = sizeof(scalarVolume);
+ mCurrentVolume = (double)uVolume / 100.0;
- err = ::AudioDeviceSetProperty(mAudioDevice, NULL, 0, false,
kAudioDevicePropertyVolumeScalar, dataSize, &scalarVolume);
- if (err != noErr)
+ // mCurrentVolume must be between 0.0 and 1.0
+ if (mCurrentVolume < 0.0)
{
- return HXR_AUDIO_DRIVER;
+ mCurrentVolume = 0.0;
+ }
+ if (mCurrentVolume > 1.0)
+ {
+ mCurrentVolume = 1.0;
}
return HXR_OK;
}
@@ -389,7 +380,7 @@
int whichChan;
for (whichChan = 0; whichChan < mInputNumberOfChannels; whichChan++)
{
- dst[whichChan] = (Float32)src[whichChan] / 32768.0;
+ dst[whichChan] = (Float32)src[whichChan] / 32768.0 *
mCurrentVolume;
}
for (whichChan = mInputNumberOfChannels; whichChan <
mDeviceNumberOfChannels; whichChan++)
{
Index: device/pub/platform/mac/osxaudio.h
===================================================================
RCS file: /cvsroot/audio/device/pub/platform/mac/osxaudio.h,v
retrieving revision 1.1.2.2
diff -u -w -r1.1.2.2 osxaudio.h
--- device/pub/platform/mac/osxaudio.h 3 Aug 2006 22:47:27 -0000 1.1.2.2
+++ device/pub/platform/mac/osxaudio.h 30 Aug 2006 20:10:46 -0000
@@ -115,6 +115,7 @@
UInt64 mResetTimeNanos;
UInt64 mElapsedNanos;
UInt64 mElapsedNanosAtPause;
+ double mCurrentVolume;
static HXMutex* zm_pMutex;
};
_______________________________________________
Audio-dev mailing list
[email protected]
http://lists.helixcommunity.org/mailman/listinfo/audio-dev