Skip to content

Commit

Permalink
aplay/mixer: pass audio_playback_opts to the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Nov 22, 2024
1 parent dfd5e68 commit 1d84764
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions src/audio/playback/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,31 +240,43 @@ class logarithmic_mix_algo : public generic_mix_algo<source_t, intermediate_t> {
};

struct state_audio_mixer final {
state_audio_mixer(const char *cfg) {
if (cfg) {
shared_ptr<char> tmp(strdup(cfg), free);
char *item, *save_ptr;
char *copy = tmp.get();

while ((item = strtok_r(copy, ":", &save_ptr))) {
if (strncmp(item, "codec=", strlen("codec=")) == 0) {
audio_codec = item + strlen("codec=");
} else if (strncmp(item, "algo=", strlen("algo=")) == 0) {
string algo = item + strlen("algo=");
if (algo == "linear") {
mixing_algorithm = decltype(mixing_algorithm)(new linear_mix_algo<sample_type_source, sample_type_mixed>());
} else if (algo == "logarithmic") {
mixing_algorithm = decltype(mixing_algorithm)(new logarithmic_mix_algo<sample_type_source, sample_type_mixed>());
} else {
LOG(LOG_LEVEL_ERROR) << "Unknown mixing algorithm: " << algo << "\n";
throw 1;
}
state_audio_mixer(const struct audio_playback_opts *opts) {
char copy[STR_LEN];
snprintf_ch(copy, "%s", opts->cfg);
char *tmp = copy;
char *item = nullptr;
char *save_ptr = nullptr;

while ((item = strtok_r(tmp, ":", &save_ptr)) != nullptr) {
if (strncmp(item, "codec=", strlen("codec=")) == 0) {
audio_codec = item + strlen("codec=");
} else if (strncmp(item, "algo=", strlen("algo=")) ==
0) {
string algo = item + strlen("algo=");
if (algo == "linear") {
mixing_algorithm =
decltype(mixing_algorithm)(
new linear_mix_algo<
sample_type_source,
sample_type_mixed>());
} else if (algo == "logarithmic") {
mixing_algorithm =
decltype(mixing_algorithm)(
new logarithmic_mix_algo<
sample_type_source,
sample_type_mixed>());
} else {
LOG(LOG_LEVEL_ERROR) << "Unknown option: " << item << "\n";
LOG(LOG_LEVEL_ERROR)
<< "Unknown mixing algorithm: "
<< algo << "\n";
throw 1;
}
copy = nullptr;
} else {
LOG(LOG_LEVEL_ERROR)
<< "Unknown option: " << item << "\n";
throw 1;
}
tmp = nullptr;
}

struct audio_codec_state *audio_coder =
Expand Down Expand Up @@ -422,7 +434,7 @@ audio_play_mixer_init(const struct audio_playback_opts *opts)
return INIT_NOERR;
}
try {
return new state_audio_mixer{opts->cfg};
return new state_audio_mixer(opts);
} catch (...) {
return nullptr;
}
Expand Down

0 comments on commit 1d84764

Please sign in to comment.