pcm_volume: return bool
Don't abort MPD when a sample format is not supported by pcm_volume().
This commit is contained in:
parent
0579b6ed27
commit
b7bfa24f22
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user