Commit 3dd38e7b authored by Max Kellermann's avatar Max Kellermann

decoder/wavpack: convert to C++

parent 3711a976
...@@ -544,7 +544,9 @@ libdecoder_plugins_a_SOURCES += \ ...@@ -544,7 +544,9 @@ libdecoder_plugins_a_SOURCES += \
endif endif
if HAVE_WAVPACK if HAVE_WAVPACK
libdecoder_plugins_a_SOURCES += src/decoder/wavpack_decoder_plugin.c libdecoder_plugins_a_SOURCES += \
src/decoder/WavpackDecoderPlugin.cxx \
src/decoder/WavpackDecoderPlugin.hxx
endif endif
if HAVE_ADPLUG if HAVE_ADPLUG
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,9 +18,13 @@ ...@@ -18,9 +18,13 @@
*/ */
#include "config.h" #include "config.h"
#include "WavpackDecoderPlugin.hxx"
#include "decoder_api.h" #include "decoder_api.h"
extern "C" {
#include "audio_check.h" #include "audio_check.h"
#include "utils.h" }
#include "tag_handler.h" #include "tag_handler.h"
#include "tag_ape.h" #include "tag_ape.h"
...@@ -50,18 +54,18 @@ typedef void (*format_samples_t)( ...@@ -50,18 +54,18 @@ typedef void (*format_samples_t)(
static void static void
format_samples_int(int bytes_per_sample, void *buffer, uint32_t count) format_samples_int(int bytes_per_sample, void *buffer, uint32_t count)
{ {
int32_t *src = buffer; int32_t *src = (int32_t *)buffer;
switch (bytes_per_sample) { switch (bytes_per_sample) {
case 1: { case 1: {
int8_t *dst = buffer; int8_t *dst = (int8_t *)buffer;
/* /*
* The asserts like the following one are because we do the * The asserts like the following one are because we do the
* formatting of samples within a single buffer. The size * formatting of samples within a single buffer. The size
* of the output samples never can be greater than the size * of the output samples never can be greater than the size
* of the input ones. Otherwise we would have an overflow. * of the input ones. Otherwise we would have an overflow.
*/ */
assert_static(sizeof(*dst) <= sizeof(*src)); static_assert(sizeof(*dst) <= sizeof(*src), "Wrong size");
/* pass through and align 8-bit samples */ /* pass through and align 8-bit samples */
while (count--) { while (count--) {
...@@ -70,8 +74,8 @@ format_samples_int(int bytes_per_sample, void *buffer, uint32_t count) ...@@ -70,8 +74,8 @@ format_samples_int(int bytes_per_sample, void *buffer, uint32_t count)
break; break;
} }
case 2: { case 2: {
uint16_t *dst = buffer; uint16_t *dst = (uint16_t *)buffer;
assert_static(sizeof(*dst) <= sizeof(*src)); static_assert(sizeof(*dst) <= sizeof(*src), "Wrong size");
/* pass through and align 16-bit samples */ /* pass through and align 16-bit samples */
while (count--) { while (count--) {
...@@ -94,7 +98,7 @@ static void ...@@ -94,7 +98,7 @@ static void
format_samples_float(G_GNUC_UNUSED int bytes_per_sample, void *buffer, format_samples_float(G_GNUC_UNUSED int bytes_per_sample, void *buffer,
uint32_t count) uint32_t count)
{ {
float *p = buffer; float *p = (float *)buffer;
while (count--) { while (count--) {
*p /= (1 << 23); *p /= (1 << 23);
...@@ -356,7 +360,7 @@ static struct wavpack_input * ...@@ -356,7 +360,7 @@ static struct wavpack_input *
wpin(void *id) wpin(void *id)
{ {
assert(id); assert(id);
return id; return (struct wavpack_input *)id;
} }
static int32_t static int32_t
...@@ -438,14 +442,14 @@ wavpack_input_can_seek(void *id) ...@@ -438,14 +442,14 @@ wavpack_input_can_seek(void *id)
} }
static WavpackStreamReader mpd_is_reader = { static WavpackStreamReader mpd_is_reader = {
.read_bytes = wavpack_input_read_bytes, wavpack_input_read_bytes,
.get_pos = wavpack_input_get_pos, wavpack_input_get_pos,
.set_pos_abs = wavpack_input_set_pos_abs, wavpack_input_set_pos_abs,
.set_pos_rel = wavpack_input_set_pos_rel, wavpack_input_set_pos_rel,
.push_back_byte = wavpack_input_push_back_byte, wavpack_input_push_back_byte,
.get_length = wavpack_input_get_length, wavpack_input_get_length,
.can_seek = wavpack_input_can_seek, wavpack_input_can_seek,
.write_bytes = NULL /* no need to write edited tags */ nullptr /* no need to write edited tags */
}; };
static void static void
...@@ -472,7 +476,7 @@ wavpack_open_wvc(struct decoder *decoder, const char *uri, ...@@ -472,7 +476,7 @@ wavpack_open_wvc(struct decoder *decoder, const char *uri,
* single files. utf8url is not absolute file path :/ * single files. utf8url is not absolute file path :/
*/ */
if (uri == NULL) if (uri == NULL)
return false; return nullptr;
wvc_url = g_strconcat(uri, "c", NULL); wvc_url = g_strconcat(uri, "c", NULL);
is_wvc = input_stream_open(wvc_url, mutex, cond, NULL); is_wvc = input_stream_open(wvc_url, mutex, cond, NULL);
...@@ -584,10 +588,14 @@ static char const *const wavpack_mime_types[] = { ...@@ -584,10 +588,14 @@ static char const *const wavpack_mime_types[] = {
}; };
const struct decoder_plugin wavpack_decoder_plugin = { const struct decoder_plugin wavpack_decoder_plugin = {
.name = "wavpack", "wavpack",
.stream_decode = wavpack_streamdecode, nullptr,
.file_decode = wavpack_filedecode, nullptr,
.scan_file = wavpack_scan_file, wavpack_streamdecode,
.suffixes = wavpack_suffixes, wavpack_filedecode,
.mime_types = wavpack_mime_types wavpack_scan_file,
nullptr,
nullptr,
wavpack_suffixes,
wavpack_mime_types
}; };
/*
* 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_DECODER_WAVPACK_HXX
#define MPD_DECODER_WAVPACK_HXX
extern const struct decoder_plugin wavpack_decoder_plugin;
#endif
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "decoder/OpusDecoderPlugin.h" #include "decoder/OpusDecoderPlugin.h"
#include "decoder/VorbisDecoderPlugin.h" #include "decoder/VorbisDecoderPlugin.h"
#include "decoder/AdPlugDecoderPlugin.h" #include "decoder/AdPlugDecoderPlugin.h"
#include "decoder/WavpackDecoderPlugin.hxx"
#include <glib.h> #include <glib.h>
...@@ -42,7 +43,6 @@ extern const struct decoder_plugin audiofile_decoder_plugin; ...@@ -42,7 +43,6 @@ extern const struct decoder_plugin audiofile_decoder_plugin;
extern const struct decoder_plugin mp4ff_decoder_plugin; extern const struct decoder_plugin mp4ff_decoder_plugin;
extern const struct decoder_plugin faad_decoder_plugin; extern const struct decoder_plugin faad_decoder_plugin;
extern const struct decoder_plugin mpcdec_decoder_plugin; extern const struct decoder_plugin mpcdec_decoder_plugin;
extern const struct decoder_plugin wavpack_decoder_plugin;
extern const struct decoder_plugin modplug_decoder_plugin; extern const struct decoder_plugin modplug_decoder_plugin;
extern const struct decoder_plugin mikmod_decoder_plugin; extern const struct decoder_plugin mikmod_decoder_plugin;
extern const struct decoder_plugin sidplay_decoder_plugin; extern const struct decoder_plugin sidplay_decoder_plugin;
......
...@@ -22,17 +22,6 @@ ...@@ -22,17 +22,6 @@
#include "gerror.h" #include "gerror.h"
#include <stdbool.h>
#ifndef assert_static
/* Compile time assertion developed by Ralf Holly */
/* http://pera-software.com/articles/compile-time-assertions.pdf */
#define assert_static(e) \
do { \
enum { assert_static__ = 1/(e) }; \
} while (0)
#endif /* !assert_static */
char * char *
parsePath(const char *path, GError **error_r); parsePath(const char *path, GError **error_r);
......
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