diff options
-rw-r--r-- | deadbeef.h | 3 | ||||
-rw-r--r-- | plugins.c | 4 | ||||
-rw-r--r-- | plugins/hotkeys/actionhandlers.c | 7 | ||||
-rw-r--r-- | plugins/hotkeys/actionhandlers.h | 3 | ||||
-rw-r--r-- | plugins/hotkeys/hotkeys.c | 4 | ||||
-rw-r--r-- | streamer.c | 11 | ||||
-rw-r--r-- | volume.c | 13 | ||||
-rw-r--r-- | volume.h | 6 |
8 files changed, 43 insertions, 8 deletions
@@ -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 @@ -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 }; @@ -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); } } + @@ -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; +} @@ -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 |