Commit e41cfff7 authored by François Grisez's avatar François Grisez

Add two fields to SoundDeviceAudioHacks structure to set general and equalizer gains of the speaker

parent 2a54c9f8
......@@ -34,8 +34,10 @@
#define DEVICE_HAS_CRAPPY_OPENGL (1<<7) /*set when the opengl is crappy and our opengl surfaceview will crash */
struct SoundDeviceAudioHacks {
const char *equalizer;
const char *mic_equalizer;
float mic_gain;
const char *spk_equalizer;
float spk_gain;
};
typedef struct SoundDeviceAudioHacks SoundDeviceAudioHacks;
......
......@@ -613,7 +613,7 @@ static MS2_INLINE void audio_stream_enable_adaptive_jittcomp(AudioStream *stream
* use audio_stream_set_sound_card_input_gain() instead.
*
* @param stream The stream.
* @param gain Gain to apply in dB.
* @param gain_db Gain to apply in dB.
*/
MS2_PUBLIC void audio_stream_set_mic_gain_db(AudioStream *stream, float gain_db);
......@@ -629,9 +629,16 @@ MS2_PUBLIC void audio_stream_set_mic_gain(AudioStream *stream, float gain);
/**
* enable/disable rtp stream
* */
*/
MS2_PUBLIC void audio_stream_mute_rtp(AudioStream *stream, bool_t val);
/**
* Apply a gain on received RTP packets.
* @param stream An AudioStream.
* @param gain_db Gain to apply in dB.
*/
MS2_PUBLIC void audio_stream_set_spk_gain_db(AudioStream *stream, float gain_db);
/**
* Set microphone volume gain.
* If the sound backend supports it, the set volume gain will be synchronized
......
......@@ -34,7 +34,7 @@
* 1st column: list of triplet frequency, gain, width
* 2nd column: mic gain in db
*/
static SoundDeviceAudioHacks SonySGP511Hacks = { "50:0.01:100 600:0.2:100 1350:0.2:100 2000:0.2:100", -4 };
static SoundDeviceAudioHacks SonySGP511Hacks = { "50:0.01:100 600:0.2:100 1350:0.2:100 2000:0.2:100", -4, NULL, 0 };
/*
* 1st column: value of ro.product.manufacturer
......@@ -410,4 +410,4 @@ SoundDeviceDescription* ms_devices_info_get_sound_device_description(MSDevicesIn
ms_message("Sound device information for [%s/%s/%s] is: builtin=[%s], delay=[%i] ms",
manufacturer, model, platform, (d->flags & DEVICE_HAS_BUILTIN_AEC) ? "yes" : "no", d->delay);
return d;
}
\ No newline at end of file
}
......@@ -1047,20 +1047,36 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
#ifdef ANDROID
/*configure equalizer if needed*/
audio_stream_set_mic_gain_db(stream, 0);
if (stream->mic_equalizer) {
SoundDeviceDescription *device = sound_device_description_get();
if (device && device->hacks) {
const char *gains = device->hacks->equalizer;
if (gains) {
MSList *gains_list = ms_parse_equalizer_string(gains);
audio_stream_set_spk_gain_db(stream, 0);
SoundDeviceDescription *device = sound_device_description_get();
if (device && device->hacks) {
const char *gains;
gains = device->hacks->mic_equalizer;
if (gains) {
MSList *gains_list = ms_parse_equalizer_string(gains);
if (gains_list) {
MSList *it;
ms_message("Found equalizer configuration for the microphone in the devices table");
for (it = gains_list; it; it++) {
MSEqualizerGain *g = (MSEqualizerGain *)it->data;
ms_message("Read equalizer gains: %f(~%f) --> %f", g->frequency, g->width, g->gain);
ms_filter_call_method(stream->mic_equalizer, MS_EQUALIZER_SET_GAIN, g);
}
ms_list_free_with_data(gains_list, ms_free);
}
}
gains = device->hacks->spk_equalizer;
if (gains) {
MSList *gains_list = ms_parse_equalizer_string(gains);
if (gains_list) {
MSList *it;
ms_message("Found equalizer configuration in the devices table");
for (it=gains_list; it; it++) {
ms_message("Found equalizer configuration for the speakers in the devices table");
for (it = gains_list; it; it++) {
MSEqualizerGain *g = (MSEqualizerGain *)it->data;
ms_message("Read equalizer gains: %f(~%f) --> %f", g->frequency, g->width, g->gain);
ms_filter_call_method(stream->mic_equalizer, MS_EQUALIZER_SET_GAIN, g);
}
if(gains_list) ms_list_free_with_data(gains_list, ms_free);
ms_list_free_with_data(gains_list, ms_free);
}
}
}
......@@ -1746,7 +1762,7 @@ static void audio_stream_set_rtp_output_gain_db(AudioStream *stream, float gain_
if (stream->volsend){
ms_filter_call_method(stream->volsend, MS_VOLUME_SET_DB_GAIN, &gain);
} else ms_warning("Could not apply gain: gain control wasn't activated. "
} else ms_warning("Could not apply gain on sent RTP packets: gain control wasn't activated. "
"Use audio_stream_enable_gain_control() before starting the stream.");
}
......@@ -1760,6 +1776,22 @@ void audio_stream_mute_rtp(AudioStream *stream, bool_t val)
}
}
void audio_stream_set_spk_gain_db(AudioStream *stream, float gain_db) {
float gain = gain_db;
#ifdef ANDROID
SoundDeviceDescription *device = sound_device_description_get();
if (device && device->hacks) {
gain += device->hacks->spk_gain;
ms_message("Applying %f dB to speaker gain based on parameter and audio hack value in device table", gain);
}
#endif
if (stream->volrecv){
ms_filter_call_method(stream->volsend, MS_VOLUME_SET_DB_GAIN, &gain);
} else ms_warning("Could not apply gain on received RTP packet: gain control wasn't activated. "
"Use audio_stream_enable_gain_control() before starting the stream.");
}
float audio_stream_get_quality_rating(AudioStream *stream){
return media_stream_get_quality_rating(&stream->ms);
}
......
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