Commit a82cf3f9 authored by aymeric's avatar aymeric
Browse files

volume level and fix a buffer size bug

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@710 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent a5537a84
No related merge requests found
Showing with 55 additions and 4 deletions
...@@ -67,6 +67,11 @@ MSFilter *ms_aq_write_new(MSSndCard * card); ...@@ -67,6 +67,11 @@ MSFilter *ms_aq_write_new(MSSndCard * card);
#define kNumberAudioOutDataBuffers 4 #define kNumberAudioOutDataBuffers 4
#define kNumberAudioInDataBuffers 4 #define kNumberAudioInDataBuffers 4
float gain_volume_in=1.0;
float gain_volume_out=1.0;
bool gain_changed_in = true;
bool gain_changed_out = true;
typedef struct AQData { typedef struct AQData {
CFStringRef uidname; CFStringRef uidname;
AudioStreamBasicDescription devicereadFormat; AudioStreamBasicDescription devicereadFormat;
...@@ -111,11 +116,35 @@ typedef struct AqSndDsCard { ...@@ -111,11 +116,35 @@ typedef struct AqSndDsCard {
static void aqcard_set_level(MSSndCard * card, MSSndCardMixerElem e, static void aqcard_set_level(MSSndCard * card, MSSndCardMixerElem e,
int percent) int percent)
{ {
switch(e){
case MS_SND_CARD_PLAYBACK:
case MS_SND_CARD_MASTER:
gain_volume_out =((float)percent)/100.0f;
gain_changed_out = true;
return;
case MS_SND_CARD_CAPTURE:
gain_volume_in =((float)percent)/100.0f;
gain_changed_in = true;
return;
default:
ms_warning("aqcard_set_level: unsupported command.");
}
} }
static int aqcard_get_level(MSSndCard * card, MSSndCardMixerElem e) static int aqcard_get_level(MSSndCard * card, MSSndCardMixerElem e)
{ {
return 0; switch(e){
case MS_SND_CARD_PLAYBACK:
case MS_SND_CARD_MASTER:
{
}
return (int)(gain_volume_out*100.0f);
case MS_SND_CARD_CAPTURE:
return (int)(gain_volume_in*100.0f);
default:
ms_warning("aqcard_get_level: unsupported command.");
}
return -1;
} }
static void aqcard_set_source(MSSndCard * card, MSSndCardCapture source) static void aqcard_set_source(MSSndCard * card, MSSndCardCapture source)
...@@ -397,8 +426,17 @@ static void readCallback(void *aqData, ...@@ -397,8 +426,17 @@ static void readCallback(void *aqData,
d->devicereadFormat.mChannelsPerFrame); d->devicereadFormat.mChannelsPerFrame);
freeb(rm); freeb(rm);
} else { } else {
rm->b_wptr += len;
putq(&d->rq, rm); rm->b_wptr += len;
if (gain_volume_in != 1.0f)
{
int16_t *ptr=(int16_t *)rm->b_rptr;
for (;ptr<(int16_t *)rm->b_wptr;ptr++)
{
*ptr=(int16_t)(((float)(*ptr))*gain_volume_in);
}
}
putq(&d->rq, rm);
} }
err = AudioQueueEnqueueBuffer(d->readQueue, inBuffer, 0, NULL); err = AudioQueueEnqueueBuffer(d->readQueue, inBuffer, 0, NULL);
...@@ -419,7 +457,7 @@ static void writeCallback(void *aqData, ...@@ -419,7 +457,7 @@ static void writeCallback(void *aqData,
OSStatus err; OSStatus err;
int len = int len =
(d->writeBufferByteSize * d->writeAudioFormat.mSampleRate / 2) / (d->writeBufferByteSize * d->writeAudioFormat.mSampleRate / 1) /
d->devicewriteFormat.mSampleRate / d->devicewriteFormat.mSampleRate /
d->devicewriteFormat.mChannelsPerFrame; d->devicewriteFormat.mChannelsPerFrame;
...@@ -449,6 +487,15 @@ static void writeCallback(void *aqData, ...@@ -449,6 +487,15 @@ static void writeCallback(void *aqData,
memset(inBuffer->mAudioData, 0, d->writeBufferByteSize); memset(inBuffer->mAudioData, 0, d->writeBufferByteSize);
} }
inBuffer->mAudioDataByteSize = d->writeBufferByteSize; inBuffer->mAudioDataByteSize = d->writeBufferByteSize;
if (gain_changed_out == true)
{
AudioQueueSetParameter (d->writeQueue,
kAudioQueueParam_Volume,
gain_volume_out);
gain_changed_out = false;
}
err = AudioQueueEnqueueBuffer(d->writeQueue, inBuffer, 0, NULL); err = AudioQueueEnqueueBuffer(d->writeQueue, inBuffer, 0, NULL);
if (err != noErr) { if (err != noErr) {
ms_error("AudioQueueEnqueueBuffer %d", err); ms_error("AudioQueueEnqueueBuffer %d", err);
...@@ -645,6 +692,10 @@ static void aq_start_w(MSFilter * f) ...@@ -645,6 +692,10 @@ static void aq_start_w(MSFilter * f)
ms_error("AudioQueueNewOutput = %d", aqresult); ms_error("AudioQueueNewOutput = %d", aqresult);
} }
AudioQueueSetParameter (d->writeQueue,
kAudioQueueParam_Volume,
gain_volume_out);
char uidname[256]; char uidname[256];
CFStringGetCString(d->uidname, uidname, 256, CFStringGetCString(d->uidname, uidname, 256,
CFStringGetSystemEncoding()); CFStringGetSystemEncoding());
......
Supports Markdown
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