aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-03 21:00:50 +0200
committerMax Kellermann <max@duempel.org>2013-08-03 21:37:56 +0200
commitd1e7b4e38136f9342aad76c685a13adf0e69f869 (patch)
tree49643b937ddfe735511b566a71398da5a945d7aa /src/decoder
parent67f591a9ce60651da41afc499bd9a22e25314e35 (diff)
downloadmpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.tar.gz
mpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.tar.xz
mpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.zip
audio_format: convert to C++
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/AdPlugDecoderPlugin.cxx7
-rw-r--r--src/decoder/AudiofileDecoderPlugin.cxx20
-rw-r--r--src/decoder/DsdiffDecoderPlugin.cxx14
-rw-r--r--src/decoder/DsfDecoderPlugin.cxx14
-rw-r--r--src/decoder/FaadDecoderPlugin.cxx14
-rw-r--r--src/decoder/FfmpegDecoderPlugin.cxx25
-rw-r--r--src/decoder/FfmpegMetaData.hxx5
-rw-r--r--src/decoder/FlacCommon.cxx24
-rw-r--r--src/decoder/FlacCommon.hxx2
-rw-r--r--src/decoder/FlacDecoderPlugin.cxx2
-rw-r--r--src/decoder/FlacPcm.cxx16
-rw-r--r--src/decoder/FlacPcm.hxx4
-rw-r--r--src/decoder/FluidsynthDecoderPlugin.cxx5
-rw-r--r--src/decoder/GmeDecoderPlugin.cxx8
-rw-r--r--src/decoder/MadDecoderPlugin.cxx8
-rw-r--r--src/decoder/MikmodDecoderPlugin.cxx7
-rw-r--r--src/decoder/ModplugDecoderPlugin.cxx7
-rw-r--r--src/decoder/MpcdecDecoderPlugin.cxx8
-rw-r--r--src/decoder/Mpg123DecoderPlugin.cxx14
-rw-r--r--src/decoder/OpusDecoderPlugin.cxx9
-rw-r--r--src/decoder/PcmDecoderPlugin.cxx8
-rw-r--r--src/decoder/SndfileDecoderPlugin.cxx14
-rw-r--r--src/decoder/VorbisDecoderPlugin.cxx10
-rw-r--r--src/decoder/WavpackDecoderPlugin.cxx24
-rw-r--r--src/decoder/WildmidiDecoderPlugin.cxx6
-rw-r--r--src/decoder/sidplay_decoder_plugin.cxx7
26 files changed, 143 insertions, 139 deletions
diff --git a/src/decoder/AdPlugDecoderPlugin.cxx b/src/decoder/AdPlugDecoderPlugin.cxx
index a9a90c283..37a95ce5d 100644
--- a/src/decoder/AdPlugDecoderPlugin.cxx
+++ b/src/decoder/AdPlugDecoderPlugin.cxx
@@ -60,11 +60,10 @@ adplug_file_decode(struct decoder *decoder, const char *path_fs)
if (player == nullptr)
return;
- struct audio_format audio_format;
- audio_format_init(&audio_format, sample_rate, SAMPLE_FORMAT_S16, 2);
- assert(audio_format_valid(&audio_format));
+ const AudioFormat audio_format(sample_rate, SampleFormat::S16, 2);
+ assert(audio_format.IsValid());
- decoder_initialized(decoder, &audio_format, false,
+ decoder_initialized(decoder, audio_format, false,
player->songlength() / 1000.);
int16_t buffer[2048];
diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx
index b77c41d02..9c00b20ce 100644
--- a/src/decoder/AudiofileDecoderPlugin.cxx
+++ b/src/decoder/AudiofileDecoderPlugin.cxx
@@ -114,27 +114,27 @@ setup_virtual_fops(struct input_stream *stream)
return vf;
}
-static enum sample_format
+static SampleFormat
audiofile_bits_to_sample_format(int bits)
{
switch (bits) {
case 8:
- return SAMPLE_FORMAT_S8;
+ return SampleFormat::S8;
case 16:
- return SAMPLE_FORMAT_S16;
+ return SampleFormat::S16;
case 24:
- return SAMPLE_FORMAT_S24_P32;
+ return SampleFormat::S24_P32;
case 32:
- return SAMPLE_FORMAT_S32;
+ return SampleFormat::S32;
}
- return SAMPLE_FORMAT_UNDEFINED;
+ return SampleFormat::UNDEFINED;
}
-static enum sample_format
+static SampleFormat
audiofile_setup_sample_format(AFfilehandle af_fp)
{
int fs, bits;
@@ -160,7 +160,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
AFvirtualfile *vf;
int fs, frame_count;
AFfilehandle af_fp;
- struct audio_format audio_format;
+ AudioFormat audio_format;
float total_time;
uint16_t bit_rate;
int ret;
@@ -180,7 +180,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
return;
}
- if (!audio_format_init_checked(&audio_format,
+ if (!audio_format_init_checked(audio_format,
afGetRate(af_fp, AF_DEFAULT_TRACK),
audiofile_setup_sample_format(af_fp),
afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK),
@@ -199,7 +199,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
- decoder_initialized(decoder, &audio_format, true, total_time);
+ decoder_initialized(decoder, audio_format, true, total_time);
do {
ret = afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk,
diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx
index 4b9a59a7a..10b31a204 100644
--- a/src/decoder/DsdiffDecoderPlugin.cxx
+++ b/src/decoder/DsdiffDecoderPlugin.cxx
@@ -433,9 +433,9 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is)
return;
GError *error = nullptr;
- struct audio_format audio_format;
- if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
- SAMPLE_FORMAT_DSD,
+ AudioFormat audio_format;
+ if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
+ SampleFormat::DSD,
metadata.channels, &error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -448,7 +448,7 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is)
(float) metadata.sample_rate;
/* success: file was recognized */
- decoder_initialized(decoder, &audio_format, false, songtime);
+ decoder_initialized(decoder, audio_format, false, songtime);
/* every iteration of the following loop decodes one "DSD"
chunk from a DFF file */
@@ -487,9 +487,9 @@ dsdiff_scan_stream(struct input_stream *is,
if (!dsdiff_read_metadata(nullptr, is, &metadata, &chunk_header))
return false;
- struct audio_format audio_format;
- if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
- SAMPLE_FORMAT_DSD,
+ AudioFormat audio_format;
+ if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
+ SampleFormat::DSD,
metadata.channels, nullptr))
/* refuse to parse files which we cannot play anyway */
return false;
diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx
index 9661d70e6..ad1323d88 100644
--- a/src/decoder/DsfDecoderPlugin.cxx
+++ b/src/decoder/DsfDecoderPlugin.cxx
@@ -285,9 +285,9 @@ dsf_stream_decode(struct decoder *decoder, struct input_stream *is)
return;
GError *error = NULL;
- struct audio_format audio_format;
- if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
- SAMPLE_FORMAT_DSD,
+ AudioFormat audio_format;
+ if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
+ SampleFormat::DSD,
metadata.channels, &error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -299,7 +299,7 @@ dsf_stream_decode(struct decoder *decoder, struct input_stream *is)
(float) metadata.sample_rate;
/* success: file was recognized */
- decoder_initialized(decoder, &audio_format, false, songtime);
+ decoder_initialized(decoder, audio_format, false, songtime);
if (!dsf_decode_chunk(decoder, is, metadata.channels,
chunk_size,
@@ -317,9 +317,9 @@ dsf_scan_stream(struct input_stream *is,
if (!dsf_read_metadata(NULL, is, &metadata))
return false;
- struct audio_format audio_format;
- if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
- SAMPLE_FORMAT_DSD,
+ AudioFormat audio_format;
+ if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
+ SampleFormat::DSD,
metadata.channels, NULL))
/* refuse to parse files which we cannot play anyway */
return false;
diff --git a/src/decoder/FaadDecoderPlugin.cxx b/src/decoder/FaadDecoderPlugin.cxx
index 1b7edb49f..547ba24e0 100644
--- a/src/decoder/FaadDecoderPlugin.cxx
+++ b/src/decoder/FaadDecoderPlugin.cxx
@@ -248,7 +248,7 @@ faad_song_duration(DecoderBuffer *buffer, struct input_stream *is)
*/
static bool
faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
- struct audio_format *audio_format, GError **error_r)
+ AudioFormat &audio_format, GError **error_r)
{
int32_t nbytes;
uint32_t sample_rate;
@@ -285,7 +285,7 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
decoder_buffer_consume(buffer, nbytes);
return audio_format_init_checked(audio_format, sample_rate,
- SAMPLE_FORMAT_S16, channels, error_r);
+ SampleFormat::S16, channels, error_r);
}
/**
@@ -325,7 +325,7 @@ faad_get_file_time_float(struct input_stream *is)
if (length < 0) {
bool ret;
- struct audio_format audio_format;
+ AudioFormat audio_format;
NeAACDecHandle decoder = NeAACDecOpen();
@@ -336,7 +336,7 @@ faad_get_file_time_float(struct input_stream *is)
decoder_buffer_fill(buffer);
- ret = faad_decoder_init(decoder, buffer, &audio_format, nullptr);
+ ret = faad_decoder_init(decoder, buffer, audio_format, nullptr);
if (ret)
length = 0;
@@ -370,7 +370,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
{
GError *error = nullptr;
float total_time = 0;
- struct audio_format audio_format;
+ AudioFormat audio_format;
bool ret;
uint16_t bit_rate = 0;
DecoderBuffer *buffer;
@@ -400,7 +400,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
/* initialize it */
- ret = faad_decoder_init(decoder, buffer, &audio_format, &error);
+ ret = faad_decoder_init(decoder, buffer, audio_format, &error);
if (!ret) {
g_warning("%s", error->message);
g_error_free(error);
@@ -410,7 +410,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
/* initialize the MPD core */
- decoder_initialized(mpd_decoder, &audio_format, false, total_time);
+ decoder_initialized(mpd_decoder, audio_format, false, total_time);
/* the decoder loop */
diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx
index b4aa947c9..e4330f4d6 100644
--- a/src/decoder/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/FfmpegDecoderPlugin.cxx
@@ -52,6 +52,11 @@ extern "C" {
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "ffmpeg"
+/* suppress the ffmpeg compatibility macro */
+#ifdef SampleFormat
+#undef SampleFormat
+#endif
+
static GLogLevelFlags
level_ffmpeg_to_glib(int level)
{
@@ -297,20 +302,20 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
}
G_GNUC_CONST
-static enum sample_format
+static SampleFormat
ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
{
switch (sample_fmt) {
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S16P:
- return SAMPLE_FORMAT_S16;
+ return SampleFormat::S16;
case AV_SAMPLE_FMT_S32:
case AV_SAMPLE_FMT_S32P:
- return SAMPLE_FORMAT_S32;
+ return SampleFormat::S32;
case AV_SAMPLE_FMT_FLTP:
- return SAMPLE_FORMAT_FLOAT;
+ return SampleFormat::FLOAT;
default:
break;
@@ -325,7 +330,7 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
else
g_warning("Unsupported libavcodec SampleFormat value: %d",
sample_fmt);
- return SAMPLE_FORMAT_UNDEFINED;
+ return SampleFormat::UNDEFINED;
}
static AVInputFormat *
@@ -420,14 +425,14 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
return;
}
- const enum sample_format sample_format =
+ const SampleFormat sample_format =
ffmpeg_sample_format(codec_context->sample_fmt);
- if (sample_format == SAMPLE_FORMAT_UNDEFINED)
+ if (sample_format == SampleFormat::UNDEFINED)
return;
GError *error = NULL;
- struct audio_format audio_format;
- if (!audio_format_init_checked(&audio_format,
+ AudioFormat audio_format;
+ if (!audio_format_init_checked(audio_format,
codec_context->sample_rate,
sample_format,
codec_context->channels, &error)) {
@@ -455,7 +460,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
? format_context->duration / AV_TIME_BASE
: 0;
- decoder_initialized(decoder, &audio_format,
+ decoder_initialized(decoder, audio_format,
input->seekable, total_time);
AVFrame *frame = avcodec_alloc_frame();
diff --git a/src/decoder/FfmpegMetaData.hxx b/src/decoder/FfmpegMetaData.hxx
index 466d2cb1d..0fd73df04 100644
--- a/src/decoder/FfmpegMetaData.hxx
+++ b/src/decoder/FfmpegMetaData.hxx
@@ -26,6 +26,11 @@ extern "C" {
#include <libavutil/dict.h>
}
+/* suppress the ffmpeg compatibility macro */
+#ifdef SampleFormat
+#undef SampleFormat
+#endif
+
struct tag_handler;
void
diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx
index 32917ed86..5bcc20b97 100644
--- a/src/decoder/FlacCommon.cxx
+++ b/src/decoder/FlacCommon.cxx
@@ -40,24 +40,24 @@ flac_data::flac_data(struct decoder *_decoder,
{
}
-static enum sample_format
+static SampleFormat
flac_sample_format(unsigned bits_per_sample)
{
switch (bits_per_sample) {
case 8:
- return SAMPLE_FORMAT_S8;
+ return SampleFormat::S8;
case 16:
- return SAMPLE_FORMAT_S16;
+ return SampleFormat::S16;
case 24:
- return SAMPLE_FORMAT_S24_P32;
+ return SampleFormat::S24_P32;
case 32:
- return SAMPLE_FORMAT_S32;
+ return SampleFormat::S32;
default:
- return SAMPLE_FORMAT_UNDEFINED;
+ return SampleFormat::UNDEFINED;
}
}
@@ -69,7 +69,7 @@ flac_got_stream_info(struct flac_data *data,
return;
GError *error = nullptr;
- if (!audio_format_init_checked(&data->audio_format,
+ if (!audio_format_init_checked(data->audio_format,
stream_info->sample_rate,
flac_sample_format(stream_info->bits_per_sample),
stream_info->channels, &error)) {
@@ -79,7 +79,7 @@ flac_got_stream_info(struct flac_data *data,
return;
}
- data->frame_size = audio_format_frame_size(&data->audio_format);
+ data->frame_size = data->audio_format.GetFrameSize();
if (data->total_frames == 0)
data->total_frames = stream_info->total_samples;
@@ -132,7 +132,7 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header)
return false;
GError *error = nullptr;
- if (!audio_format_init_checked(&data->audio_format,
+ if (!audio_format_init_checked(data->audio_format,
header->sample_rate,
flac_sample_format(header->bits_per_sample),
header->channels, &error)) {
@@ -142,9 +142,9 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header)
return false;
}
- data->frame_size = audio_format_frame_size(&data->audio_format);
+ data->frame_size = data->audio_format.GetFrameSize();
- decoder_initialized(data->decoder, &data->audio_format,
+ decoder_initialized(data->decoder, data->audio_format,
data->input_stream->seekable,
(float)data->total_frames /
(float)data->audio_format.sample_rate);
@@ -170,7 +170,7 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
buffer = data->buffer.Get(buffer_size);
flac_convert(buffer, frame->header.channels,
- (enum sample_format)data->audio_format.format, buf,
+ data->audio_format.format, buf,
0, frame->header.blocksize);
if (nbytes > 0)
diff --git a/src/decoder/FlacCommon.hxx b/src/decoder/FlacCommon.hxx
index d2e240d81..f9fade6fc 100644
--- a/src/decoder/FlacCommon.hxx
+++ b/src/decoder/FlacCommon.hxx
@@ -56,7 +56,7 @@ struct flac_data : public FlacInput {
* The validated audio format of the FLAC file. This
* attribute is defined if "initialized" is true.
*/
- struct audio_format audio_format;
+ AudioFormat audio_format;
/**
* The total number of frames in this song. The decoder
diff --git a/src/decoder/FlacDecoderPlugin.cxx b/src/decoder/FlacDecoderPlugin.cxx
index fc0925610..7becf73e5 100644
--- a/src/decoder/FlacDecoderPlugin.cxx
+++ b/src/decoder/FlacDecoderPlugin.cxx
@@ -144,7 +144,7 @@ flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd,
if (data->initialized) {
/* done */
- decoder_initialized(data->decoder, &data->audio_format,
+ decoder_initialized(data->decoder, data->audio_format,
data->input_stream->seekable,
(float)data->total_frames /
(float)data->audio_format.sample_rate);
diff --git a/src/decoder/FlacPcm.cxx b/src/decoder/FlacPcm.cxx
index 17a13edda..ff855fa70 100644
--- a/src/decoder/FlacPcm.cxx
+++ b/src/decoder/FlacPcm.cxx
@@ -76,12 +76,12 @@ flac_convert_8(int8_t *dest,
void
flac_convert(void *dest,
- unsigned int num_channels, enum sample_format sample_format,
+ unsigned int num_channels, SampleFormat sample_format,
const FLAC__int32 *const buf[],
unsigned int position, unsigned int end)
{
switch (sample_format) {
- case SAMPLE_FORMAT_S16:
+ case SampleFormat::S16:
if (num_channels == 2)
flac_convert_stereo16((int16_t*)dest, buf,
position, end);
@@ -90,20 +90,20 @@ flac_convert(void *dest,
position, end);
break;
- case SAMPLE_FORMAT_S24_P32:
- case SAMPLE_FORMAT_S32:
+ case SampleFormat::S24_P32:
+ case SampleFormat::S32:
flac_convert_32((int32_t*)dest, num_channels, buf,
position, end);
break;
- case SAMPLE_FORMAT_S8:
+ case SampleFormat::S8:
flac_convert_8((int8_t*)dest, num_channels, buf,
position, end);
break;
- case SAMPLE_FORMAT_FLOAT:
- case SAMPLE_FORMAT_DSD:
- case SAMPLE_FORMAT_UNDEFINED:
+ case SampleFormat::FLOAT:
+ case SampleFormat::DSD:
+ case SampleFormat::UNDEFINED:
assert(false);
gcc_unreachable();
}
diff --git a/src/decoder/FlacPcm.hxx b/src/decoder/FlacPcm.hxx
index 97d214c17..fa85f65dd 100644
--- a/src/decoder/FlacPcm.hxx
+++ b/src/decoder/FlacPcm.hxx
@@ -20,13 +20,13 @@
#ifndef MPD_FLAC_PCM_HXX
#define MPD_FLAC_PCM_HXX
-#include "audio_format.h"
+#include "AudioFormat.hxx"
#include <FLAC/ordinals.h>
void
flac_convert(void *dest,
- unsigned int num_channels, enum sample_format sample_format,
+ unsigned int num_channels, SampleFormat sample_format,
const FLAC__int32 *const buf[],
unsigned int position, unsigned int end);
diff --git a/src/decoder/FluidsynthDecoderPlugin.cxx b/src/decoder/FluidsynthDecoderPlugin.cxx
index 15d2f5e6b..e559ad45e 100644
--- a/src/decoder/FluidsynthDecoderPlugin.cxx
+++ b/src/decoder/FluidsynthDecoderPlugin.cxx
@@ -166,9 +166,8 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs)
/* initialization complete - announce the audio format to the
MPD core */
- struct audio_format audio_format;
- audio_format_init(&audio_format, sample_rate, SAMPLE_FORMAT_S16, 2);
- decoder_initialized(decoder, &audio_format, false, -1);
+ const AudioFormat audio_format(sample_rate, SampleFormat::S16, 2);
+ decoder_initialized(decoder, audio_format, false, -1);
while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING) {
int16_t buffer[2048];
diff --git a/src/decoder/GmeDecoderPlugin.cxx b/src/decoder/GmeDecoderPlugin.cxx
index 8158ab553..d8edbe4cb 100644
--- a/src/decoder/GmeDecoderPlugin.cxx
+++ b/src/decoder/GmeDecoderPlugin.cxx
@@ -153,9 +153,9 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
/* initialize the MPD decoder */
GError *error = nullptr;
- struct audio_format audio_format;
- if (!audio_format_init_checked(&audio_format, GME_SAMPLE_RATE,
- SAMPLE_FORMAT_S16, GME_CHANNELS,
+ AudioFormat audio_format;
+ if (!audio_format_init_checked(audio_format, GME_SAMPLE_RATE,
+ SampleFormat::S16, GME_CHANNELS,
&error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -164,7 +164,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
return;
}
- decoder_initialized(decoder, &audio_format, true, song_len);
+ decoder_initialized(decoder, audio_format, true, song_len);
gme_err = gme_start_track(emu, song_num);
if (gme_err != nullptr)
diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx
index b75e12343..04d171b9b 100644
--- a/src/decoder/MadDecoderPlugin.cxx
+++ b/src/decoder/MadDecoderPlugin.cxx
@@ -1124,11 +1124,11 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
return;
}
- struct audio_format audio_format;
+ AudioFormat audio_format;
GError *error = nullptr;
- if (!audio_format_init_checked(&audio_format,
+ if (!audio_format_init_checked(audio_format,
data.frame.header.samplerate,
- SAMPLE_FORMAT_S24_P32,
+ SampleFormat::S24_P32,
MAD_NCHANNELS(&data.frame.header),
&error)) {
g_warning("%s", error->message);
@@ -1138,7 +1138,7 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
return;
}
- decoder_initialized(decoder, &audio_format,
+ decoder_initialized(decoder, audio_format,
input_stream_is_seekable(input_stream),
data.total_time);
diff --git a/src/decoder/MikmodDecoderPlugin.cxx b/src/decoder/MikmodDecoderPlugin.cxx
index d332664ee..3aa8a68ed 100644
--- a/src/decoder/MikmodDecoderPlugin.cxx
+++ b/src/decoder/MikmodDecoderPlugin.cxx
@@ -147,7 +147,6 @@ mikmod_decoder_file_decode(struct decoder *decoder, const char *path_fs)
{
char *path2;
MODULE *handle;
- struct audio_format audio_format;
int ret;
SBYTE buffer[MIKMOD_FRAME_SIZE];
enum decoder_command cmd = DECODE_COMMAND_NONE;
@@ -164,10 +163,10 @@ mikmod_decoder_file_decode(struct decoder *decoder, const char *path_fs)
/* Prevent module from looping forever */
handle->loop = 0;
- audio_format_init(&audio_format, mikmod_sample_rate, SAMPLE_FORMAT_S16, 2);
- assert(audio_format_valid(&audio_format));
+ const AudioFormat audio_format(mikmod_sample_rate, SampleFormat::S16, 2);
+ assert(audio_format.IsValid());
- decoder_initialized(decoder, &audio_format, false, 0);
+ decoder_initialized(decoder, audio_format, false, 0);
Player_Start(handle);
while (cmd == DECODE_COMMAND_NONE && Player_Active()) {
diff --git a/src/decoder/ModplugDecoderPlugin.cxx b/src/decoder/ModplugDecoderPlugin.cxx
index 2ba3b0f49..b95736bf8 100644
--- a/src/decoder/ModplugDecoderPlugin.cxx
+++ b/src/decoder/ModplugDecoderPlugin.cxx
@@ -94,7 +94,6 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
ModPlugFile *f;
ModPlug_Settings settings;
GByteArray *bdatas;
- struct audio_format audio_format;
int ret;
char audio_buffer[MODPLUG_FRAME_SIZE];
enum decoder_command cmd = DECODE_COMMAND_NONE;
@@ -122,10 +121,10 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
return;
}
- audio_format_init(&audio_format, 44100, SAMPLE_FORMAT_S16, 2);
- assert(audio_format_valid(&audio_format));
+ static constexpr AudioFormat audio_format(44100, SampleFormat::S16, 2);
+ assert(audio_format.IsValid());
- decoder_initialized(decoder, &audio_format,
+ decoder_initialized(decoder, audio_format,
input_stream_is_seekable(is),
ModPlug_GetLength(f) / 1000.0);
diff --git a/src/decoder/MpcdecDecoderPlugin.cxx b/src/decoder/MpcdecDecoderPlugin.cxx
index 921d7d923..cfb9c034b 100644
--- a/src/decoder/MpcdecDecoderPlugin.cxx
+++ b/src/decoder/MpcdecDecoderPlugin.cxx
@@ -154,9 +154,9 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
mpc_demux_get_info(demux, &info);
GError *error = nullptr;
- struct audio_format audio_format;
- if (!audio_format_init_checked(&audio_format, info.sample_freq,
- SAMPLE_FORMAT_S24_P32,
+ AudioFormat audio_format;
+ if (!audio_format_init_checked(audio_format, info.sample_freq,
+ SampleFormat::S24_P32,
info.channels, &error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -173,7 +173,7 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
decoder_replay_gain(mpd_decoder, &replay_gain_info);
- decoder_initialized(mpd_decoder, &audio_format,
+ decoder_initialized(mpd_decoder, audio_format,
input_stream_is_seekable(is),
mpc_streaminfo_get_length(&info));
diff --git a/src/decoder/Mpg123DecoderPlugin.cxx b/src/decoder/Mpg123DecoderPlugin.cxx
index 73f94ea44..1aac825a2 100644
--- a/src/decoder/Mpg123DecoderPlugin.cxx
+++ b/src/decoder/Mpg123DecoderPlugin.cxx
@@ -56,7 +56,7 @@ mpd_mpg123_finish(void)
*/
static bool
mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
- struct audio_format *audio_format)
+ AudioFormat &audio_format)
{
GError *gerror = nullptr;
char *path_dup;
@@ -90,7 +90,7 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
return false;
}
- if (!audio_format_init_checked(audio_format, rate, SAMPLE_FORMAT_S16,
+ if (!audio_format_init_checked(audio_format, rate, SampleFormat::S16,
channels, &gerror)) {
g_warning("%s", gerror->message);
g_error_free(gerror);
@@ -103,7 +103,6 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
static void
mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
{
- struct audio_format audio_format;
mpg123_handle *handle;
int error;
off_t num_samples;
@@ -119,7 +118,8 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
return;
}
- if (!mpd_mpg123_open(handle, path_fs, &audio_format)) {
+ AudioFormat audio_format;
+ if (!mpd_mpg123_open(handle, path_fs, audio_format)) {
mpg123_delete(handle);
return;
}
@@ -128,7 +128,7 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
/* tell MPD core we're ready */
- decoder_initialized(decoder, &audio_format, true,
+ decoder_initialized(decoder, audio_format, true,
(float)num_samples /
(float)audio_format.sample_rate);
@@ -198,7 +198,6 @@ static bool
mpd_mpg123_scan_file(const char *path_fs,
const struct tag_handler *handler, void *handler_ctx)
{
- struct audio_format audio_format;
mpg123_handle *handle;
int error;
off_t num_samples;
@@ -210,7 +209,8 @@ mpd_mpg123_scan_file(const char *path_fs,
return false;
}
- if (!mpd_mpg123_open(handle, path_fs, &audio_format)) {
+ AudioFormat audio_format;
+ if (!mpd_mpg123_open(handle, path_fs, audio_format)) {
mpg123_delete(handle);
return false;
}
diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx
index 08c67b570..94c687317 100644
--- a/src/decoder/OpusDecoderPlugin.cxx
+++ b/src/decoder/OpusDecoderPlugin.cxx
@@ -202,11 +202,10 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
return DECODE_COMMAND_STOP;
}
- struct audio_format audio_format;
- audio_format_init(&audio_format, opus_sample_rate,
- SAMPLE_FORMAT_S16, channels);
- decoder_initialized(decoder, &audio_format, false, -1);
- frame_size = audio_format_frame_size(&audio_format);
+ const AudioFormat audio_format(opus_sample_rate,
+ SampleFormat::S16, channels);
+ decoder_initialized(decoder, audio_format, false, -1);
+ frame_size = audio_format.GetFrameSize();
/* allocate an output buffer for 16 bit PCM samples big enough
to hold a quarter second, larger than 120ms required by
diff --git a/src/decoder/PcmDecoderPlugin.cxx b/src/decoder/PcmDecoderPlugin.cxx
index f64357e68..8976f511f 100644
--- a/src/decoder/PcmDecoderPlugin.cxx
+++ b/src/decoder/PcmDecoderPlugin.cxx
@@ -36,9 +36,9 @@ extern "C" {
static void
pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
{
- static constexpr struct audio_format audio_format = {
+ static constexpr AudioFormat audio_format = {
44100,
- SAMPLE_FORMAT_S16,
+ SampleFormat::S16,
2,
};
@@ -49,14 +49,14 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
GError *error = nullptr;
enum decoder_command cmd;
- double time_to_size = audio_format_time_to_size(&audio_format);
+ const double time_to_size = audio_format.GetTimeToSize();
float total_time = -1;
const goffset size = input_stream_get_size(is);
if (size >= 0)
total_time = size / time_to_size;
- decoder_initialized(decoder, &audio_format,
+ decoder_initialized(decoder, audio_format,
input_stream_is_seekable(is), total_time);
do {
diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx
index b1bb97538..63401a47b 100644
--- a/src/decoder/SndfileDecoderPlugin.cxx
+++ b/src/decoder/SndfileDecoderPlugin.cxx
@@ -99,7 +99,7 @@ static SF_VIRTUAL_IO vio = {
* Converts a frame number to a timestamp (in seconds).
*/
static float
-frame_to_time(sf_count_t frame, const struct audio_format *audio_format)
+frame_to_time(sf_count_t frame, const AudioFormat *audio_format)
{
return (float)frame / (float)audio_format->sample_rate;
}
@@ -108,7 +108,7 @@ frame_to_time(sf_count_t frame, const struct audio_format *audio_format)
* Converts a timestamp (in seconds) to a frame number.
*/
static sf_count_t
-time_to_frame(float t, const struct audio_format *audio_format)
+time_to_frame(float t, const AudioFormat *audio_format)
{
return (sf_count_t)(t * audio_format->sample_rate);
}
@@ -119,7 +119,6 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is)
GError *error = nullptr;
SNDFILE *sf;
SF_INFO info;
- struct audio_format audio_format;
size_t frame_size;
sf_count_t read_frames, num_frames;
int buffer[4096];
@@ -136,18 +135,19 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is)
/* 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. */
- if (!audio_format_init_checked(&audio_format, info.samplerate,
- SAMPLE_FORMAT_S32,
+ AudioFormat audio_format;
+ if (!audio_format_init_checked(audio_format, info.samplerate,
+ SampleFormat::S32,
info.channels, &error)) {
g_warning("%s", error->message);
g_error_free(error);
return;
}
- decoder_initialized(decoder, &audio_format, info.seekable,
+ decoder_initialized(decoder, audio_format, info.seekable,
frame_to_time(info.frames, &audio_format));
- frame_size = audio_format_frame_size(&audio_format);
+ frame_size = audio_format.GetFrameSize();
read_frames = sizeof(buffer) / frame_size;
do {
diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx
index 68d5a21f0..f51480d71 100644
--- a/src/decoder/VorbisDecoderPlugin.cxx
+++ b/src/decoder/VorbisDecoderPlugin.cxx
@@ -202,12 +202,12 @@ vorbis_stream_decode(struct decoder *decoder,
return;
}
- struct audio_format audio_format;
- if (!audio_format_init_checked(&audio_format, vi->rate,
+ AudioFormat audio_format;
+ if (!audio_format_init_checked(audio_format, vi->rate,
#ifdef HAVE_TREMOR
- SAMPLE_FORMAT_S16,
+ SampleFormat::S16,
#else
- SAMPLE_FORMAT_FLOAT,
+ SampleFormat::FLOAT,
#endif
vi->channels, &error)) {
g_warning("%s", error->message);
@@ -219,7 +219,7 @@ vorbis_stream_decode(struct decoder *decoder,
if (total_time < 0)
total_time = 0;
- decoder_initialized(decoder, &audio_format, vis.seekable, total_time);
+ decoder_initialized(decoder, audio_format, vis.seekable, total_time);
enum decoder_command cmd = decoder_get_command(decoder);
diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx
index 1a31b7aac..aa62a0f67 100644
--- a/src/decoder/WavpackDecoderPlugin.cxx
+++ b/src/decoder/WavpackDecoderPlugin.cxx
@@ -106,27 +106,27 @@ format_samples_float(G_GNUC_UNUSED int bytes_per_sample, void *buffer,
/**
* Choose a MPD sample format from libwavpacks' number of bits.
*/
-static enum sample_format
+static SampleFormat
wavpack_bits_to_sample_format(bool is_float, int bytes_per_sample)
{
if (is_float)
- return SAMPLE_FORMAT_FLOAT;
+ return SampleFormat::FLOAT;
switch (bytes_per_sample) {
case 1:
- return SAMPLE_FORMAT_S8;
+ return SampleFormat::S8;
case 2:
- return SAMPLE_FORMAT_S16;
+ return SampleFormat::S16;
case 3:
- return SAMPLE_FORMAT_S24_P32;
+ return SampleFormat::S24_P32;
case 4:
- return SAMPLE_FORMAT_S32;
+ return SampleFormat::S32;
default:
- return SAMPLE_FORMAT_UNDEFINED;
+ return SampleFormat::UNDEFINED;
}
}
@@ -139,8 +139,8 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek)
{
GError *error = NULL;
bool is_float;
- enum sample_format sample_format;
- struct audio_format audio_format;
+ SampleFormat sample_format;
+ AudioFormat audio_format;
format_samples_t format_samples;
float total_time;
int bytes_per_sample, output_sample_size;
@@ -150,7 +150,7 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek)
wavpack_bits_to_sample_format(is_float,
WavpackGetBytesPerSample(wpc));
- if (!audio_format_init_checked(&audio_format,
+ if (!audio_format_init_checked(audio_format,
WavpackGetSampleRate(wpc),
sample_format,
WavpackGetNumChannels(wpc), &error)) {
@@ -168,14 +168,14 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek)
total_time = WavpackGetNumSamples(wpc);
total_time /= audio_format.sample_rate;
bytes_per_sample = WavpackGetBytesPerSample(wpc);
- output_sample_size = audio_format_frame_size(&audio_format);
+ output_sample_size = audio_format.GetFrameSize();
/* wavpack gives us all kind of samples in a 32-bit space */
int32_t chunk[1024];
const uint32_t samples_requested = G_N_ELEMENTS(chunk) /
audio_format.channels;
- decoder_initialized(decoder, &audio_format, can_seek, total_time);
+ decoder_initialized(decoder, audio_format, can_seek, total_time);
enum decoder_command cmd = decoder_get_command(decoder);
while (cmd != DECODE_COMMAND_STOP) {
diff --git a/src/decoder/WildmidiDecoderPlugin.cxx b/src/decoder/WildmidiDecoderPlugin.cxx
index 721229f87..832cabe76 100644
--- a/src/decoder/WildmidiDecoderPlugin.cxx
+++ b/src/decoder/WildmidiDecoderPlugin.cxx
@@ -60,9 +60,9 @@ wildmidi_finish(void)
static void
wildmidi_file_decode(struct decoder *decoder, const char *path_fs)
{
- static const struct audio_format audio_format = {
+ static constexpr AudioFormat audio_format = {
WILDMIDI_SAMPLE_RATE,
- SAMPLE_FORMAT_S16,
+ SampleFormat::S16,
2,
};
midi *wm;
@@ -79,7 +79,7 @@ wildmidi_file_decode(struct decoder *decoder, const char *path_fs)
return;
}
- decoder_initialized(decoder, &audio_format, true,
+ decoder_initialized(decoder, audio_format, true,
info->approx_total_samples / WILDMIDI_SAMPLE_RATE);
do {
diff --git a/src/decoder/sidplay_decoder_plugin.cxx b/src/decoder/sidplay_decoder_plugin.cxx
index cfe82cf57..d63dca6af 100644
--- a/src/decoder/sidplay_decoder_plugin.cxx
+++ b/src/decoder/sidplay_decoder_plugin.cxx
@@ -285,11 +285,10 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
/* initialize the MPD decoder */
- struct audio_format audio_format;
- audio_format_init(&audio_format, 48000, SAMPLE_FORMAT_S16, channels);
- assert(audio_format_valid(&audio_format));
+ const AudioFormat audio_format(48000, SampleFormat::S16, channels);
+ assert(audio_format.IsValid());
- decoder_initialized(decoder, &audio_format, true, (float)song_len);
+ decoder_initialized(decoder, audio_format, true, (float)song_len);
/* .. and play */