pcm_volume: return bool

Don't abort MPD when a sample format is not supported by pcm_volume().
This commit is contained in:
Max Kellermann 2009-03-02 09:42:16 +01:00
parent 0579b6ed27
commit b7bfa24f22
5 changed files with 25 additions and 13 deletions

View File

@ -112,36 +112,35 @@ pcm_volume_change_24(int32_t *buffer, unsigned num_samples, int volume)
} }
} }
void bool
pcm_volume(void *buffer, int length, pcm_volume(void *buffer, int length,
const struct audio_format *format, const struct audio_format *format,
int volume) int volume)
{ {
if (volume == PCM_VOLUME_1) if (volume == PCM_VOLUME_1)
return; return true;
if (volume <= 0) { if (volume <= 0) {
memset(buffer, 0, length); memset(buffer, 0, length);
return; return true;
} }
switch (format->bits) { switch (format->bits) {
case 8: case 8:
pcm_volume_change_8((int8_t *)buffer, length, volume); pcm_volume_change_8((int8_t *)buffer, length, volume);
break; return true;
case 16: case 16:
pcm_volume_change_16((int16_t *)buffer, length / 2, pcm_volume_change_16((int16_t *)buffer, length / 2,
volume); volume);
break; return true;
case 24: case 24:
pcm_volume_change_24((int32_t*)buffer, length / 4, pcm_volume_change_24((int32_t*)buffer, length / 4,
volume); volume);
break; return true;
default: default:
g_error("%u bits not supported by pcm_volume!\n", return false;
format->bits);
} }
} }

View File

@ -22,6 +22,7 @@
#include "pcm_prng.h" #include "pcm_prng.h"
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
enum { enum {
/** this value means "100% volume" */ /** this value means "100% volume" */
@ -62,8 +63,9 @@ pcm_volume_dither(void)
* @param length the length of the PCM buffer * @param length the length of the PCM buffer
* @param format the audio format of the PCM buffer * @param format the audio format of the PCM buffer
* @param volume the volume between 0 and #PCM_VOLUME_1 * @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, pcm_volume(void *buffer, int length,
const struct audio_format *format, const struct audio_format *format,
int volume); int volume);

View File

@ -238,6 +238,8 @@ static bool
play_chunk(struct song *song, struct music_chunk *chunk, play_chunk(struct song *song, struct music_chunk *chunk,
const struct audio_format *format, double sizeToTime) const struct audio_format *format, double sizeToTime)
{ {
bool success;
pc.elapsed_time = chunk->times; pc.elapsed_time = chunk->times;
pc.bit_rate = chunk->bit_rate; pc.bit_rate = chunk->bit_rate;
@ -266,8 +268,15 @@ play_chunk(struct song *song, struct music_chunk *chunk,
if (chunk->length == 0) if (chunk->length == 0)
return true; return true;
pcm_volume(chunk->data, chunk->length, success = pcm_volume(chunk->data, chunk->length,
format, pc.software_volume); 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)) { if (!audio_output_all_play(chunk->data, chunk->length)) {
pc.errored_song = dc.current_song; pc.errored_song = dc.current_song;

View File

@ -32,11 +32,12 @@
/** /**
* No-op dummy. * No-op dummy.
*/ */
void bool
pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length, pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length,
G_GNUC_UNUSED const struct audio_format *format, G_GNUC_UNUSED const struct audio_format *format,
G_GNUC_UNUSED int volume) G_GNUC_UNUSED int volume)
{ {
return true;
} }
void void

View File

@ -30,11 +30,12 @@
/** /**
* No-op dummy. * No-op dummy.
*/ */
void bool
pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length, pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length,
G_GNUC_UNUSED const struct audio_format *format, G_GNUC_UNUSED const struct audio_format *format,
G_GNUC_UNUSED int volume) G_GNUC_UNUSED int volume)
{ {
return true;
} }
struct decoder { struct decoder {