aboutsummaryrefslogtreecommitdiffstats
path: root/src/encoder
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/encoder
parent67f591a9ce60651da41afc499bd9a22e25314e35 (diff)
downloadmpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.tar.gz
mpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.tar.xz
mpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.zip
audio_format: convert to C++
Diffstat (limited to 'src/encoder')
-rw-r--r--src/encoder/FlacEncoderPlugin.cxx31
-rw-r--r--src/encoder/LameEncoderPlugin.cxx14
-rw-r--r--src/encoder/NullEncoderPlugin.cxx2
-rw-r--r--src/encoder/OpusEncoderPlugin.cxx36
-rw-r--r--src/encoder/TwolameEncoderPlugin.cxx14
-rw-r--r--src/encoder/VorbisEncoderPlugin.cxx13
-rw-r--r--src/encoder/WaveEncoderPlugin.cxx22
7 files changed, 67 insertions, 65 deletions
diff --git a/src/encoder/FlacEncoderPlugin.cxx b/src/encoder/FlacEncoderPlugin.cxx
index 3aeb96cf7..5e7e7f526 100644
--- a/src/encoder/FlacEncoderPlugin.cxx
+++ b/src/encoder/FlacEncoderPlugin.cxx
@@ -20,7 +20,7 @@
#include "config.h"
#include "FlacEncoderPlugin.hxx"
#include "EncoderAPI.hxx"
-#include "audio_format.h"
+#include "AudioFormat.hxx"
#include "pcm/PcmBuffer.hxx"
#include "util/fifo_buffer.h"
@@ -40,7 +40,7 @@ extern "C" {
struct flac_encoder {
Encoder encoder;
- struct audio_format audio_format;
+ AudioFormat audio_format;
unsigned compression;
FLAC__StreamEncoder *fse;
@@ -160,31 +160,31 @@ flac_encoder_close(Encoder *_encoder)
}
static bool
-flac_encoder_open(Encoder *_encoder, struct audio_format *audio_format,
+flac_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
GError **error)
{
struct flac_encoder *encoder = (struct flac_encoder *)_encoder;
unsigned bits_per_sample;
- encoder->audio_format = *audio_format;
+ encoder->audio_format = audio_format;
/* FIXME: flac should support 32bit as well */
- switch (audio_format->format) {
- case SAMPLE_FORMAT_S8:
+ switch (audio_format.format) {
+ case SampleFormat::S8:
bits_per_sample = 8;
break;
- case SAMPLE_FORMAT_S16:
+ case SampleFormat::S16:
bits_per_sample = 16;
break;
- case SAMPLE_FORMAT_S24_P32:
+ case SampleFormat::S24_P32:
bits_per_sample = 24;
break;
default:
bits_per_sample = 24;
- audio_format->format = SAMPLE_FORMAT_S24_P32;
+ audio_format.format = SampleFormat::S24_P32;
}
/* allocate the encoder */
@@ -263,30 +263,33 @@ flac_encoder_write(Encoder *_encoder,
/* format conversion */
- num_frames = length / audio_format_frame_size(&encoder->audio_format);
+ num_frames = length / encoder->audio_format.GetFrameSize();
num_samples = num_frames * encoder->audio_format.channels;
switch (encoder->audio_format.format) {
- case SAMPLE_FORMAT_S8:
+ case SampleFormat::S8:
exbuffer = encoder->expand_buffer.Get(length * 4);
pcm8_to_flac((int32_t *)exbuffer, (const int8_t *)data,
num_samples);
buffer = exbuffer;
break;
- case SAMPLE_FORMAT_S16:
+ case SampleFormat::S16:
exbuffer = encoder->expand_buffer.Get(length * 2);
pcm16_to_flac((int32_t *)exbuffer, (const int16_t *)data,
num_samples);
buffer = exbuffer;
break;
- case SAMPLE_FORMAT_S24_P32:
- case SAMPLE_FORMAT_S32:
+ case SampleFormat::S24_P32:
+ case SampleFormat::S32:
/* nothing need to be done; format is the same for
both mpd and libFLAC */
buffer = data;
break;
+
+ default:
+ gcc_unreachable();
}
/* feed samples to encoder */
diff --git a/src/encoder/LameEncoderPlugin.cxx b/src/encoder/LameEncoderPlugin.cxx
index 933fa3ff2..ea0b91380 100644
--- a/src/encoder/LameEncoderPlugin.cxx
+++ b/src/encoder/LameEncoderPlugin.cxx
@@ -20,7 +20,7 @@
#include "config.h"
#include "LameEncoderPlugin.hxx"
#include "EncoderAPI.hxx"
-#include "audio_format.h"
+#include "AudioFormat.hxx"
#include <lame/lame.h>
@@ -32,7 +32,7 @@
struct LameEncoder final {
Encoder encoder;
- struct audio_format audio_format;
+ AudioFormat audio_format;
float quality;
int bitrate;
@@ -187,15 +187,15 @@ lame_encoder_setup(LameEncoder *encoder, GError **error)
}
static bool
-lame_encoder_open(Encoder *_encoder, struct audio_format *audio_format,
+lame_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
GError **error)
{
LameEncoder *encoder = (LameEncoder *)_encoder;
- audio_format->format = SAMPLE_FORMAT_S16;
- audio_format->channels = 2;
+ audio_format.format = SampleFormat::S16;
+ audio_format.channels = 2;
- encoder->audio_format = *audio_format;
+ encoder->audio_format = audio_format;
encoder->gfp = lame_init();
if (encoder->gfp == nullptr) {
@@ -233,7 +233,7 @@ lame_encoder_write(Encoder *_encoder,
assert(encoder->buffer_length == 0);
const unsigned num_frames =
- length / audio_format_frame_size(&encoder->audio_format);
+ length / encoder->audio_format.GetFrameSize();
float *left = g_new(float, num_frames);
float *right = g_new(float, num_frames);
diff --git a/src/encoder/NullEncoderPlugin.cxx b/src/encoder/NullEncoderPlugin.cxx
index 39e391063..206d55c2f 100644
--- a/src/encoder/NullEncoderPlugin.cxx
+++ b/src/encoder/NullEncoderPlugin.cxx
@@ -66,7 +66,7 @@ null_encoder_close(Encoder *_encoder)
static bool
null_encoder_open(Encoder *_encoder,
- gcc_unused struct audio_format *audio_format,
+ gcc_unused AudioFormat &audio_format,
gcc_unused GError **error)
{
NullEncoder *encoder = (NullEncoder *)_encoder;
diff --git a/src/encoder/OpusEncoderPlugin.cxx b/src/encoder/OpusEncoderPlugin.cxx
index a5947e4b8..a6f36f7d5 100644
--- a/src/encoder/OpusEncoderPlugin.cxx
+++ b/src/encoder/OpusEncoderPlugin.cxx
@@ -21,7 +21,7 @@
#include "OpusEncoderPlugin.hxx"
#include "OggStream.hxx"
#include "EncoderAPI.hxx"
-#include "audio_format.h"
+#include "AudioFormat.hxx"
#include "mpd_error.h"
#include <opus.h>
@@ -44,7 +44,7 @@ struct opus_encoder {
/* runtime information */
- struct audio_format audio_format;
+ AudioFormat audio_format;
size_t frame_size;
@@ -144,37 +144,37 @@ opus_encoder_finish(Encoder *_encoder)
static bool
opus_encoder_open(Encoder *_encoder,
- struct audio_format *audio_format,
+ AudioFormat &audio_format,
GError **error_r)
{
struct opus_encoder *encoder = (struct opus_encoder *)_encoder;
/* libopus supports only 48 kHz */
- audio_format->sample_rate = 48000;
+ audio_format.sample_rate = 48000;
- if (audio_format->channels > 2)
- audio_format->channels = 1;
+ if (audio_format.channels > 2)
+ audio_format.channels = 1;
- switch ((enum sample_format)audio_format->format) {
- case SAMPLE_FORMAT_S16:
- case SAMPLE_FORMAT_FLOAT:
+ switch (audio_format.format) {
+ case SampleFormat::S16:
+ case SampleFormat::FLOAT:
break;
- case SAMPLE_FORMAT_S8:
- audio_format->format = SAMPLE_FORMAT_S16;
+ case SampleFormat::S8:
+ audio_format.format = SampleFormat::S16;
break;
default:
- audio_format->format = SAMPLE_FORMAT_FLOAT;
+ audio_format.format = SampleFormat::FLOAT;
break;
}
- encoder->audio_format = *audio_format;
- encoder->frame_size = audio_format_frame_size(audio_format);
+ encoder->audio_format = audio_format;
+ encoder->frame_size = audio_format.GetFrameSize();
int error;
- encoder->enc = opus_encoder_create(audio_format->sample_rate,
- audio_format->channels,
+ encoder->enc = opus_encoder_create(audio_format.sample_rate,
+ audio_format.channels,
OPUS_APPLICATION_AUDIO,
&error);
if (encoder->enc == nullptr) {
@@ -190,7 +190,7 @@ opus_encoder_open(Encoder *_encoder,
opus_encoder_ctl(encoder->enc, OPUS_GET_LOOKAHEAD(&encoder->lookahead));
- encoder->buffer_frames = audio_format->sample_rate / 50;
+ encoder->buffer_frames = audio_format.sample_rate / 50;
encoder->buffer_size = encoder->frame_size * encoder->buffer_frames;
encoder->buffer_position = 0;
encoder->buffer = (unsigned char *)g_malloc(encoder->buffer_size);
@@ -218,7 +218,7 @@ opus_encoder_do_encode(struct opus_encoder *encoder, bool eos,
assert(encoder->buffer_position == encoder->buffer_size);
opus_int32 result =
- encoder->audio_format.format == SAMPLE_FORMAT_S16
+ encoder->audio_format.format == SampleFormat::S16
? opus_encode(encoder->enc,
(const opus_int16 *)encoder->buffer,
encoder->buffer_frames,
diff --git a/src/encoder/TwolameEncoderPlugin.cxx b/src/encoder/TwolameEncoderPlugin.cxx
index c307b7b4f..4e2d47b63 100644
--- a/src/encoder/TwolameEncoderPlugin.cxx
+++ b/src/encoder/TwolameEncoderPlugin.cxx
@@ -20,7 +20,7 @@
#include "config.h"
#include "TwolameEncoderPlugin.hxx"
#include "EncoderAPI.hxx"
-#include "audio_format.h"
+#include "AudioFormat.hxx"
#include <twolame.h>
@@ -32,7 +32,7 @@
struct TwolameEncoder final {
Encoder encoder;
- struct audio_format audio_format;
+ AudioFormat audio_format;
float quality;
int bitrate;
@@ -187,15 +187,15 @@ twolame_encoder_setup(TwolameEncoder *encoder, GError **error)
}
static bool
-twolame_encoder_open(Encoder *_encoder, struct audio_format *audio_format,
+twolame_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
GError **error)
{
TwolameEncoder *encoder = (TwolameEncoder *)_encoder;
- audio_format->format = SAMPLE_FORMAT_S16;
- audio_format->channels = 2;
+ audio_format.format = SampleFormat::S16;
+ audio_format.channels = 2;
- encoder->audio_format = *audio_format;
+ encoder->audio_format = audio_format;
encoder->options = twolame_init();
if (encoder->options == nullptr) {
@@ -243,7 +243,7 @@ twolame_encoder_write(Encoder *_encoder,
assert(encoder->buffer_length == 0);
const unsigned num_frames =
- length / audio_format_frame_size(&encoder->audio_format);
+ length / encoder->audio_format.GetFrameSize();
int bytes_out = twolame_encode_buffer_interleaved(encoder->options,
src, num_frames,
diff --git a/src/encoder/VorbisEncoderPlugin.cxx b/src/encoder/VorbisEncoderPlugin.cxx
index 1fc9bde67..bc43ffa43 100644
--- a/src/encoder/VorbisEncoderPlugin.cxx
+++ b/src/encoder/VorbisEncoderPlugin.cxx
@@ -22,7 +22,7 @@
#include "OggStream.hxx"
#include "EncoderAPI.hxx"
#include "Tag.hxx"
-#include "audio_format.h"
+#include "AudioFormat.hxx"
#include "mpd_error.h"
#include <vorbis/vorbisenc.h>
@@ -43,7 +43,7 @@ struct vorbis_encoder {
/* runtime information */
- struct audio_format audio_format;
+ AudioFormat audio_format;
vorbis_dsp_state vd;
vorbis_block vb;
@@ -202,14 +202,14 @@ vorbis_encoder_send_header(struct vorbis_encoder *encoder)
static bool
vorbis_encoder_open(Encoder *_encoder,
- struct audio_format *audio_format,
+ AudioFormat &audio_format,
GError **error)
{
struct vorbis_encoder *encoder = (struct vorbis_encoder *)_encoder;
- audio_format->format = SAMPLE_FORMAT_FLOAT;
+ audio_format.format = SampleFormat::FLOAT;
- encoder->audio_format = *audio_format;
+ encoder->audio_format = audio_format;
if (!vorbis_encoder_reinit(encoder, error))
return false;
@@ -328,8 +328,7 @@ vorbis_encoder_write(Encoder *_encoder,
{
struct vorbis_encoder *encoder = (struct vorbis_encoder *)_encoder;
- unsigned num_frames = length
- / audio_format_frame_size(&encoder->audio_format);
+ unsigned num_frames = length / encoder->audio_format.GetFrameSize();
/* this is for only 16-bit audio */
diff --git a/src/encoder/WaveEncoderPlugin.cxx b/src/encoder/WaveEncoderPlugin.cxx
index 939012d89..cc94247cb 100644
--- a/src/encoder/WaveEncoderPlugin.cxx
+++ b/src/encoder/WaveEncoderPlugin.cxx
@@ -100,32 +100,32 @@ wave_encoder_finish(Encoder *_encoder)
static bool
wave_encoder_open(Encoder *_encoder,
- gcc_unused struct audio_format *audio_format,
+ AudioFormat &audio_format,
gcc_unused GError **error)
{
WaveEncoder *encoder = (WaveEncoder *)_encoder;
- assert(audio_format_valid(audio_format));
+ assert(audio_format.IsValid());
- switch (audio_format->format) {
- case SAMPLE_FORMAT_S8:
+ switch (audio_format.format) {
+ case SampleFormat::S8:
encoder->bits = 8;
break;
- case SAMPLE_FORMAT_S16:
+ case SampleFormat::S16:
encoder->bits = 16;
break;
- case SAMPLE_FORMAT_S24_P32:
+ case SampleFormat::S24_P32:
encoder->bits = 24;
break;
- case SAMPLE_FORMAT_S32:
+ case SampleFormat::S32:
encoder->bits = 32;
break;
default:
- audio_format->format = SAMPLE_FORMAT_S16;
+ audio_format.format = SampleFormat::S16;
encoder->bits = 16;
break;
}
@@ -136,10 +136,10 @@ wave_encoder_open(Encoder *_encoder,
/* create PCM wave header in initial buffer */
fill_wave_header(header,
- audio_format->channels,
+ audio_format.channels,
encoder->bits,
- audio_format->sample_rate,
- (encoder->bits / 8) * audio_format->channels );
+ audio_format.sample_rate,
+ (encoder->bits / 8) * audio_format.channels);
fifo_buffer_append(encoder->buffer, sizeof(*header));
return true;