aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputPlugins
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/inputPlugins/_flac_common.c131
-rw-r--r--src/inputPlugins/_flac_common.h13
-rw-r--r--src/inputPlugins/aac_plugin.c4
-rw-r--r--src/inputPlugins/audiofile_plugin.c8
-rw-r--r--src/inputPlugins/flac_plugin.c74
-rw-r--r--src/inputPlugins/mp3_plugin.c10
-rw-r--r--src/inputPlugins/mp4_plugin.c2
-rw-r--r--src/inputPlugins/mpc_plugin.c10
-rw-r--r--src/inputPlugins/oggflac_plugin.c45
-rw-r--r--src/inputPlugins/wavpack_plugin.c6
10 files changed, 152 insertions, 151 deletions
diff --git a/src/inputPlugins/_flac_common.c b/src/inputPlugins/_flac_common.c
index 9950f75db..546f5c192 100644
--- a/src/inputPlugins/_flac_common.c
+++ b/src/inputPlugins/_flac_common.c
@@ -32,7 +32,6 @@
void init_FlacData(FlacData * data, InputStream * inStream)
{
- data->chunk_length = 0;
data->time = 0;
data->position = 0;
data->bitRate = 0;
@@ -160,9 +159,9 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
switch (block->type) {
case FLAC__METADATA_TYPE_STREAMINFO:
- dc.audio_format.bits = (mpd_sint8)si->bits_per_sample;
+ dc.audio_format.bits = (int8_t)si->bits_per_sample;
dc.audio_format.sampleRate = si->sample_rate;
- dc.audio_format.channels = (mpd_sint8)si->channels;
+ dc.audio_format.channels = (int8_t)si->channels;
dc.total_time = ((float)si->total_samples) / (si->sample_rate);
break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
@@ -194,4 +193,130 @@ void flac_error_common_cb(const char *plugin,
}
}
+static void flac_convert_stereo16(int16_t *dest,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ for (; position < end; ++position) {
+ *dest++ = buf[0][position];
+ *dest++ = buf[1][position];
+ }
+}
+
+static void
+flac_convert_16(int16_t *dest,
+ unsigned int num_channels,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ unsigned int c_chan;
+
+ for (; position < end; ++position)
+ for (c_chan = 0; c_chan < num_channels; c_chan++)
+ *dest++ = buf[c_chan][position];
+}
+
+/**
+ * Note: this function also handles 24 bit files!
+ */
+static void
+flac_convert_32(int32_t *dest,
+ unsigned int num_channels,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ unsigned int c_chan;
+
+ for (; position < end; ++position)
+ for (c_chan = 0; c_chan < num_channels; c_chan++)
+ *dest++ = buf[c_chan][position];
+}
+
+static void
+flac_convert_8(int8_t *dest,
+ unsigned int num_channels,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ unsigned int c_chan;
+
+ for (; position < end; ++position)
+ for (c_chan = 0; c_chan < num_channels; c_chan++)
+ *dest++ = buf[c_chan][position];
+}
+
+static void flac_convert(unsigned char *dest,
+ unsigned int num_channels,
+ unsigned int bytes_per_sample,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ switch (bytes_per_sample) {
+ case 2:
+ if (num_channels == 2)
+ flac_convert_stereo16((int16_t*)dest, buf,
+ position, end);
+ else
+ flac_convert_16((int16_t*)dest, num_channels, buf,
+ position, end);
+ break;
+
+ case 4:
+ flac_convert_32((int32_t*)dest, num_channels, buf,
+ position, end);
+ break;
+
+ case 1:
+ flac_convert_8((int8_t*)dest, num_channels, buf,
+ position, end);
+ break;
+ }
+}
+
+FLAC__StreamDecoderWriteStatus
+flac_common_write(FlacData *data, const FLAC__Frame * frame,
+ const FLAC__int32 *const buf[])
+{
+ unsigned int c_samp;
+ const unsigned int num_channels = frame->header.channels;
+ const unsigned int bytes_per_sample = (dc.audio_format.bits / 8);
+ const unsigned int bytes_per_channel =
+ bytes_per_sample * frame->header.channels;
+ const unsigned int max_samples = FLAC_CHUNK_SIZE / bytes_per_channel;
+ unsigned int num_samples;
+ enum dc_action action;
+
+ assert(dc.audio_format.bits > 0);
+
+ if (bytes_per_sample != 1 && bytes_per_sample != 2 &&
+ bytes_per_sample != 4)
+ /* exotic unsupported bit rate */
+ return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+
+ for (c_samp = 0; c_samp < frame->header.blocksize;
+ c_samp += num_samples) {
+ num_samples = frame->header.blocksize - c_samp;
+ if (num_samples > max_samples)
+ num_samples = max_samples;
+
+ flac_convert(data->chunk,
+ num_channels, bytes_per_sample, buf,
+ c_samp, c_samp + num_samples);
+
+ action = ob_send(data->chunk,
+ num_samples * bytes_per_channel,
+ data->time, data->bitRate,
+ data->replayGainInfo);
+ switch (action) {
+ case DC_ACTION_STOP:
+ return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+ case DC_ACTION_SEEK:
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ default: break; /* compilers are complainers */
+ }
+ }
+
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+}
+
#endif /* HAVE_FLAC || HAVE_OGGFLAC */
diff --git a/src/inputPlugins/_flac_common.h b/src/inputPlugins/_flac_common.h
index a1b0cac8f..f88866b08 100644
--- a/src/inputPlugins/_flac_common.h
+++ b/src/inputPlugins/_flac_common.h
@@ -140,7 +140,6 @@ typedef size_t flac_read_status_size_t;
typedef struct {
unsigned char chunk[FLAC_CHUNK_SIZE];
- size_t chunk_length;
float time;
unsigned int bitRate;
FLAC__uint64 position;
@@ -160,15 +159,9 @@ void flac_error_common_cb(const char *plugin,
struct mpd_tag *copyVorbisCommentBlockToMpdTag(const FLAC__StreamMetadata * block,
struct mpd_tag *tag);
-/* keep this inlined, this is just macro but prettier :) */
-static inline enum dc_action flacSendChunk(FlacData * data)
-{
- enum dc_action ret = ob_send(data->chunk, data->chunk_length,
- data->time, data->bitRate,
- data->replayGainInfo);
- data->chunk_length = 0;
- return ret;
-}
+FLAC__StreamDecoderWriteStatus
+flac_common_write(FlacData *data, const FLAC__Frame * frame,
+ const FLAC__int32 *const buf[]);
#endif /* HAVE_FLAC || HAVE_OGGFLAC */
diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c
index dc97c1e08..2e5df8f48 100644
--- a/src/inputPlugins/aac_plugin.c
+++ b/src/inputPlugins/aac_plugin.c
@@ -313,7 +313,7 @@ static int aac_stream_decode(InputStream *inStream)
unsigned int sampleCount;
char *sampleBuffer;
size_t sampleBufferLen;
- mpd_uint16 bitRate = 0;
+ uint16_t bitRate = 0;
AacBuffer b;
initAacBuffer(inStream, &b);
@@ -442,7 +442,7 @@ static int aac_decode(char *path)
/*float * seekTable;
long seekTableEnd = -1;
int seekPositionFound = 0; */
- mpd_uint16 bitRate = 0;
+ uint16_t bitRate = 0;
AacBuffer b;
InputStream inStream;
diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c
index 6fcc98239..858b71229 100644
--- a/src/inputPlugins/audiofile_plugin.c
+++ b/src/inputPlugins/audiofile_plugin.c
@@ -45,7 +45,7 @@ static int audiofile_decode(char *path)
int fs, frame_count;
AFfilehandle af_fp;
int bits;
- mpd_uint16 bitRate;
+ uint16_t bitRate;
struct stat st;
int ret, current = 0;
char chunk[CHUNK_SIZE];
@@ -64,18 +64,18 @@ static int audiofile_decode(char *path)
afSetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK,
AF_SAMPFMT_TWOSCOMP, 16);
afGetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits);
- dc.audio_format.bits = (mpd_uint8)bits;
+ dc.audio_format.bits = (uint8_t)bits;
dc.audio_format.sampleRate =
(unsigned int)afGetRate(af_fp, AF_DEFAULT_TRACK);
dc.audio_format.channels =
- (mpd_uint8)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
+ (uint8_t)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK);
dc.total_time = ((float)frame_count /
(float)dc.audio_format.sampleRate);
- bitRate = (mpd_uint16)(st.st_size * 8.0 / dc.total_time / 1000.0 + 0.5);
+ bitRate = (uint16_t)(st.st_size * 8.0 / dc.total_time / 1000.0 + 0.5);
if (dc.audio_format.bits != 8 && dc.audio_format.bits != 16) {
ERROR("Only 8 and 16-bit files are supported. %s is %i-bit\n",
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index 89e988a03..228301291 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -199,39 +199,6 @@ static void flacMetadata(mpd_unused const flac_decoder * dec,
flac_metadata_common_cb(block, (FlacData *) vdata);
}
-static void flac_convert_stereo16(unsigned char *dest,
- const FLAC__int32 * const buf[],
- unsigned int position, unsigned int end)
-{
- for (; position < end; ++position) {
- *(uint16_t*)dest = buf[0][position];
- dest += 2;
- *(uint16_t*)dest = buf[1][position];
- dest += 2;
- }
-}
-
-static void flac_convert(unsigned char *dest,
- unsigned int num_channels,
- unsigned int bytes_per_sample,
- const FLAC__int32 * const buf[],
- unsigned int position, unsigned int end)
-{
- unsigned int c_chan, i;
- FLAC__uint16 u16;
- unsigned char *uc;
-
- for (; position < end; ++position) {
- for (c_chan = 0; c_chan < num_channels; c_chan++) {
- u16 = buf[c_chan][position];
- uc = (unsigned char *)&u16;
- for (i = 0; i < bytes_per_sample; i++) {
- *dest++ = *uc++;
- }
- }
- }
-}
-
static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
const FLAC__Frame * frame,
const FLAC__int32 * const buf[],
@@ -239,18 +206,9 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
{
FlacData *data = (FlacData *) vdata;
FLAC__uint32 samples = frame->header.blocksize;
- unsigned int c_samp;
- const unsigned int num_channels = frame->header.channels;
- const unsigned int bytes_per_sample = (dc.audio_format.bits / 8);
- const unsigned int bytes_per_channel =
- bytes_per_sample * frame->header.channels;
- const unsigned int max_samples = FLAC_CHUNK_SIZE / bytes_per_channel;
- unsigned int num_samples;
float timeChange;
FLAC__uint64 newPosition = 0;
- assert(dc.audio_format.bits > 0);
-
timeChange = ((float)samples) / frame->header.sample_rate;
data->time += timeChange;
@@ -264,32 +222,7 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
}
data->position = newPosition;
- for (c_samp = 0; c_samp < frame->header.blocksize;
- c_samp += num_samples) {
- num_samples = frame->header.blocksize - c_samp;
- if (num_samples > max_samples)
- num_samples = max_samples;
-
- if (num_channels == 2 && bytes_per_sample == 2)
- flac_convert_stereo16(data->chunk + data->chunk_length,
- buf, c_samp,
- c_samp + num_samples);
- else
- flac_convert(data->chunk + data->chunk_length,
- num_channels, bytes_per_sample, buf,
- c_samp, c_samp + num_samples);
- data->chunk_length = num_samples * bytes_per_channel;
-
- switch (flacSendChunk(data)) {
- case DC_ACTION_STOP:
- return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
- case DC_ACTION_SEEK:
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
- default: break; /* compilers are complainers */
- }
- }
-
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ return flac_common_write(data, frame, buf);
}
static struct mpd_tag *flacMetadataDup(char *file, int *vorbisCommentFound)
@@ -426,7 +359,6 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg)
data.time = ((float)sampleToSeek) /
dc.audio_format.sampleRate;
data.position = 0;
- data.chunk_length = 0;
} else {
dc.seek_where = DC_SEEK_ERROR;
}
@@ -437,10 +369,6 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg)
flacPrintErroredState(flac_get_state(flacDec));
flac_finish(flacDec);
}
- /* send last little bit */
- if (data.chunk_length > 0 && !dc_intr())
- flacSendChunk(&data);
-
fail:
if (data.replayGainInfo)
freeReplayGainInfo(data.replayGainInfo);
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index 1d6333fd6..0d664b020 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -65,7 +65,7 @@ static unsigned long prng(unsigned long state)
return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
}
-static mpd_sint16 audio_linear_dither(unsigned int bits, mad_fixed_t sample,
+static int16_t audio_linear_dither(unsigned int bits, mad_fixed_t sample,
struct audio_dither *dither)
{
unsigned int scalebits;
@@ -107,15 +107,15 @@ static mpd_sint16 audio_linear_dither(unsigned int bits, mad_fixed_t sample,
dither->error[0] = sample - output;
- return (mpd_sint16)(output >> scalebits);
+ return (int16_t)(output >> scalebits);
}
-static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth,
+static unsigned dither_buffer(int16_t *dest0, const struct mad_synth *synth,
struct audio_dither *dither,
unsigned int start, unsigned int end,
unsigned int num_channels)
{
- mpd_sint16 *dest = dest0;
+ int16_t *dest = dest0;
unsigned int i;
for (i = start; i < end; ++i) {
@@ -153,7 +153,7 @@ typedef struct _mp3DecodeData {
struct mad_synth synth;
mad_timer_t timer;
unsigned char readBuffer[READ_BUFFER_SIZE];
- mpd_sint16 outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE];
+ int16_t outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE];
float totalTime;
float elapsedTime;
enum muteframe muteFrame;
diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c
index 1e65f6667..0763c6c12 100644
--- a/src/inputPlugins/mp4_plugin.c
+++ b/src/inputPlugins/mp4_plugin.c
@@ -103,7 +103,7 @@ static int mp4_decode(InputStream * inStream)
long seekTableEnd = -1;
int seekPositionFound = 0;
long offset;
- mpd_uint16 bitRate = 0;
+ uint16_t bitRate = 0;
int seeking = 0;
mp4cb = xmalloc(sizeof(mp4ff_callback_t));
diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c
index e5502a2f0..735916cdc 100644
--- a/src/inputPlugins/mpc_plugin.c
+++ b/src/inputPlugins/mpc_plugin.c
@@ -74,10 +74,10 @@ static mpc_int32_t mpc_getsize_cb(void *vdata)
}
/* this _looks_ performance-critical, don't de-inline -- eric */
-static inline mpd_sint16 convertSample(MPC_SAMPLE_FORMAT sample)
+static inline int16_t convertSample(MPC_SAMPLE_FORMAT sample)
{
/* only doing 16-bit audio for now */
- mpd_sint32 val;
+ int32_t val;
const int clip_min = -1 << (16 - 1);
const int clip_max = (1 << (16 - 1)) - 1;
@@ -121,7 +121,7 @@ static int mpc_decode(InputStream * inStream)
char chunk[MPC_CHUNK_SIZE];
int chunkpos = 0;
long bitRate = 0;
- mpd_sint16 *s16 = (mpd_sint16 *) chunk;
+ int16_t *s16 = (int16_t *) chunk;
unsigned long samplePos = 0;
mpc_uint32_t vbrUpdateAcc;
mpc_uint32_t vbrUpdateBits;
@@ -175,7 +175,7 @@ static int mpc_decode(InputStream * inStream)
dc_action_begin();
samplePos = dc.seek_where * dc.audio_format.sampleRate;
if (mpc_decoder_seek_sample(&decoder, samplePos)) {
- s16 = (mpd_sint16 *) chunk;
+ s16 = (int16_t *) chunk;
chunkpos = 0;
} else
dc.seek_where = DC_SEEK_ERROR;
@@ -214,7 +214,7 @@ static int mpc_decode(InputStream * inStream)
bitRate, replayGainInfo);
chunkpos = 0;
- s16 = (mpd_sint16 *) chunk;
+ s16 = (int16_t *) chunk;
if (dc_intr()) {
eof = 1;
break;
diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c
index 841030481..36bd9dced 100644
--- a/src/inputPlugins/oggflac_plugin.c
+++ b/src/inputPlugins/oggflac_plugin.c
@@ -162,51 +162,12 @@ static FLAC__StreamDecoderWriteStatus oggflacWrite(mpd_unused const
{
FlacData *data = (FlacData *) vdata;
FLAC__uint32 samples = frame->header.blocksize;
- FLAC__uint16 u16;
- unsigned char *uc;
- unsigned int c_samp, c_chan;
- int i;
float timeChange;
timeChange = ((float)samples) / frame->header.sample_rate;
data->time += timeChange;
- /* ogg123 uses a complicated method of calculating bitrate
- * with averaging which I'm not too fond of.
- * (waste of memory/CPU cycles, especially given this is _lossless_)
- * a get_decode_position() is not available in OggFLAC, either
- *
- * this does not give an accurate bitrate:
- * (bytes_last_read was set in the read callback)
- data->bitRate = ((8.0 * data->bytes_last_read *
- frame->header.sample_rate)
- /((float)samples * 1000)) + 0.5;
- */
-
- for (c_samp = 0; c_samp < frame->header.blocksize; c_samp++) {
- for (c_chan = 0; c_chan < frame->header.channels;
- c_chan++) {
- u16 = buf[c_chan][c_samp];
- uc = (unsigned char *)&u16;
- for (i = 0; i < (dc.audio_format.bits / 8); i++) {
- if (data->chunk_length >= FLAC_CHUNK_SIZE) {
- /* FIXME: line wrapping */
- switch (flacSendChunk(data)) {
- case DC_ACTION_STOP:
- return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
- case DC_ACTION_SEEK:
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
- default:
- /* compilers are complainers */
- break;
- }
- }
- data->chunk[data->chunk_length++] = *(uc++);
- }
- }
- }
-
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ return flac_common_write(data, frame, buf);
}
/* used by TagDup */
@@ -367,7 +328,6 @@ static int oggflac_decode(InputStream * inStream)
data.time = ((float)sampleToSeek) /
dc.audio_format.sampleRate;
data.position = 0;
- data.chunk_length = 0;
} else {
dc.seek_where = DC_SEEK_ERROR;
}
@@ -380,9 +340,6 @@ static int oggflac_decode(InputStream * inStream)
(OggFLAC__seekable_stream_decoder_get_state(decoder));
OggFLAC__seekable_stream_decoder_finish(decoder);
}
- /* send last little bit */
- if (data.chunk_length > 0 && !dc_intr())
- flacSendChunk(&data);
fail:
oggflac_cleanup(&data, decoder);
diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c
index 8bba8ae2b..b6da51e5e 100644
--- a/src/inputPlugins/wavpack_plugin.c
+++ b/src/inputPlugins/wavpack_plugin.c
@@ -429,10 +429,8 @@ static int wavpack_open_wvc(InputStream *is_wvc)
char wvc_url[MPD_PATH_MAX];
size_t len;
- /* This is the only reader of dc.current_song */
- if (!get_song_url(wvc_url, dc.current_song))
- return 0;
-
+ /* This is the only reader of dc.utf8url (in inputPlugins) */
+ pathcpy_trunc(wvc_url, dc.utf8url);
len = strlen(wvc_url);
if ((len + 2) >= MPD_PATH_MAX)
return 0;