summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-02-28 13:13:35 -0500
committerXANTRONIX Development2022-02-28 13:13:49 -0500
commit2bf8a288c817715f84a16cabc13c717c3943e3f4 (patch)
tree912d5b8f0bd0acd215d74837e86b61e26bd77720
parent4152e6845e71344142faf0911382d5a2b05ae1e4 (diff)
downloadxas-2bf8a288c817715f84a16cabc13c717c3943e3f4.tar.gz
xas-2bf8a288c817715f84a16cabc13c717c3943e3f4.tar.bz2
xas-2bf8a288c817715f84a16cabc13c717c3943e3f4.zip
Allow setting bank player gain separately
-rw-r--r--examples/say.c2
-rw-r--r--include/xas/bank.h6
-rw-r--r--src/bank.c29
3 files changed, 27 insertions, 10 deletions
diff --git a/examples/say.c b/examples/say.c
index c89a245..4edd864 100644
--- a/examples/say.c
+++ b/examples/say.c
@@ -154,7 +154,7 @@ int main(int argc, char **argv) {
goto error_bank_record;
}
- xas_bank_player_select(player, 0, 1.0);
+ xas_bank_player_set_entry(player, 0);
for (i=0; i<duration_frames; i++) {
void *buf;
diff --git a/include/xas/bank.h b/include/xas/bank.h
index cd1511e..982302f 100644
--- a/include/xas/bank.h
+++ b/include/xas/bank.h
@@ -53,9 +53,9 @@ xas_bank_player *xas_bank_player_new(xas_bank *bank);
void xas_bank_player_destroy(xas_bank_player *player);
-int xas_bank_player_select(xas_bank_player *player,
- size_t entry,
- float gain);
+void xas_bank_player_set_gain(xas_bank_player *player, float gain);
+
+int xas_bank_player_set_entry(xas_bank_player *player, size_t entry);
int xas_bank_player_start(xas_bank_player *player);
diff --git a/src/bank.c b/src/bank.c
index 1d1dc3a..24e4466 100644
--- a/src/bank.c
+++ b/src/bank.c
@@ -118,6 +118,12 @@ error_riff_open_file:
return -1;
}
+static int set_gain(xas_bank_player *player, float gain) {
+ xas_bank_player_set_gain(player, gain);
+
+ return 0;
+}
+
xas_bank_player *xas_bank_player_new(xas_bank *bank) {
xas_bank_player *player;
@@ -125,8 +131,9 @@ xas_bank_player *xas_bank_player_new(xas_bank *bank) {
goto error_malloc_player;
}
- player->obj.start = (xas_object_start_callback)xas_bank_player_start;
- player->obj.stop = (xas_object_stop_callback)xas_bank_player_stop;
+ player->obj.start = (xas_object_start_callback)xas_bank_player_start;
+ player->obj.stop = (xas_object_stop_callback)xas_bank_player_stop;
+ player->obj.set_gain = (xas_object_set_gain_callback)set_gain;
player->bank = bank;
player->status = XAS_BANK_PLAYER_STOPPED;
@@ -144,13 +151,23 @@ void xas_bank_player_destroy(xas_bank_player *player) {
free(player);
}
-int xas_bank_player_select(xas_bank_player *player,
- size_t entry,
- float gain) {
+int xas_bank_player_set_entry(xas_bank_player *player, size_t entry) {
+ if (entry > player->bank->entry_count) {
+ errno = EINVAL;
+
+ goto error_invalid_entry;
+ }
+
player->entry = entry;
- player->gain = gain;
return 0;
+
+error_invalid_entry:
+ return -1;
+}
+
+void xas_bank_player_set_gain(xas_bank_player *player, float gain) {
+ player->gain = gain;
}
int xas_bank_player_start(xas_bank_player *player) {