Commit 81fe8504 authored by François Grisez's avatar François Grisez

Implementation of volume gain getter/setter

parent 09164a01
......@@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
const IID IID_ISimpleAudioVolume = __uuidof(ISimpleAudioVolume);
#if defined(MS2_WINDOWS_PHONE) || defined(MS2_WINDOWS_UNIVERSAL)
const IID IID_IAudioClient2 = __uuidof(IAudioClient2);
#else
......@@ -100,11 +101,26 @@ static int ms_wasapi_read_get_nchannels(MSFilter *f, void *arg) {
return 0;
}
static int ms_wasapi_read_set_volume_gain(MSFilter *f, void *arg) {
MSWASAPIReaderType r = MSWASAPI_READER(f->data);
r->setVolumeLevel(*(float *)arg);
return 0;
}
static int ms_wasapi_read_get_volume_gain(MSFilter *f, void *arg) {
MSWASAPIReaderType r = MSWASAPI_READER(f->data);
float *volume = (float *)arg;
*volume = r->getVolumeLevel();
return *volume >= 0.0f ? 0 : -1;
}
static MSFilterMethod ms_wasapi_read_methods[] = {
{ MS_FILTER_SET_SAMPLE_RATE, ms_wasapi_read_set_sample_rate },
{ MS_FILTER_GET_SAMPLE_RATE, ms_wasapi_read_get_sample_rate },
{ MS_FILTER_SET_NCHANNELS, ms_wasapi_read_set_nchannels },
{ MS_FILTER_GET_NCHANNELS, ms_wasapi_read_get_nchannels },
{ MS_AUDIO_CAPTURE_SET_VOLUME_GAIN, ms_wasapi_read_set_volume_gain },
{ MS_AUDIO_CAPTURE_GET_VOLUME_GAIN, ms_wasapi_read_get_volume_gain },
{ 0, NULL }
};
......@@ -228,11 +244,26 @@ static int ms_wasapi_write_get_nchannels(MSFilter *f, void *arg) {
return 0;
}
static int ms_wasapi_write_set_volume_gain(MSFilter *f, void *arg) {
MSWASAPIWriterType w = MSWASAPI_WRITER(f->data);
w->setVolumeLevel(*(float *)arg);
return 0;
}
static int ms_wasapi_write_get_volume_gain(MSFilter *f, void *arg) {
MSWASAPIWriterType w = MSWASAPI_WRITER(f->data);
float *volume = (float *)arg;
*volume = w->getVolumeLevel();
return *volume >= 0.0f ? 0 : -1;
}
static MSFilterMethod ms_wasapi_write_methods[] = {
{ MS_FILTER_SET_SAMPLE_RATE, ms_wasapi_write_set_sample_rate },
{ MS_FILTER_GET_SAMPLE_RATE, ms_wasapi_write_get_sample_rate },
{ MS_FILTER_SET_NCHANNELS, ms_wasapi_write_set_nchannels },
{ MS_FILTER_GET_NCHANNELS, ms_wasapi_write_get_nchannels },
{ MS_AUDIO_PLAYBACK_SET_VOLUME_GAIN, ms_wasapi_write_set_volume_gain },
{ MS_AUDIO_PLAYBACK_GET_VOLUME_GAIN, ms_wasapi_write_get_volume_gain },
{ 0, NULL }
};
......
......@@ -69,6 +69,7 @@ typedef struct WasapiSndCard {
extern const IID IID_IAudioClient2;
extern const IID IID_IAudioCaptureClient;
extern const IID IID_IAudioRenderClient;
extern const IID IID_ISimpleAudioVolume;
#ifdef MS2_WINDOWS_DESKTOP
extern const CLSID CLSID_MMDeviceEnumerator;
......
......@@ -49,7 +49,7 @@ bool MSWASAPIReader::smInstantiated = false;
MSWASAPIReader::MSWASAPIReader()
: mAudioClient(NULL), mAudioCaptureClient(NULL), mBufferFrameCount(0), mIsInitialized(false), mIsActivated(false), mIsStarted(false)
: mAudioClient(NULL), mAudioCaptureClient(NULL), mVolumeControler(NULL), mBufferFrameCount(0), mIsInitialized(false), mIsActivated(false), mIsStarted(false)
{
#ifdef MS2_WINDOWS_UNIVERSAL
mActivationEvent = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS);
......@@ -197,6 +197,8 @@ int MSWASAPIReader::activate()
ms_message("MSWASAPI audio input interface buffer size: %i", mBufferFrameCount);
result = mAudioClient->GetService(IID_IAudioCaptureClient, (void **)&mAudioCaptureClient);
REPORT_ERROR("Could not get render service from the MSWASAPI audio input interface [%x]", result);
result = mAudioClient->GetService(IID_ISimpleAudioVolume, (void **)&mVolumeControler);
REPORT_ERROR("Could not get volume control service from the MSWASAPI audio input interface [%x]", result);
mIsActivated = true;
return 0;
......@@ -208,6 +210,7 @@ error:
int MSWASAPIReader::deactivate()
{
RELEASE_CLIENT(mAudioCaptureClient);
RELEASE_CLIENT(mVolumeControler);
mIsActivated = false;
return 0;
}
......@@ -277,6 +280,36 @@ error:
return -1;
}
float MSWASAPIReader::getVolumeLevel() {
HRESULT result;
float volume;
if (!mIsActivated) {
ms_error("MSWASAPIReader::getVolumeLevel(): the MSWASAPIReader instance is not started");
goto error;
}
result = mVolumeControler->GetMasterVolume(&volume);
REPORT_ERROR("MSWASAPIReader::getVolumeLevel(): could not get the master volume [%x]", result);
return volume;
error:
return -1.0f;
}
void MSWASAPIReader::setVolumeLevel(float volume) {
HRESULT result;
if (!mIsActivated) {
ms_error("MSWASAPIReader::setVolumeLevel(): the MSWASAPIReader instance is not started");
goto error;
}
result = mVolumeControler->SetMasterVolume(volume, NULL);
REPORT_ERROR("MSWASAPIReader::setVolumeLevel(): could not set the master volume [%x]", result);
error:
return;
}
void MSWASAPIReader::silence(MSFilter *f)
{
mblk_t *om;
......
......@@ -48,6 +48,8 @@ public:
int getRate() { return mRate; }
int getNChannels() { return mNChannels; }
float getVolumeLevel();
void setVolumeLevel(float volume);
#ifdef MS2_WINDOWS_UNIVERSAL
void setAsNotInstantiated() { smInstantiated = false; }
......@@ -71,6 +73,7 @@ private:
IAudioClient *mAudioClient;
#endif
IAudioCaptureClient *mAudioCaptureClient;
ISimpleAudioVolume *mVolumeControler;
UINT32 mBufferFrameCount;
bool mIsInitialized;
bool mIsActivated;
......
......@@ -48,7 +48,7 @@ bool MSWASAPIWriter::smInstantiated = false;
MSWASAPIWriter::MSWASAPIWriter()
: mAudioClient(NULL), mAudioRenderClient(NULL), mBufferFrameCount(0), mIsInitialized(false), mIsActivated(false), mIsStarted(false)
: mAudioClient(NULL), mAudioRenderClient(NULL), mVolumeControler(NULL), mBufferFrameCount(0), mIsInitialized(false), mIsActivated(false), mIsStarted(false)
{
#ifdef MS2_WINDOWS_UNIVERSAL
mActivationEvent = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS);
......@@ -190,6 +190,8 @@ int MSWASAPIWriter::activate()
ms_message("MSWASAPI audio output interface buffer size: %i", mBufferFrameCount);
result = mAudioClient->GetService(IID_IAudioRenderClient, (void **)&mAudioRenderClient);
REPORT_ERROR("Could not get render service from the MSWASAPI audio output interface [%x]", result);
result = mAudioClient->GetService(IID_ISimpleAudioVolume, (void **)&mVolumeControler);
REPORT_ERROR("Could not get volume control service from the MSWASAPI audio output interface [%x]", result);
mIsActivated = true;
return 0;
......@@ -281,6 +283,36 @@ error:
return -1;
}
float MSWASAPIWriter::getVolumeLevel() {
HRESULT result;
float volume;
if (!mIsActivated) {
ms_error("MSWASAPIWriter::getVolumeLevel(): the MSWASAPIWriter instance is not started");
goto error;
}
result = mVolumeControler->GetMasterVolume(&volume);
REPORT_ERROR("MSWASAPIWriter::getVolumeLevel(): could not get the master volume [%x]", result);
return volume;
error:
return -1.0f;
}
void MSWASAPIWriter::setVolumeLevel(float volume) {
HRESULT result;
if (!mIsActivated) {
ms_error("MSWASAPIWriter::setVolumeLevel(): the MSWASAPIWriter instance is not started");
goto error;
}
result = mVolumeControler->SetMasterVolume(volume, NULL);
REPORT_ERROR("MSWASAPIWriter::setVolumeLevel(): could not set the master volume [%x]", result);
error:
return;
}
void MSWASAPIWriter::drop(MSFilter *f) {
mblk_t *im;
......
......@@ -48,6 +48,8 @@ public:
int getRate() { return mRate; }
int getNChannels() { return mNChannels; }
float getVolumeLevel();
void setVolumeLevel(float volume);
#ifdef MS2_WINDOWS_UNIVERSAL
void setAsNotInstantiated() { smInstantiated = false; }
......@@ -73,6 +75,7 @@ private:
IAudioClient *mAudioClient;
#endif
IAudioRenderClient *mAudioRenderClient;
ISimpleAudioVolume *mVolumeControler;
UINT32 mBufferFrameCount;
bool mIsInitialized;
bool mIsActivated;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment