Commit 0847ca4e authored by Max Kellermann's avatar Max Kellermann

pcm_{mix,volume}: pass only sample_format to pcm_mix()

The other audio_format attributes are not used.
parent 572d8d0c
...@@ -195,7 +195,7 @@ replay_gain_filter_filter(struct filter *_filter, ...@@ -195,7 +195,7 @@ replay_gain_filter_filter(struct filter *_filter,
memcpy(dest, src, src_size); memcpy(dest, src, src_size);
success = pcm_volume(dest, src_size, &filter->audio_format, success = pcm_volume(dest, src_size, filter->audio_format.format,
filter->volume); filter->volume);
if (!success) { if (!success) {
g_set_error(error_r, replay_gain_quark(), 0, g_set_error(error_r, replay_gain_quark(), 0,
......
...@@ -116,7 +116,7 @@ volume_filter_filter(struct filter *_filter, const void *src, size_t src_size, ...@@ -116,7 +116,7 @@ volume_filter_filter(struct filter *_filter, const void *src, size_t src_size,
memcpy(dest, src, src_size); memcpy(dest, src, src_size);
success = pcm_volume(dest, src_size, &filter->audio_format, success = pcm_volume(dest, src_size, filter->audio_format.format,
filter->volume); filter->volume);
if (!success) { if (!success) {
g_set_error(error_r, volume_quark(), 0, g_set_error(error_r, volume_quark(), 0,
......
...@@ -401,7 +401,7 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk, ...@@ -401,7 +401,7 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk,
char *dest = pcm_buffer_get(&ao->cross_fade_buffer, char *dest = pcm_buffer_get(&ao->cross_fade_buffer,
other_length); other_length);
memcpy(dest, other_data, other_length); memcpy(dest, other_data, other_length);
pcm_mix(dest, data, length, &ao->in_audio_format, pcm_mix(dest, data, length, ao->in_audio_format.format,
1.0 - chunk->mix_ratio); 1.0 - chunk->mix_ratio);
data = dest; data = dest;
......
...@@ -102,9 +102,9 @@ pcm_add_vol_32(int32_t *buffer1, const int32_t *buffer2, ...@@ -102,9 +102,9 @@ pcm_add_vol_32(int32_t *buffer1, const int32_t *buffer2,
static void static void
pcm_add_vol(void *buffer1, const void *buffer2, size_t size, pcm_add_vol(void *buffer1, const void *buffer2, size_t size,
int vol1, int vol2, int vol1, int vol2,
const struct audio_format *format) enum sample_format format)
{ {
switch (format->format) { switch (format) {
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
pcm_add_vol_8((int8_t *)buffer1, (const int8_t *)buffer2, pcm_add_vol_8((int8_t *)buffer1, (const int8_t *)buffer2,
size, vol1, vol2); size, vol1, vol2);
...@@ -127,7 +127,7 @@ pcm_add_vol(void *buffer1, const void *buffer2, size_t size, ...@@ -127,7 +127,7 @@ pcm_add_vol(void *buffer1, const void *buffer2, size_t size,
default: default:
MPD_ERROR("format %s not supported by pcm_add_vol", MPD_ERROR("format %s not supported by pcm_add_vol",
sample_format_to_string(format->format)); sample_format_to_string(format));
} }
} }
...@@ -189,9 +189,9 @@ pcm_add_32(int32_t *buffer1, const int32_t *buffer2, unsigned num_samples) ...@@ -189,9 +189,9 @@ pcm_add_32(int32_t *buffer1, const int32_t *buffer2, unsigned num_samples)
static void static void
pcm_add(void *buffer1, const void *buffer2, size_t size, pcm_add(void *buffer1, const void *buffer2, size_t size,
const struct audio_format *format) enum sample_format format)
{ {
switch (format->format) { switch (format) {
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
pcm_add_8((int8_t *)buffer1, (const int8_t *)buffer2, size); pcm_add_8((int8_t *)buffer1, (const int8_t *)buffer2, size);
break; break;
...@@ -210,13 +210,13 @@ pcm_add(void *buffer1, const void *buffer2, size_t size, ...@@ -210,13 +210,13 @@ pcm_add(void *buffer1, const void *buffer2, size_t size,
default: default:
MPD_ERROR("format %s not supported by pcm_add", MPD_ERROR("format %s not supported by pcm_add",
sample_format_to_string(format->format)); sample_format_to_string(format));
} }
} }
void void
pcm_mix(void *buffer1, const void *buffer2, size_t size, pcm_mix(void *buffer1, const void *buffer2, size_t size,
const struct audio_format *format, float portion1) enum sample_format format, float portion1)
{ {
int vol1; int vol1;
float s; float s;
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
#ifndef PCM_MIX_H #ifndef PCM_MIX_H
#define PCM_MIX_H #define PCM_MIX_H
#include <stddef.h> #include "audio_format.h"
struct audio_format; #include <stddef.h>
/* /*
* Linearly mixes two PCM buffers. Both must have the same length and * Linearly mixes two PCM buffers. Both must have the same length and
...@@ -33,13 +33,13 @@ struct audio_format; ...@@ -33,13 +33,13 @@ struct audio_format;
* @param buffer1 the first PCM buffer, and the destination buffer * @param buffer1 the first PCM buffer, and the destination buffer
* @param buffer2 the second PCM buffer * @param buffer2 the second PCM buffer
* @param size the size of both buffers in bytes * @param size the size of both buffers in bytes
* @param format the audio format of both buffers * @param format the sample format of both buffers
* @param portion1 a number between 0.0 and 1.0 specifying the portion * @param portion1 a number between 0.0 and 1.0 specifying the portion
* of the first buffer in the mix; portion2 = (1.0 - portion1). The value * of the first buffer in the mix; portion2 = (1.0 - portion1). The value
* NaN is used by the MixRamp code to specify that simple addition is required. * NaN is used by the MixRamp code to specify that simple addition is required.
*/ */
void void
pcm_mix(void *buffer1, const void *buffer2, size_t size, pcm_mix(void *buffer1, const void *buffer2, size_t size,
const struct audio_format *format, float portion1); enum sample_format format, float portion1);
#endif #endif
...@@ -139,7 +139,7 @@ pcm_volume_change_32(int32_t *buffer, unsigned num_samples, int volume) ...@@ -139,7 +139,7 @@ pcm_volume_change_32(int32_t *buffer, unsigned num_samples, int volume)
bool bool
pcm_volume(void *buffer, int length, pcm_volume(void *buffer, int length,
const struct audio_format *format, enum sample_format format,
int volume) int volume)
{ {
if (volume == PCM_VOLUME_1) if (volume == PCM_VOLUME_1)
...@@ -150,7 +150,7 @@ pcm_volume(void *buffer, int length, ...@@ -150,7 +150,7 @@ pcm_volume(void *buffer, int length,
return true; return true;
} }
switch (format->format) { switch (format) {
case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_S8:
pcm_volume_change_8((int8_t *)buffer, length, volume); pcm_volume_change_8((int8_t *)buffer, length, volume);
return true; return true;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define PCM_VOLUME_H #define PCM_VOLUME_H
#include "pcm_prng.h" #include "pcm_prng.h"
#include "audio_format.h"
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -62,13 +63,13 @@ pcm_volume_dither(void) ...@@ -62,13 +63,13 @@ pcm_volume_dither(void)
* *
* @param buffer the PCM buffer * @param buffer the PCM buffer
* @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 sample 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 * @return true on success, false if the audio format is not supported
*/ */
bool bool
pcm_volume(void *buffer, int length, pcm_volume(void *buffer, int length,
const struct audio_format *format, enum sample_format format,
int volume); int volume);
#endif #endif
...@@ -116,7 +116,7 @@ filter_plugin_by_name(G_GNUC_UNUSED const char *name) ...@@ -116,7 +116,7 @@ filter_plugin_by_name(G_GNUC_UNUSED const char *name)
bool 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 enum sample_format format,
G_GNUC_UNUSED int volume) G_GNUC_UNUSED int volume)
{ {
assert(false); assert(false);
......
...@@ -53,7 +53,7 @@ idle_add(G_GNUC_UNUSED unsigned flags) ...@@ -53,7 +53,7 @@ idle_add(G_GNUC_UNUSED unsigned flags)
*/ */
bool 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 enum sample_format format,
G_GNUC_UNUSED int volume) G_GNUC_UNUSED int volume)
{ {
return true; return true;
......
...@@ -57,7 +57,7 @@ idle_add(G_GNUC_UNUSED unsigned flags) ...@@ -57,7 +57,7 @@ idle_add(G_GNUC_UNUSED unsigned flags)
*/ */
bool 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 enum sample_format format,
G_GNUC_UNUSED int volume) G_GNUC_UNUSED int volume)
{ {
return true; return true;
......
...@@ -59,7 +59,7 @@ int main(int argc, char **argv) ...@@ -59,7 +59,7 @@ int main(int argc, char **argv)
audio_format_init(&audio_format, 48000, SAMPLE_FORMAT_S16, 2); audio_format_init(&audio_format, 48000, SAMPLE_FORMAT_S16, 2);
while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
if (!pcm_volume(buffer, nbytes, &audio_format, if (!pcm_volume(buffer, nbytes, audio_format.format,
PCM_VOLUME_1 / 2)) { PCM_VOLUME_1 / 2)) {
g_printerr("pcm_volume() has failed\n"); g_printerr("pcm_volume() has failed\n");
return 2; return 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment