diff options
-rw-r--r-- | src/pcm_volume.c | 15 | ||||
-rw-r--r-- | src/pcm_volume.h | 4 | ||||
-rw-r--r-- | src/player_thread.c | 13 | ||||
-rw-r--r-- | test/read_tags.c | 3 | ||||
-rw-r--r-- | test/run_decoder.c | 3 |
5 files changed, 25 insertions, 13 deletions
diff --git a/src/pcm_volume.c b/src/pcm_volume.c index 383caecca..49b0f9fb7 100644 --- a/src/pcm_volume.c +++ b/src/pcm_volume.c @@ -112,36 +112,35 @@ pcm_volume_change_24(int32_t *buffer, unsigned num_samples, int volume) } } -void +bool pcm_volume(void *buffer, int length, const struct audio_format *format, int volume) { if (volume == PCM_VOLUME_1) - return; + return true; if (volume <= 0) { memset(buffer, 0, length); - return; + return true; } switch (format->bits) { case 8: pcm_volume_change_8((int8_t *)buffer, length, volume); - break; + return true; case 16: pcm_volume_change_16((int16_t *)buffer, length / 2, volume); - break; + return true; case 24: pcm_volume_change_24((int32_t*)buffer, length / 4, volume); - break; + return true; default: - g_error("%u bits not supported by pcm_volume!\n", - format->bits); + return false; } } diff --git a/src/pcm_volume.h b/src/pcm_volume.h index 1b5e7fb0e..e21ea6f56 100644 --- a/src/pcm_volume.h +++ b/src/pcm_volume.h @@ -22,6 +22,7 @@ #include "pcm_prng.h" #include <stdint.h> +#include <stdbool.h> enum { /** this value means "100% volume" */ @@ -62,8 +63,9 @@ pcm_volume_dither(void) * @param length the length of the PCM buffer * @param format the audio format of the PCM buffer * @param volume the volume between 0 and #PCM_VOLUME_1 + * @return true on success, false if the audio format is not supported */ -void +bool pcm_volume(void *buffer, int length, const struct audio_format *format, int volume); diff --git a/src/player_thread.c b/src/player_thread.c index 24942fbfd..fb3e9bf68 100644 --- a/src/player_thread.c +++ b/src/player_thread.c @@ -238,6 +238,8 @@ static bool play_chunk(struct song *song, struct music_chunk *chunk, const struct audio_format *format, double sizeToTime) { + bool success; + pc.elapsed_time = chunk->times; pc.bit_rate = chunk->bit_rate; @@ -266,8 +268,15 @@ play_chunk(struct song *song, struct music_chunk *chunk, if (chunk->length == 0) return true; - pcm_volume(chunk->data, chunk->length, - format, pc.software_volume); + success = pcm_volume(chunk->data, chunk->length, + format, pc.software_volume); + if (!success) { + g_warning("pcm_volume() failed on %u:%u:%u", + format->sample_rate, format->bits, format->channels); + pc.errored_song = dc.current_song; + pc.error = PLAYER_ERROR_AUDIO; + return false; + } if (!audio_output_all_play(chunk->data, chunk->length)) { pc.errored_song = dc.current_song; diff --git a/test/read_tags.c b/test/read_tags.c index cdee3722f..1b223f074 100644 --- a/test/read_tags.c +++ b/test/read_tags.c @@ -32,11 +32,12 @@ /** * No-op dummy. */ -void +bool pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length, G_GNUC_UNUSED const struct audio_format *format, G_GNUC_UNUSED int volume) { + return true; } void diff --git a/test/run_decoder.c b/test/run_decoder.c index 8d11494c7..6bd331b02 100644 --- a/test/run_decoder.c +++ b/test/run_decoder.c @@ -30,11 +30,12 @@ /** * No-op dummy. */ -void +bool pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length, G_GNUC_UNUSED const struct audio_format *format, G_GNUC_UNUSED int volume) { + return true; } struct decoder { |