diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/audio_format.h | 9 | ||||
-rw-r--r-- | src/audio_parser.c | 10 | ||||
-rw-r--r-- | src/decoder/_flac_common.c | 5 | ||||
-rw-r--r-- | src/decoder/audiofile_plugin.c | 8 | ||||
-rw-r--r-- | src/decoder/faad_plugin.c | 6 | ||||
-rw-r--r-- | src/decoder/ffmpeg_plugin.c | 9 | ||||
-rw-r--r-- | src/decoder/mad_plugin.c | 10 | ||||
-rw-r--r-- | src/decoder/mikmod_plugin.c | 4 | ||||
-rw-r--r-- | src/decoder/modplug_plugin.c | 4 | ||||
-rw-r--r-- | src/decoder/mp4ff_plugin.c | 6 | ||||
-rw-r--r-- | src/decoder/mpcdec_plugin.c | 4 | ||||
-rw-r--r-- | src/decoder/sidplay_plugin.cxx | 4 | ||||
-rw-r--r-- | src/decoder/sndfile_decoder_plugin.c | 4 | ||||
-rw-r--r-- | src/decoder/vorbis_plugin.c | 3 | ||||
-rw-r--r-- | src/decoder/wavpack_plugin.c | 6 |
15 files changed, 39 insertions, 53 deletions
diff --git a/src/audio_format.h b/src/audio_format.h index 64087d070..e325c1b38 100644 --- a/src/audio_format.h +++ b/src/audio_format.h @@ -36,6 +36,15 @@ static inline void audio_format_clear(struct audio_format *af) af->channels = 0; } +static inline void audio_format_init(struct audio_format *af, + uint32_t sample_rate, + uint8_t bits, uint8_t channels) +{ + af->sample_rate = sample_rate; + af->bits = bits; + af->channels = channels; +} + static inline bool audio_format_defined(const struct audio_format *af) { return af->sample_rate != 0; diff --git a/src/audio_parser.c b/src/audio_parser.c index 906b0f819..d29f5f449 100644 --- a/src/audio_parser.c +++ b/src/audio_parser.c @@ -41,6 +41,8 @@ audio_format_parse(struct audio_format *dest, const char *src, GError **error) { char *endptr; unsigned long value; + uint32_t rate; + uint8_t bits, channels; audio_format_clear(dest); @@ -61,7 +63,7 @@ audio_format_parse(struct audio_format *dest, const char *src, GError **error) return false; } - dest->sample_rate = value; + rate = value; /* parse sample format */ @@ -81,7 +83,7 @@ audio_format_parse(struct audio_format *dest, const char *src, GError **error) return false; } - dest->bits = value; + bits = value; /* parse channel count */ @@ -93,7 +95,9 @@ audio_format_parse(struct audio_format *dest, const char *src, GError **error) return false; } - dest->channels = value; + channels = value; + + audio_format_init(dest, rate, bits, channels); return true; } diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c index 713dfe9b2..7b3453854 100644 --- a/src/decoder/_flac_common.c +++ b/src/decoder/_flac_common.c @@ -195,9 +195,8 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block, switch (block->type) { case FLAC__METADATA_TYPE_STREAMINFO: - data->audio_format.bits = (int8_t)si->bits_per_sample; - data->audio_format.sample_rate = si->sample_rate; - data->audio_format.channels = (int8_t)si->channels; + audio_format_init(&data->audio_format, si->sample_rate, + si->bits_per_sample, si->channels); data->total_time = ((float)si->total_samples) / (si->sample_rate); break; case FLAC__METADATA_TYPE_VORBIS_COMMENT: diff --git a/src/decoder/audiofile_plugin.c b/src/decoder/audiofile_plugin.c index f66d90dc1..b4959f6c2 100644 --- a/src/decoder/audiofile_plugin.c +++ b/src/decoder/audiofile_plugin.c @@ -136,11 +136,9 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is) afSetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, bits); afGetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits); - audio_format.bits = (uint8_t)bits; - audio_format.sample_rate = - (unsigned int)afGetRate(af_fp, AF_DEFAULT_TRACK); - audio_format.channels = - (uint8_t)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK); + + audio_format_init(&audio_format, afGetRate(af_fp, AF_DEFAULT_TRACK), + bits, afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK)); if (!audio_format_valid(&audio_format)) { g_warning("Invalid audio format: %u:%u:%u\n", diff --git a/src/decoder/faad_plugin.c b/src/decoder/faad_plugin.c index d0537dd5b..1b8b2b784 100644 --- a/src/decoder/faad_plugin.c +++ b/src/decoder/faad_plugin.c @@ -262,11 +262,7 @@ faad_decoder_init(faacDecHandle decoder, struct decoder_buffer *buffer, decoder_buffer_consume(buffer, nbytes); - *audio_format = (struct audio_format){ - .bits = 16, - .channels = channels, - .sample_rate = sample_rate, - }; + audio_format_init(audio_format, sample_rate, 16, channels); return true; } diff --git a/src/decoder/ffmpeg_plugin.c b/src/decoder/ffmpeg_plugin.c index 03c46a732..f6003d2f3 100644 --- a/src/decoder/ffmpeg_plugin.c +++ b/src/decoder/ffmpeg_plugin.c @@ -267,6 +267,7 @@ ffmpeg_decode_internal(struct ffmpeg_context *ctx) struct audio_format audio_format; enum decoder_command cmd; int total_time; + uint8_t bits; total_time = 0; @@ -275,13 +276,13 @@ ffmpeg_decode_internal(struct ffmpeg_context *ctx) } #if LIBAVCODEC_VERSION_INT >= ((51<<16)+(41<<8)+0) - audio_format.bits = (uint8_t) av_get_bits_per_sample_format(codec_context->sample_fmt); + bits = (uint8_t) av_get_bits_per_sample_format(codec_context->sample_fmt); #else /* XXX fixme 16-bit for older ffmpeg (13 Aug 2007) */ - audio_format.bits = (uint8_t) 16; + bits = (uint8_t) 16; #endif - audio_format.sample_rate = (unsigned int)codec_context->sample_rate; - audio_format.channels = codec_context->channels; + audio_format_init(&audio_format, codec_context->sample_rate, bits, + codec_context->channels); if (!audio_format_valid(&audio_format)) { g_warning("Invalid audio format: %u:%u:%u\n", diff --git a/src/decoder/mad_plugin.c b/src/decoder/mad_plugin.c index c6b9d32d3..85f4506d2 100644 --- a/src/decoder/mad_plugin.c +++ b/src/decoder/mad_plugin.c @@ -1148,13 +1148,6 @@ mp3_read(struct mp3_data *data, struct replay_gain_info **replay_gain_info_r) return ret != DECODE_BREAK; } -static void mp3_audio_format(struct mp3_data *data, struct audio_format *af) -{ - af->bits = 24; - af->sample_rate = (data->frame).header.samplerate; - af->channels = MAD_NCHANNELS(&(data->frame).header); -} - static void mp3_decode(struct decoder *decoder, struct input_stream *input_stream) { @@ -1170,7 +1163,8 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) return; } - mp3_audio_format(&data, &audio_format); + audio_format_init(&audio_format, data.frame.header.samplerate, 24, + MAD_NCHANNELS(&data.frame.header)); decoder_initialized(decoder, &audio_format, data.input_stream->seekable, data.total_time); diff --git a/src/decoder/mikmod_plugin.c b/src/decoder/mikmod_plugin.c index 065c34319..e7b7bfb03 100644 --- a/src/decoder/mikmod_plugin.c +++ b/src/decoder/mikmod_plugin.c @@ -175,9 +175,7 @@ mod_decode(struct decoder *decoder, const char *path) return; } - audio_format.bits = 16; - audio_format.sample_rate = 44100; - audio_format.channels = 2; + audio_format_init(&audio_format, 44100, 16, 2); secPerByte = 1.0 / ((audio_format.bits * audio_format.channels / 8.0) * diff --git a/src/decoder/modplug_plugin.c b/src/decoder/modplug_plugin.c index 31f0a47c2..6c375e6a0 100644 --- a/src/decoder/modplug_plugin.c +++ b/src/decoder/modplug_plugin.c @@ -121,9 +121,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is) return; } - audio_format.bits = 16; - audio_format.sample_rate = 44100; - audio_format.channels = 2; + audio_format_init(&audio_format, 44100, 16, 2); sec_perbyte = 1.0 / ((audio_format.bits * audio_format.channels / 8.0) * diff --git a/src/decoder/mp4ff_plugin.c b/src/decoder/mp4ff_plugin.c index cf9382904..d2c63f983 100644 --- a/src/decoder/mp4ff_plugin.c +++ b/src/decoder/mp4ff_plugin.c @@ -131,11 +131,7 @@ mp4_faad_new(mp4ff_t *mp4fh, int *track_r, struct audio_format *audio_format) } *track_r = track; - *audio_format = (struct audio_format){ - .bits = 16, - .channels = channels, - .sample_rate = sample_rate, - }; + audio_format_init(audio_format, sample_rate, 16, channels); if (!audio_format_valid(audio_format)) { g_warning("Invalid audio format: %u:%u:%u\n", diff --git a/src/decoder/mpcdec_plugin.c b/src/decoder/mpcdec_plugin.c index 26349f93a..a684da104 100644 --- a/src/decoder/mpcdec_plugin.c +++ b/src/decoder/mpcdec_plugin.c @@ -193,9 +193,7 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is) mpc_demux_get_info(demux, &info); #endif - audio_format.bits = 24; - audio_format.channels = info.channels; - audio_format.sample_rate = info.sample_freq; + audio_format_init(&audio_format, info.sample_freq, 24, info.channels); if (!audio_format_valid(&audio_format)) { #ifndef MPC_IS_OLD_API diff --git a/src/decoder/sidplay_plugin.cxx b/src/decoder/sidplay_plugin.cxx index c62e6b4b6..54ab746e2 100644 --- a/src/decoder/sidplay_plugin.cxx +++ b/src/decoder/sidplay_plugin.cxx @@ -103,9 +103,7 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs) /* initialize the MPD decoder */ struct audio_format audio_format; - audio_format.sample_rate = 48000; - audio_format.bits = 16; - audio_format.channels = 2; + audio_format_init(&audio_format, 48000, 16, 2); decoder_initialized(decoder, &audio_format, false, -1); diff --git a/src/decoder/sndfile_decoder_plugin.c b/src/decoder/sndfile_decoder_plugin.c index 0c5d2f063..4cc64459f 100644 --- a/src/decoder/sndfile_decoder_plugin.c +++ b/src/decoder/sndfile_decoder_plugin.c @@ -124,12 +124,10 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is) return; } - audio_format.sample_rate = info.samplerate; /* for now, always read 32 bit samples. Later, we could lower MPD's CPU usage by reading 16 bit samples with sf_readf_short() on low-quality source files. */ - audio_format.bits = 32; - audio_format.channels = info.channels; + audio_format_init(&audio_format, info.samplerate, 32, info.channels); if (!audio_format_valid(&audio_format)) { g_warning("invalid audio format"); diff --git a/src/decoder/vorbis_plugin.c b/src/decoder/vorbis_plugin.c index d4f81e91f..bab1d57ec 100644 --- a/src/decoder/vorbis_plugin.c +++ b/src/decoder/vorbis_plugin.c @@ -324,8 +324,7 @@ vorbis_stream_decode(struct decoder *decoder, vorbis_info *vi = ov_info(&vf, -1); struct replay_gain_info *new_rgi; - audio_format.channels = vi->channels; - audio_format.sample_rate = vi->rate; + audio_format_init(&audio_format, vi->rate, 16, vi->channels); if (!audio_format_valid(&audio_format)) { g_warning("Invalid audio format: %u:%u:%u\n", diff --git a/src/decoder/wavpack_plugin.c b/src/decoder/wavpack_plugin.c index 821536fb5..f3d701144 100644 --- a/src/decoder/wavpack_plugin.c +++ b/src/decoder/wavpack_plugin.c @@ -145,9 +145,9 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek, int bytes_per_sample, output_sample_size; int position; - audio_format.sample_rate = WavpackGetSampleRate(wpc); - audio_format.channels = WavpackGetReducedChannels(wpc); - audio_format.bits = WavpackGetBitsPerSample(wpc); + audio_format_init(&audio_format, WavpackGetSampleRate(wpc), + WavpackGetBitsPerSample(wpc), + WavpackGetReducedChannels(wpc)); /* round bitwidth to 8-bit units */ audio_format.bits = (audio_format.bits + 7) & (~7); |