summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2012-11-25 12:22:57 +0100
committerGravatar waker <wakeroid@gmail.com>2012-11-25 12:22:57 +0100
commite1e8da8bfe85e42b4e0c893170acd7ecbe3af512 (patch)
treea153f644c8db59f2343d9e1a39b49f06792e2f26
parent4d190480e4dbb382673e5a2f698fe39c9feb9b80 (diff)
added new set_mute/is_mute API; added hotkey for this
-rw-r--r--deadbeef.h3
-rw-r--r--plugins.c4
-rw-r--r--plugins/hotkeys/actionhandlers.c7
-rw-r--r--plugins/hotkeys/actionhandlers.h3
-rw-r--r--plugins/hotkeys/hotkeys.c4
-rw-r--r--streamer.c11
-rw-r--r--volume.c13
-rw-r--r--volume.h6
8 files changed, 43 insertions, 8 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 10f8af38..cfe4885c 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -796,6 +796,9 @@ typedef struct {
// data size must be float[DDB_AUDIO_MEMORY_FRAMES]
void (*audio_get_waveform_data) (int type, float *data);
+ void (*audio_set_mute) (int mute);
+ int (*audio_is_mute) (void);
+
} DB_functions_t;
// NOTE: an item placement must be selected like this
diff --git a/plugins.c b/plugins.c
index 3bee6b27..a12b026c 100644
--- a/plugins.c
+++ b/plugins.c
@@ -340,8 +340,10 @@ static DB_functions_t deadbeef_api = {
.pl_get_meta_raw = (int (*) (DB_playItem_t *it, const char *key, char *val, int size))pl_get_meta_raw,
.plt_get_meta = (int (*) (ddb_playlist_t *handle, const char *key, char *val, int size))plt_get_meta,
.pl_meta_exists = (int (*) (DB_playItem_t *it, const char *key))pl_meta_exists,
- // FIXME ******* devel branch only *******
+ // ******* new 1.5 APIs ********
.audio_get_waveform_data = audio_get_waveform_data,
+ .audio_set_mute = audio_set_mute,
+ .audio_is_mute = audio_is_mute,
};
DB_functions_t *deadbeef = &deadbeef_api;
diff --git a/plugins/hotkeys/actionhandlers.c b/plugins/hotkeys/actionhandlers.c
index ab90a788..b28c9c39 100644
--- a/plugins/hotkeys/actionhandlers.c
+++ b/plugins/hotkeys/actionhandlers.c
@@ -306,3 +306,10 @@ action_remove_from_playqueue_handler (DB_plugin_action_t *act, int ctx) {
deadbeef->sendmessage (DB_EV_PLAYLIST_REFRESH, 0, 0, 0);
return 0;
}
+
+int
+action_toggle_mute_handler (DB_plugin_action_t *act, int ctx) {
+ int mute = 1-deadbeef->audio_is_mute ();
+ deadbeef->audio_set_mute (mute);
+ return 0;
+}
diff --git a/plugins/hotkeys/actionhandlers.h b/plugins/hotkeys/actionhandlers.h
index 7457f8eb..46a2e0cb 100644
--- a/plugins/hotkeys/actionhandlers.h
+++ b/plugins/hotkeys/actionhandlers.h
@@ -96,4 +96,7 @@ action_add_to_playqueue_handler (DB_plugin_action_t *act, int ctx);
int
action_remove_from_playqueue_handler (DB_plugin_action_t *act, int ctx);
+int
+action_toggle_mute_handler (DB_plugin_action_t *act, int ctx);
+
#endif
diff --git a/plugins/hotkeys/hotkeys.c b/plugins/hotkeys/hotkeys.c
index ca519976..b2c9f750 100644
--- a/plugins/hotkeys/hotkeys.c
+++ b/plugins/hotkeys/hotkeys.c
@@ -889,10 +889,10 @@ static DB_plugin_action_t action_add_to_playqueue = {
};
static DB_plugin_action_t action_toggle_mute = {
- .title = "Playback/[stub] Toggle Mute",
+ .title = "Playback/Toggle Mute",
.name = "toggle_mute",
.flags = DB_ACTION_COMMON,
- .callback = NULL,
+ .callback = action_toggle_mute_handler,
.next = &action_add_to_playqueue
};
diff --git a/streamer.c b/streamer.c
index df772917..c97014c4 100644
--- a/streamer.c
+++ b/streamer.c
@@ -2092,7 +2092,7 @@ streamer_read (char *bytes, int size) {
char *stream = bytes;
int bytesread = sz;
if (output->fmt.bps == 16) {
- int16_t ivolume = volume_get_amp () * 1000;
+ int16_t ivolume = volume_get_amp () * (1-audio_is_mute ()) * 1000;
for (int i = 0; i < bytesread/2; i++) {
int16_t sample = *((int16_t*)stream);
*((int16_t*)stream) = (int16_t)(((int32_t)sample) * ivolume / 1000);
@@ -2100,14 +2100,14 @@ streamer_read (char *bytes, int size) {
}
}
else if (output->fmt.bps == 8) {
- int16_t ivolume = volume_get_amp () * 255;
+ int16_t ivolume = volume_get_amp () * (1-audio_is_mute ()) * 255;
for (int i = 0; i < bytesread; i++) {
*stream = (int8_t)(((int32_t)(*stream)) * ivolume / 1000);
stream++;
}
}
else if (output->fmt.bps == 24) {
- int16_t ivolume = volume_get_amp () * 1000;
+ int16_t ivolume = volume_get_amp () * (1-audio_is_mute ()) * 1000;
for (int i = 0; i < bytesread/3; i++) {
int32_t sample = ((unsigned char)stream[0]) | ((unsigned char)stream[1]<<8) | (stream[2]<<16);
int32_t newsample = (int64_t)sample * ivolume / 1000;
@@ -2118,7 +2118,7 @@ streamer_read (char *bytes, int size) {
}
}
else if (output->fmt.bps == 32 && !output->fmt.is_float) {
- int16_t ivolume = volume_get_amp () * 1000;
+ int16_t ivolume = volume_get_amp () * (1-audio_is_mute ()) * 1000;
for (int i = 0; i < bytesread/4; i++) {
int32_t sample = *((int32_t*)stream);
int32_t newsample = (int64_t)sample * ivolume / 1000;
@@ -2127,7 +2127,7 @@ streamer_read (char *bytes, int size) {
}
}
else if (output->fmt.bps == 32 && output->fmt.is_float) {
- float fvolume = volume_get_amp ();
+ float fvolume = volume_get_amp () * (1-audio_is_mute ());
for (int i = 0; i < bytesread/4; i++) {
*((float*)stream) = (*((float*)stream)) * fvolume;
stream += 4;
@@ -2361,3 +2361,4 @@ streamer_set_streamer_playlist (playlist_t *plt) {
plt_ref (streamer_playlist);
}
}
+
diff --git a/volume.c b/volume.c
index c4db8545..f5c800b5 100644
--- a/volume.c
+++ b/volume.c
@@ -33,6 +33,7 @@
static float volume_db = 0; // in dB
static float volume_amp = 1; // amplitude [0..1]
+static int audio_mute = 0;
void
volume_set_db (float dB) {
@@ -45,6 +46,7 @@ volume_set_db (float dB) {
conf_set_float ("playback.volume", dB);
volume_db = dB;
volume_amp = dB > VOLUME_MIN ? db_to_amp (dB) : 0;
+ audio_mute = 0;
}
float
@@ -63,6 +65,7 @@ volume_set_amp (float amp) {
volume_amp = amp;
volume_db = amp > 0 ? amp_to_db (amp) : VOLUME_MIN;
conf_set_float ("playback.volume", volume_db);
+ audio_mute = 0;
}
float
@@ -87,3 +90,13 @@ float
volume_get_min_db (void) {
return VOLUME_MIN;
}
+
+void
+audio_set_mute (int mute) {
+ audio_mute = mute;
+}
+
+int
+audio_is_mute (void) {
+ return audio_mute;
+}
diff --git a/volume.h b/volume.h
index fe6b03c5..c8a72f29 100644
--- a/volume.h
+++ b/volume.h
@@ -48,4 +48,10 @@ amp_to_db (float amp);
float
volume_get_min_db (void);
+void
+audio_set_mute (int mute);
+
+int
+audio_is_mute (void);
+
#endif // __VOLUME_H