decoder/flac: pass number of frames to flac_convert()
This commit is contained in:
parent
1c818ef0a0
commit
62e96e9a58
@ -179,7 +179,7 @@ FlacDecoder::OnWrite(const FLAC__Frame &frame,
|
|||||||
|
|
||||||
flac_convert(data, frame.header.channels,
|
flac_convert(data, frame.header.channels,
|
||||||
audio_format.format, buf,
|
audio_format.format, buf,
|
||||||
0, frame.header.blocksize);
|
frame.header.blocksize);
|
||||||
|
|
||||||
unsigned bit_rate = nbytes * 8 * frame.header.sample_rate /
|
unsigned bit_rate = nbytes * 8 * frame.header.sample_rate /
|
||||||
(1000 * frame.header.blocksize);
|
(1000 * frame.header.blocksize);
|
||||||
|
@ -24,11 +24,11 @@
|
|||||||
|
|
||||||
static void flac_convert_stereo16(int16_t *dest,
|
static void flac_convert_stereo16(int16_t *dest,
|
||||||
const FLAC__int32 * const buf[],
|
const FLAC__int32 * const buf[],
|
||||||
unsigned int position, unsigned int end)
|
size_t n_frames)
|
||||||
{
|
{
|
||||||
for (; position < end; ++position) {
|
for (size_t i = 0; i != n_frames; ++i) {
|
||||||
*dest++ = buf[0][position];
|
*dest++ = buf[0][i];
|
||||||
*dest++ = buf[1][position];
|
*dest++ = buf[1][i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,13 +36,13 @@ static void
|
|||||||
flac_convert_16(int16_t *dest,
|
flac_convert_16(int16_t *dest,
|
||||||
unsigned int num_channels,
|
unsigned int num_channels,
|
||||||
const FLAC__int32 * const buf[],
|
const FLAC__int32 * const buf[],
|
||||||
unsigned int position, unsigned int end)
|
size_t n_frames)
|
||||||
{
|
{
|
||||||
unsigned int c_chan;
|
unsigned int c_chan;
|
||||||
|
|
||||||
for (; position < end; ++position)
|
for (size_t i = 0; i != n_frames; ++i)
|
||||||
for (c_chan = 0; c_chan < num_channels; c_chan++)
|
for (c_chan = 0; c_chan < num_channels; c_chan++)
|
||||||
*dest++ = buf[c_chan][position];
|
*dest++ = buf[c_chan][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,53 +52,52 @@ static void
|
|||||||
flac_convert_32(int32_t *dest,
|
flac_convert_32(int32_t *dest,
|
||||||
unsigned int num_channels,
|
unsigned int num_channels,
|
||||||
const FLAC__int32 * const buf[],
|
const FLAC__int32 * const buf[],
|
||||||
unsigned int position, unsigned int end)
|
size_t n_frames)
|
||||||
{
|
{
|
||||||
unsigned int c_chan;
|
unsigned int c_chan;
|
||||||
|
|
||||||
for (; position < end; ++position)
|
for (size_t i = 0; i != n_frames; ++i)
|
||||||
for (c_chan = 0; c_chan < num_channels; c_chan++)
|
for (c_chan = 0; c_chan < num_channels; c_chan++)
|
||||||
*dest++ = buf[c_chan][position];
|
*dest++ = buf[c_chan][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
flac_convert_8(int8_t *dest,
|
flac_convert_8(int8_t *dest,
|
||||||
unsigned int num_channels,
|
unsigned int num_channels,
|
||||||
const FLAC__int32 * const buf[],
|
const FLAC__int32 * const buf[],
|
||||||
unsigned int position, unsigned int end)
|
size_t n_frames)
|
||||||
{
|
{
|
||||||
unsigned int c_chan;
|
unsigned int c_chan;
|
||||||
|
|
||||||
for (; position < end; ++position)
|
for (size_t i = 0; i != n_frames; ++i)
|
||||||
for (c_chan = 0; c_chan < num_channels; c_chan++)
|
for (c_chan = 0; c_chan < num_channels; c_chan++)
|
||||||
*dest++ = buf[c_chan][position];
|
*dest++ = buf[c_chan][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
flac_convert(void *dest,
|
flac_convert(void *dest,
|
||||||
unsigned int num_channels, SampleFormat sample_format,
|
unsigned int num_channels, SampleFormat sample_format,
|
||||||
const FLAC__int32 *const buf[],
|
const FLAC__int32 *const buf[],
|
||||||
unsigned int position, unsigned int end)
|
size_t n_frames)
|
||||||
{
|
{
|
||||||
switch (sample_format) {
|
switch (sample_format) {
|
||||||
case SampleFormat::S16:
|
case SampleFormat::S16:
|
||||||
if (num_channels == 2)
|
if (num_channels == 2)
|
||||||
flac_convert_stereo16((int16_t*)dest, buf,
|
flac_convert_stereo16((int16_t *)dest, buf, n_frames);
|
||||||
position, end);
|
|
||||||
else
|
else
|
||||||
flac_convert_16((int16_t*)dest, num_channels, buf,
|
flac_convert_16((int16_t*)dest, num_channels, buf,
|
||||||
position, end);
|
n_frames);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SampleFormat::S24_P32:
|
case SampleFormat::S24_P32:
|
||||||
case SampleFormat::S32:
|
case SampleFormat::S32:
|
||||||
flac_convert_32((int32_t*)dest, num_channels, buf,
|
flac_convert_32((int32_t*)dest, num_channels, buf,
|
||||||
position, end);
|
n_frames);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SampleFormat::S8:
|
case SampleFormat::S8:
|
||||||
flac_convert_8((int8_t*)dest, num_channels, buf,
|
flac_convert_8((int8_t*)dest, num_channels, buf,
|
||||||
position, end);
|
n_frames);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SampleFormat::FLOAT:
|
case SampleFormat::FLOAT:
|
||||||
|
@ -24,10 +24,12 @@
|
|||||||
|
|
||||||
#include <FLAC/ordinals.h>
|
#include <FLAC/ordinals.h>
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
flac_convert(void *dest,
|
flac_convert(void *dest,
|
||||||
unsigned int num_channels, SampleFormat sample_format,
|
unsigned int num_channels, SampleFormat sample_format,
|
||||||
const FLAC__int32 *const buf[],
|
const FLAC__int32 *const buf[],
|
||||||
unsigned int position, unsigned int end);
|
size_t n_frames);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user