Skip to content

Commit

Permalink
bits-per-sample fixes (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomty89 authored and flyingmutant committed Feb 19, 2019
1 parent d14b432 commit d93f9c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
15 changes: 13 additions & 2 deletions buffer.h
Expand Up @@ -19,8 +19,19 @@
#ifndef CMUS_BUFFER_H
#define CMUS_BUFFER_H

/* must be a multiple of any supported frame size */
#define CHUNK_SIZE (60 * 1024)
/*
* must be a multiple of any supported frame size
*
* 12 is the LCM of 1, 2, 3 and 4, which corresponds to
* 8, 16, 24 and 32 bits respectively
*
* 840 is the LCM of 1, 2, 3, 4, 5, 6, 7 and 8, which
* are the numbers of supported channels
*
* we used to define the value as 60 * 1024 = 61440
* hence the extra 6, which makes the new value 60480
*/
#define CHUNK_SIZE (12 * 840 * 6)

extern unsigned int buffer_nr_chunks;

Expand Down
24 changes: 8 additions & 16 deletions ip/flac.c
Expand Up @@ -58,6 +58,7 @@ struct flac_private {
struct keyval *comments;
double duration;
long bitrate;
int bps;
};

static T(ReadStatus) read_cb(const Dec *dec, unsigned char *buf, size_t *size, void *data)
Expand Down Expand Up @@ -175,12 +176,12 @@ static FLAC__StreamDecoderWriteStatus write_cb(const Dec *dec, const FLAC__Frame

depth = frame->header.bits_per_sample;
if (!depth)
depth = bits;
depth = priv->bps;
nch = frame->header.channels;
dest = priv->buf + priv->buf_wpos;
for (i = 0; i < frames; i++) {
for (ch = 0; ch < channels; ch++) {
src = LE32(buf[ch % nch][i] << (bits -depth));
src = LE32(buf[ch % nch][i] << (bits - depth));
memcpy(dest, &src, bits / 8);
dest += bits / 8;
}
Expand All @@ -207,19 +208,9 @@ static void metadata_cb(const Dec *dec, const FLAC__StreamMetadata *metadata, vo
const FLAC__StreamMetadata_StreamInfo *si = &metadata->data.stream_info;
int bits = 0;

switch (si->bits_per_sample) {
case 8:
bits = 8;
break;
case 12:
case 16:
bits = 16;
break;
case 20:
case 24:
case 32:
bits = 32;
break;
if (si->bits_per_sample >= 4 && si->bits_per_sample <= 32) {
bits = priv->bps = si->bits_per_sample;
bits = 8 * ((bits + 7) / 8);
}

ip_data->sf = sf_rate(si->sample_rate) |
Expand Down Expand Up @@ -304,7 +295,8 @@ static int flac_open(struct input_plugin_data *ip_data)
const struct flac_private priv_init = {
.dec = dec,
.duration = -1,
.bitrate = -1
.bitrate = -1,
.bps = 0
};

if (!dec)
Expand Down

0 comments on commit d93f9c3

Please sign in to comment.