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

Add a function to fill a MSEqualizerGain by parsing a string

parent 1d33765a
......@@ -28,6 +28,8 @@ typedef struct _MSEqualizerGain{
float width; ///< frequency band width around mid frequency for which the gain is applied, in Hz. Use 0 for the lowest frequency resolution.
}MSEqualizerGain;
MS2_PUBLIC MSList *ms_parse_equalizer_string(const char *str);
#define MS_EQUALIZER_SET_GAIN MS_FILTER_METHOD(MS_EQUALIZER_ID,0,MSEqualizerGain)
#define MS_EQUALIZER_GET_GAIN MS_FILTER_METHOD(MS_EQUALIZER_ID,1,MSEqualizerGain)
#define MS_EQUALIZER_SET_ACTIVE MS_FILTER_METHOD(MS_EQUALIZER_ID,2,int)
......
......@@ -382,4 +382,19 @@ MSFilterDesc ms_equalizer_desc={
#endif
MSList *ms_parse_equalizer_string(const char *str) {
MSList *eq_list = NULL;
do {
int bytes;
MSEqualizerGain g;
if (sscanf(str, "%f:%f:%f %n", &g.frequency, &g.gain, &g.width, &bytes) == 3) {
MSEqualizerGain *gain = ms_new(MSEqualizerGain, 1);
*gain = g;
eq_list = ms_list_append(eq_list, gain);
str += bytes;
} else break;
} while (1);
return eq_list;
}
MS_FILTER_DESC_EXPORT(ms_equalizer_desc)
......@@ -1043,17 +1043,19 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
if (device && device->hacks) {
const char *gains = device->hacks->equalizer;
if (gains) {
MSList *gains_list;
stream->eq_loc = MSEqualizerMic;
ms_message("Found equalizer configuration in the devices table");
do {
int bytes;
MSEqualizerGain g;
if (sscanf(gains, "%f:%f:%f %n", &g.frequency, &g.gain, &g.width, &bytes) == 3) {
ms_message("Read equalizer gains: %f(~%f) --> %f", g.frequency, g.width, g.gain);
ms_filter_call_method(stream->equalizer, MS_EQUALIZER_SET_GAIN, &g);
gains += bytes;
} else break;
} while(1);
gains_list = ms_parse_equalizer_string(gains);
if (gains_list) {
MSList *it;
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->equalizer, MS_EQUALIZER_SET_GAIN, g);
}
ms_list_free_with_data(gains_list, ms_free);
}
}
}
}
......
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