MCPcopy Create free account
hub / github.com/Sapd/HeadsetControl / parse_parametric_equalizer_band

Function parse_parametric_equalizer_band

src/utility.c:164–211  ·  view source on GitHub ↗

* Parses a equalizer band string into a struct parametric_equalizer_band. * * Expected band_str format: "float,float,float,string" * Expected fields: "frequency,gain,q-factor,filter-type" * * Returns HSC_INVALID_ARG if the string can't be parsed. */

Source from the content-addressed store, hash-verified

162 * Returns HSC_INVALID_ARG if the string can't be parsed.
163 */
164static int parse_parametric_equalizer_band(const char* band_str, struct parametric_equalizer_band* out_band)
165{
166 const char* delim = " ,";
167
168 // Make a modifiable copy of input, because strtok modifies the string.
169 char* tmp = strdup(band_str);
170 if (!tmp) {
171 return -1;
172 }
173
174 // parse freq, gain, q_factor, type
175 char* token = strtok(tmp, delim);
176 if (!token) {
177 free(tmp);
178 return HSC_INVALID_ARG;
179 }
180 out_band->frequency = strtof(token, NULL);
181
182 token = strtok(NULL, delim);
183 if (!token) {
184 free(tmp);
185 return HSC_INVALID_ARG;
186 }
187 out_band->gain = strtof(token, NULL);
188
189 token = strtok(NULL, delim);
190 if (!token) {
191 free(tmp);
192 return HSC_INVALID_ARG;
193 }
194 out_band->q_factor = strtof(token, NULL);
195
196 token = strtok(NULL, delim);
197 if (!token) {
198 free(tmp);
199 return HSC_INVALID_ARG;
200 }
201
202 out_band->type = parse_eq_filter_type(token);
203 if ((int)out_band->type == HSC_INVALID_ARG) {
204 printf("Couldn't parse filter type: %s\n", token);
205 free(tmp);
206 return HSC_INVALID_ARG;
207 }
208
209 free(tmp);
210 return 0;
211}
212
213/**
214 * Parses the full parametric equalizer string that can contain multiple band

Callers 1

Calls 1

parse_eq_filter_typeFunction · 0.85

Tested by

no test coverage detected