From d664baff2699842f2182968f5c26dbf63babdeff Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Jan 2013 21:47:12 +0100 Subject: audio_{parser,config}: convert to C++ --- Makefile.am | 21 ++-- src/AudioCompress/compress.h | 9 ++ src/AudioConfig.cxx | 50 ++++++++++ src/AudioConfig.hxx | 31 ++++++ src/AudioParser.cxx | 222 +++++++++++++++++++++++++++++++++++++++++++ src/AudioParser.hxx | 47 +++++++++ src/DecoderAPI.cxx | 6 +- src/Main.cxx | 2 +- src/OutputInit.cxx | 2 +- src/audio_check.h | 8 ++ src/audio_config.c | 52 ---------- src/audio_config.h | 31 ------ src/audio_parser.c | 222 ------------------------------------------- src/audio_parser.h | 57 ----------- test/run_convert.cxx | 2 +- test/run_encoder.cxx | 2 +- test/run_filter.cxx | 6 +- test/run_normalize.c | 73 -------------- test/run_normalize.cxx | 73 ++++++++++++++ test/run_output.cxx | 2 +- test/software_volume.cxx | 2 +- 21 files changed, 458 insertions(+), 462 deletions(-) create mode 100644 src/AudioConfig.cxx create mode 100644 src/AudioConfig.hxx create mode 100644 src/AudioParser.cxx create mode 100644 src/AudioParser.hxx delete mode 100644 src/audio_config.c delete mode 100644 src/audio_config.h delete mode 100644 src/audio_parser.c delete mode 100644 src/audio_parser.h delete mode 100644 test/run_normalize.c create mode 100644 test/run_normalize.cxx diff --git a/Makefile.am b/Makefile.am index 92c47423..17315e17 100644 --- a/Makefile.am +++ b/Makefile.am @@ -54,7 +54,6 @@ mpd_headers = \ src/ape.h \ src/audio_format.h \ src/audio_check.h \ - src/audio_parser.h \ src/output_internal.h \ src/output_api.h \ src/filter_internal.h \ @@ -132,10 +131,10 @@ src_mpd_SOURCES = \ src/thread/GLibCond.hxx \ src/clock.c src/clock.h \ src/notify.cxx src/notify.hxx \ - src/audio_config.c src/audio_config.h \ + src/AudioConfig.cxx src/AudioConfig.hxx \ src/audio_check.c \ src/audio_format.c \ - src/audio_parser.c \ + src/AudioParser.cxx src/AudioParser.hxx \ src/protocol/ArgParser.cxx src/protocol/ArgParser.hxx \ src/protocol/Result.cxx src/protocol/Result.hxx \ src/CommandError.cxx src/CommandError.hxx \ @@ -1244,7 +1243,7 @@ test_run_filter_SOURCES = test/run_filter.cxx \ src/tokenizer.c src/utils.c src/string_util.c \ src/audio_check.c \ src/audio_format.c \ - src/audio_parser.c \ + src/AudioParser.cxx \ src/ReplayGainInfo.cxx \ src/AudioCompress/compress.c @@ -1264,7 +1263,7 @@ test_run_encoder_SOURCES = test/run_encoder.cxx \ src/Tag.cxx src/TagNames.c src/TagPool.cxx \ src/audio_check.c \ src/audio_format.c \ - src/audio_parser.c + src/AudioParser.cxx test_run_encoder_LDADD = \ $(ENCODER_LIBS) \ $(TAG_LIBS) \ @@ -1283,7 +1282,7 @@ test_test_vorbis_encoder_SOURCES = test/test_vorbis_encoder.c \ src/Tag.cxx src/TagNames.c src/TagPool.cxx \ src/audio_check.c \ src/audio_format.c \ - src/audio_parser.c \ + src/AudioParser.cxx \ src/pcm_buffer.c \ $(ENCODER_SRC) test_test_vorbis_encoder_CPPFLAGS = $(AM_CPPFLAGS) \ @@ -1299,15 +1298,15 @@ endif test_software_volume_SOURCES = test/software_volume.cxx \ test/stdbin.h \ src/audio_check.c \ - src/audio_parser.c + src/AudioParser.cxx test_software_volume_LDADD = \ $(PCM_LIBS) \ $(GLIB_LIBS) -test_run_normalize_SOURCES = test/run_normalize.c \ +test_run_normalize_SOURCES = test/run_normalize.cxx \ test/stdbin.h \ src/audio_check.c \ - src/audio_parser.c \ + src/AudioParser.cxx \ src/AudioCompress/compress.c test_run_normalize_LDADD = \ $(GLIB_LIBS) @@ -1316,7 +1315,7 @@ test_run_convert_SOURCES = test/run_convert.cxx \ src/dsd2pcm/dsd2pcm.c \ src/audio_format.c \ src/audio_check.c \ - src/audio_parser.c + src/AudioParser.cxx test_run_convert_LDADD = \ $(PCM_LIBS) \ libutil.a \ @@ -1339,7 +1338,7 @@ test_run_output_SOURCES = test/run_output.cxx \ src/IOThread.cxx \ src/audio_check.c \ src/audio_format.c \ - src/audio_parser.c \ + src/AudioParser.cxx \ src/timer.c src/clock.c \ src/Tag.cxx src/TagNames.c src/TagPool.cxx \ src/Page.cxx \ diff --git a/src/AudioCompress/compress.h b/src/AudioCompress/compress.h index 073d4af9..8556d16b 100644 --- a/src/AudioCompress/compress.h +++ b/src/AudioCompress/compress.h @@ -19,6 +19,10 @@ struct CompressorConfig { struct Compressor; +#ifdef __cplusplus +extern "C" { +#endif + //! Create a new compressor (use history value of 0 for default) struct Compressor *Compressor_new(unsigned int history); @@ -34,7 +38,12 @@ struct CompressorConfig *Compressor_getConfig(struct Compressor *); //! Process 16-bit signed data void Compressor_Process_int16(struct Compressor *, int16_t *data, unsigned int count); +#ifdef __cplusplus +} +#endif + //! TODO: Compressor_Process_int32, Compressor_Process_float, others as needed //! TODO: functions for getting at the peak/gain/clip history buffers (for monitoring) + #endif diff --git a/src/AudioConfig.cxx b/src/AudioConfig.cxx new file mode 100644 index 00000000..e546aed2 --- /dev/null +++ b/src/AudioConfig.cxx @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "AudioConfig.hxx" +#include "audio_format.h" +#include "AudioParser.hxx" +#include "conf.h" +#include "mpd_error.h" + +static struct audio_format configured_audio_format; + +void getOutputAudioFormat(const struct audio_format *inAudioFormat, + struct audio_format *outAudioFormat) +{ + *outAudioFormat = *inAudioFormat; + audio_format_mask_apply(outAudioFormat, &configured_audio_format); +} + +void initAudioConfig(void) +{ + const struct config_param *param = config_get_param(CONF_AUDIO_OUTPUT_FORMAT); + GError *error = NULL; + bool ret; + + if (param == NULL) + return; + + ret = audio_format_parse(&configured_audio_format, param->value, + true, &error); + if (!ret) + MPD_ERROR("error parsing line %i: %s", + param->line, error->message); +} diff --git a/src/AudioConfig.hxx b/src/AudioConfig.hxx new file mode 100644 index 00000000..717a8e2e --- /dev/null +++ b/src/AudioConfig.hxx @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_AUDIO_CONFIG_HXX +#define MPD_AUDIO_CONFIG_HXX + +struct audio_format; + +void getOutputAudioFormat(const struct audio_format *inFormat, + struct audio_format *outFormat); + +/* make sure initPlayerData is called before this function!! */ +void initAudioConfig(void); + +#endif diff --git a/src/AudioParser.cxx b/src/AudioParser.cxx new file mode 100644 index 00000000..9178c3e1 --- /dev/null +++ b/src/AudioParser.cxx @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2003-2011 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * Parser functions for audio related objects. + * + */ + +#include "config.h" +#include "AudioParser.hxx" +#include "audio_format.h" +#include "audio_check.h" +#include "gcc.h" + +#include +#include +#include + +/** + * The GLib quark used for errors reported by this library. + */ +static inline GQuark +audio_parser_quark(void) +{ + return g_quark_from_static_string("audio_parser"); +} + +static bool +parse_sample_rate(const char *src, bool mask, uint32_t *sample_rate_r, + const char **endptr_r, GError **error_r) +{ + unsigned long value; + char *endptr; + + if (mask && *src == '*') { + *sample_rate_r = 0; + *endptr_r = src + 1; + return true; + } + + value = strtoul(src, &endptr, 10); + if (endptr == src) { + g_set_error(error_r, audio_parser_quark(), 0, + "Failed to parse the sample rate"); + return false; + } else if (!audio_check_sample_rate(value, error_r)) + return false; + + *sample_rate_r = value; + *endptr_r = endptr; + return true; +} + +static bool +parse_sample_format(const char *src, bool mask, + enum sample_format *sample_format_r, + const char **endptr_r, GError **error_r) +{ + unsigned long value; + char *endptr; + enum sample_format sample_format; + + if (mask && *src == '*') { + *sample_format_r = SAMPLE_FORMAT_UNDEFINED; + *endptr_r = src + 1; + return true; + } + + if (*src == 'f') { + *sample_format_r = SAMPLE_FORMAT_FLOAT; + *endptr_r = src + 1; + return true; + } + + if (memcmp(src, "dsd", 3) == 0) { + *sample_format_r = SAMPLE_FORMAT_DSD; + *endptr_r = src + 3; + return true; + } + + value = strtoul(src, &endptr, 10); + if (endptr == src) { + g_set_error(error_r, audio_parser_quark(), 0, + "Failed to parse the sample format"); + return false; + } + + switch (value) { + case 8: + sample_format = SAMPLE_FORMAT_S8; + break; + + case 16: + sample_format = SAMPLE_FORMAT_S16; + break; + + case 24: + if (memcmp(endptr, "_3", 2) == 0) + /* for backwards compatibility */ + endptr += 2; + + sample_format = SAMPLE_FORMAT_S24_P32; + break; + + case 32: + sample_format = SAMPLE_FORMAT_S32; + break; + + default: + g_set_error(error_r, audio_parser_quark(), 0, + "Invalid sample format: %lu", value); + return false; + } + + assert(audio_valid_sample_format(sample_format)); + + *sample_format_r = sample_format; + *endptr_r = endptr; + return true; +} + +static bool +parse_channel_count(const char *src, bool mask, uint8_t *channels_r, + const char **endptr_r, GError **error_r) +{ + unsigned long value; + char *endptr; + + if (mask && *src == '*') { + *channels_r = 0; + *endptr_r = src + 1; + return true; + } + + value = strtoul(src, &endptr, 10); + if (endptr == src) { + g_set_error(error_r, audio_parser_quark(), 0, + "Failed to parse the channel count"); + return false; + } else if (!audio_check_channel_count(value, error_r)) + return false; + + *channels_r = value; + *endptr_r = endptr; + return true; +} + +bool +audio_format_parse(struct audio_format *dest, const char *src, + bool mask, GError **error_r) +{ + uint32_t rate; + enum sample_format sample_format; + uint8_t channels; + + audio_format_clear(dest); + + /* parse sample rate */ + +#if GCC_CHECK_VERSION(4,7) + /* workaround -Wmaybe-uninitialized false positive */ + rate = 0; +#endif + + if (!parse_sample_rate(src, mask, &rate, &src, error_r)) + return false; + + if (*src++ != ':') { + g_set_error(error_r, audio_parser_quark(), 0, + "Sample format missing"); + return false; + } + + /* parse sample format */ + +#if GCC_CHECK_VERSION(4,7) + /* workaround -Wmaybe-uninitialized false positive */ + sample_format = SAMPLE_FORMAT_UNDEFINED; +#endif + + if (!parse_sample_format(src, mask, &sample_format, &src, error_r)) + return false; + + if (*src++ != ':') { + g_set_error(error_r, audio_parser_quark(), 0, + "Channel count missing"); + return false; + } + + /* parse channel count */ + + if (!parse_channel_count(src, mask, &channels, &src, error_r)) + return false; + + if (*src != 0) { + g_set_error(error_r, audio_parser_quark(), 0, + "Extra data after channel count: %s", src); + return false; + } + + audio_format_init(dest, rate, sample_format, channels); + assert(mask ? audio_format_mask_valid(dest) + : audio_format_valid(dest)); + + return true; +} diff --git a/src/AudioParser.hxx b/src/AudioParser.hxx new file mode 100644 index 00000000..f7855e8e --- /dev/null +++ b/src/AudioParser.hxx @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** \file + * + * Parser functions for audio related objects. + */ + +#ifndef MPD_AUDIO_PARSER_HXX +#define MPD_AUDIO_PARSER_HXX + +#include "gerror.h" + +struct audio_format; + +/** + * Parses a string in the form "SAMPLE_RATE:BITS:CHANNELS" into an + * #audio_format. + * + * @param dest the destination #audio_format struct + * @param src the input string + * @param mask if true, then "*" is allowed for any number of items + * @param error_r location to store the error occurring, or NULL to + * ignore errors + * @return true on success + */ +bool +audio_format_parse(struct audio_format *dest, const char *src, + bool mask, GError **error_r); + +#endif diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx index 29b39688..b68af19b 100644 --- a/src/DecoderAPI.cxx +++ b/src/DecoderAPI.cxx @@ -19,11 +19,7 @@ #include "config.h" #include "decoder_api.h" - -extern "C" { -#include "audio_config.h" -} - +#include "AudioConfig.hxx" #include "replay_gain_config.h" #include "MusicChunk.hxx" #include "MusicBuffer.hxx" diff --git a/src/Main.cxx b/src/Main.cxx index a22ee631..63a78d0e 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -51,11 +51,11 @@ #include "PlaylistRegistry.hxx" #include "ZeroconfGlue.hxx" #include "DecoderList.hxx" +#include "AudioConfig.hxx" extern "C" { #include "daemon.h" #include "stats.h" -#include "audio_config.h" #include "pcm_resample.h" } diff --git a/src/OutputInit.cxx b/src/OutputInit.cxx index dfb246a0..0d3dd05a 100644 --- a/src/OutputInit.cxx +++ b/src/OutputInit.cxx @@ -22,10 +22,10 @@ #include "OutputList.hxx" #include "FilterConfig.hxx" #include "output_api.h" +#include "AudioParser.hxx" extern "C" { #include "output_internal.h" -#include "audio_parser.h" #include "mixer_control.h" #include "mixer_type.h" #include "mixer_list.h" diff --git a/src/audio_check.h b/src/audio_check.h index e2302126..d4d3f13f 100644 --- a/src/audio_check.h +++ b/src/audio_check.h @@ -35,6 +35,10 @@ audio_format_quark(void) return g_quark_from_static_string("audio_format"); } +#ifdef __cplusplus +extern "C" { +#endif + bool audio_check_sample_rate(unsigned long sample_rate, GError **error_r); @@ -52,4 +56,8 @@ audio_format_init_checked(struct audio_format *af, unsigned long sample_rate, enum sample_format sample_format, unsigned channels, GError **error_r); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/audio_config.c b/src/audio_config.c deleted file mode 100644 index bae3c184..00000000 --- a/src/audio_config.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" -#include "audio_config.h" -#include "audio_format.h" -#include "audio_parser.h" -#include "conf.h" -#include "mpd_error.h" - -#include - -static struct audio_format configured_audio_format; - -void getOutputAudioFormat(const struct audio_format *inAudioFormat, - struct audio_format *outAudioFormat) -{ - *outAudioFormat = *inAudioFormat; - audio_format_mask_apply(outAudioFormat, &configured_audio_format); -} - -void initAudioConfig(void) -{ - const struct config_param *param = config_get_param(CONF_AUDIO_OUTPUT_FORMAT); - GError *error = NULL; - bool ret; - - if (param == NULL) - return; - - ret = audio_format_parse(&configured_audio_format, param->value, - true, &error); - if (!ret) - MPD_ERROR("error parsing line %i: %s", - param->line, error->message); -} diff --git a/src/audio_config.h b/src/audio_config.h deleted file mode 100644 index fe43dbbc..00000000 --- a/src/audio_config.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_AUDIO_CONFIG_H -#define MPD_AUDIO_CONFIG_H - -struct audio_format; - -void getOutputAudioFormat(const struct audio_format *inFormat, - struct audio_format *outFormat); - -/* make sure initPlayerData is called before this function!! */ -void initAudioConfig(void); - -#endif diff --git a/src/audio_parser.c b/src/audio_parser.c deleted file mode 100644 index 152eab5d..00000000 --- a/src/audio_parser.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/* - * Parser functions for audio related objects. - * - */ - -#include "config.h" -#include "audio_parser.h" -#include "audio_format.h" -#include "audio_check.h" -#include "gcc.h" - -#include -#include -#include - -/** - * The GLib quark used for errors reported by this library. - */ -static inline GQuark -audio_parser_quark(void) -{ - return g_quark_from_static_string("audio_parser"); -} - -static bool -parse_sample_rate(const char *src, bool mask, uint32_t *sample_rate_r, - const char **endptr_r, GError **error_r) -{ - unsigned long value; - char *endptr; - - if (mask && *src == '*') { - *sample_rate_r = 0; - *endptr_r = src + 1; - return true; - } - - value = strtoul(src, &endptr, 10); - if (endptr == src) { - g_set_error(error_r, audio_parser_quark(), 0, - "Failed to parse the sample rate"); - return false; - } else if (!audio_check_sample_rate(value, error_r)) - return false; - - *sample_rate_r = value; - *endptr_r = endptr; - return true; -} - -static bool -parse_sample_format(const char *src, bool mask, - enum sample_format *sample_format_r, - const char **endptr_r, GError **error_r) -{ - unsigned long value; - char *endptr; - enum sample_format sample_format; - - if (mask && *src == '*') { - *sample_format_r = SAMPLE_FORMAT_UNDEFINED; - *endptr_r = src + 1; - return true; - } - - if (*src == 'f') { - *sample_format_r = SAMPLE_FORMAT_FLOAT; - *endptr_r = src + 1; - return true; - } - - if (memcmp(src, "dsd", 3) == 0) { - *sample_format_r = SAMPLE_FORMAT_DSD; - *endptr_r = src + 3; - return true; - } - - value = strtoul(src, &endptr, 10); - if (endptr == src) { - g_set_error(error_r, audio_parser_quark(), 0, - "Failed to parse the sample format"); - return false; - } - - switch (value) { - case 8: - sample_format = SAMPLE_FORMAT_S8; - break; - - case 16: - sample_format = SAMPLE_FORMAT_S16; - break; - - case 24: - if (memcmp(endptr, "_3", 2) == 0) - /* for backwards compatibility */ - endptr += 2; - - sample_format = SAMPLE_FORMAT_S24_P32; - break; - - case 32: - sample_format = SAMPLE_FORMAT_S32; - break; - - default: - g_set_error(error_r, audio_parser_quark(), 0, - "Invalid sample format: %lu", value); - return false; - } - - assert(audio_valid_sample_format(sample_format)); - - *sample_format_r = sample_format; - *endptr_r = endptr; - return true; -} - -static bool -parse_channel_count(const char *src, bool mask, uint8_t *channels_r, - const char **endptr_r, GError **error_r) -{ - unsigned long value; - char *endptr; - - if (mask && *src == '*') { - *channels_r = 0; - *endptr_r = src + 1; - return true; - } - - value = strtoul(src, &endptr, 10); - if (endptr == src) { - g_set_error(error_r, audio_parser_quark(), 0, - "Failed to parse the channel count"); - return false; - } else if (!audio_check_channel_count(value, error_r)) - return false; - - *channels_r = value; - *endptr_r = endptr; - return true; -} - -bool -audio_format_parse(struct audio_format *dest, const char *src, - bool mask, GError **error_r) -{ - uint32_t rate; - enum sample_format sample_format; - uint8_t channels; - - audio_format_clear(dest); - - /* parse sample rate */ - -#if GCC_CHECK_VERSION(4,7) - /* workaround -Wmaybe-uninitialized false positive */ - rate = 0; -#endif - - if (!parse_sample_rate(src, mask, &rate, &src, error_r)) - return false; - - if (*src++ != ':') { - g_set_error(error_r, audio_parser_quark(), 0, - "Sample format missing"); - return false; - } - - /* parse sample format */ - -#if GCC_CHECK_VERSION(4,7) - /* workaround -Wmaybe-uninitialized false positive */ - sample_format = SAMPLE_FORMAT_UNDEFINED; -#endif - - if (!parse_sample_format(src, mask, &sample_format, &src, error_r)) - return false; - - if (*src++ != ':') { - g_set_error(error_r, audio_parser_quark(), 0, - "Channel count missing"); - return false; - } - - /* parse channel count */ - - if (!parse_channel_count(src, mask, &channels, &src, error_r)) - return false; - - if (*src != 0) { - g_set_error(error_r, audio_parser_quark(), 0, - "Extra data after channel count: %s", src); - return false; - } - - audio_format_init(dest, rate, sample_format, channels); - assert(mask ? audio_format_mask_valid(dest) - : audio_format_valid(dest)); - - return true; -} diff --git a/src/audio_parser.h b/src/audio_parser.h deleted file mode 100644 index bbe868f6..00000000 --- a/src/audio_parser.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** \file - * - * Parser functions for audio related objects. - */ - -#ifndef AUDIO_PARSER_H -#define AUDIO_PARSER_H - -#include "gerror.h" - -#include - -struct audio_format; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Parses a string in the form "SAMPLE_RATE:BITS:CHANNELS" into an - * #audio_format. - * - * @param dest the destination #audio_format struct - * @param src the input string - * @param mask if true, then "*" is allowed for any number of items - * @param error_r location to store the error occurring, or NULL to - * ignore errors - * @return true on success - */ -bool -audio_format_parse(struct audio_format *dest, const char *src, - bool mask, GError **error_r); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/test/run_convert.cxx b/test/run_convert.cxx index a71ebc2c..1e54f2d3 100644 --- a/test/run_convert.cxx +++ b/test/run_convert.cxx @@ -24,7 +24,7 @@ */ #include "config.h" -#include "audio_parser.h" +#include "AudioParser.hxx" #include "audio_format.h" #include "pcm_convert.h" #include "conf.h" diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx index 6a141296..3d500d0b 100644 --- a/test/run_encoder.cxx +++ b/test/run_encoder.cxx @@ -21,7 +21,7 @@ #include "encoder_list.h" #include "encoder_plugin.h" #include "audio_format.h" -#include "audio_parser.h" +#include "AudioParser.hxx" #include "conf.h" #include "stdbin.h" diff --git a/test/run_filter.cxx b/test/run_filter.cxx index dbf6caa9..87672adc 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -20,11 +20,7 @@ #include "config.h" #include "conf.h" #include "fs/Path.hxx" - -extern "C" { -#include "audio_parser.h" -} - +#include "AudioParser.hxx" #include "audio_format.h" #include "filter_plugin.h" #include "pcm_volume.h" diff --git a/test/run_normalize.c b/test/run_normalize.c deleted file mode 100644 index fc26829e..00000000 --- a/test/run_normalize.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/* - * This program is a command line interface to MPD's normalize library - * (based on AudioCompress). - * - */ - -#include "config.h" -#include "AudioCompress/compress.h" -#include "audio_parser.h" -#include "audio_format.h" -#include "stdbin.h" - -#include - -#include -#include -#include - -int main(int argc, char **argv) -{ - GError *error = NULL; - struct audio_format audio_format; - bool ret; - struct Compressor *compressor; - static char buffer[4096]; - ssize_t nbytes; - - if (argc > 2) { - g_printerr("Usage: run_normalize [FORMAT] OUT\n"); - return 1; - } - - if (argc > 1) { - ret = audio_format_parse(&audio_format, argv[1], - false, &error); - if (!ret) { - g_printerr("Failed to parse audio format: %s\n", - error->message); - return 1; - } - } else - audio_format_init(&audio_format, 48000, 16, 2); - - compressor = Compressor_new(0); - - while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { - Compressor_Process_int16(compressor, - (int16_t *)buffer, nbytes / 2); - - G_GNUC_UNUSED ssize_t ignored = write(1, buffer, nbytes); - } - - Compressor_delete(compressor); -} diff --git a/test/run_normalize.cxx b/test/run_normalize.cxx new file mode 100644 index 00000000..070dbaf5 --- /dev/null +++ b/test/run_normalize.cxx @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2003-2011 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * This program is a command line interface to MPD's normalize library + * (based on AudioCompress). + * + */ + +#include "config.h" +#include "AudioCompress/compress.h" +#include "AudioParser.hxx" +#include "audio_format.h" +#include "stdbin.h" + +#include + +#include +#include +#include + +int main(int argc, char **argv) +{ + GError *error = NULL; + struct audio_format audio_format; + bool ret; + struct Compressor *compressor; + static char buffer[4096]; + ssize_t nbytes; + + if (argc > 2) { + g_printerr("Usage: run_normalize [FORMAT] OUT\n"); + return 1; + } + + if (argc > 1) { + ret = audio_format_parse(&audio_format, argv[1], + false, &error); + if (!ret) { + g_printerr("Failed to parse audio format: %s\n", + error->message); + return 1; + } + } else + audio_format_init(&audio_format, 48000, SAMPLE_FORMAT_S16, 2); + + compressor = Compressor_new(0); + + while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { + Compressor_Process_int16(compressor, + (int16_t *)buffer, nbytes / 2); + + G_GNUC_UNUSED ssize_t ignored = write(1, buffer, nbytes); + } + + Compressor_delete(compressor); +} diff --git a/test/run_output.cxx b/test/run_output.cxx index ec94beaa..e9daf3c1 100644 --- a/test/run_output.cxx +++ b/test/run_output.cxx @@ -26,11 +26,11 @@ #include "GlobalEvents.hxx" #include "IOThread.hxx" #include "fs/Path.hxx" +#include "AudioParser.hxx" extern "C" { #include "output_plugin.h" #include "output_internal.h" -#include "audio_parser.h" #include "filter_registry.h" #include "pcm_convert.h" } diff --git a/test/software_volume.cxx b/test/software_volume.cxx index 18068665..2579a4f0 100644 --- a/test/software_volume.cxx +++ b/test/software_volume.cxx @@ -25,7 +25,7 @@ #include "config.h" #include "pcm_volume.h" -#include "audio_parser.h" +#include "AudioParser.hxx" #include "audio_format.h" #include "stdbin.h" -- cgit v1.2.3