decoder/flac: use pcm_buffer instead of fixed buffer
This is a great simplification for flac_common_write(), because we can convert and submit all of the buffer in one turn. No more partial buffers with complicated formulas.
This commit is contained in:
parent
b6a2ffd3d7
commit
2f69831fb8
@ -31,6 +31,8 @@ void
|
|||||||
flac_data_init(struct flac_data *data, struct decoder * decoder,
|
flac_data_init(struct flac_data *data, struct decoder * decoder,
|
||||||
struct input_stream *input_stream)
|
struct input_stream *input_stream)
|
||||||
{
|
{
|
||||||
|
pcm_buffer_init(&data->buffer);
|
||||||
|
|
||||||
data->time = 0;
|
data->time = 0;
|
||||||
data->position = 0;
|
data->position = 0;
|
||||||
data->bit_rate = 0;
|
data->bit_rate = 0;
|
||||||
@ -43,6 +45,8 @@ flac_data_init(struct flac_data *data, struct decoder * decoder,
|
|||||||
void
|
void
|
||||||
flac_data_deinit(struct flac_data *data)
|
flac_data_deinit(struct flac_data *data)
|
||||||
{
|
{
|
||||||
|
pcm_buffer_deinit(&data->buffer);
|
||||||
|
|
||||||
if (data->replay_gain_info != NULL)
|
if (data->replay_gain_info != NULL)
|
||||||
replay_gain_info_free(data->replay_gain_info);
|
replay_gain_info_free(data->replay_gain_info);
|
||||||
|
|
||||||
@ -333,45 +337,31 @@ FLAC__StreamDecoderWriteStatus
|
|||||||
flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
|
flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
|
||||||
const FLAC__int32 *const buf[])
|
const FLAC__int32 *const buf[])
|
||||||
{
|
{
|
||||||
unsigned int c_samp;
|
|
||||||
const unsigned sample_format = data->audio_format.bits;
|
|
||||||
const unsigned int num_channels = frame->header.channels;
|
|
||||||
const unsigned int bytes_per_sample =
|
|
||||||
audio_format_sample_size(&data->audio_format);
|
|
||||||
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 decoder_command cmd;
|
enum decoder_command cmd;
|
||||||
|
size_t buffer_size = frame->header.blocksize *
|
||||||
|
audio_format_frame_size(&data->audio_format);
|
||||||
|
void *buffer;
|
||||||
|
|
||||||
for (c_samp = 0; c_samp < frame->header.blocksize;
|
buffer = pcm_buffer_get(&data->buffer, buffer_size);
|
||||||
c_samp += num_samples) {
|
|
||||||
num_samples = frame->header.blocksize - c_samp;
|
|
||||||
if (num_samples > max_samples)
|
|
||||||
num_samples = max_samples;
|
|
||||||
|
|
||||||
flac_convert(data->chunk,
|
flac_convert(buffer, data->audio_format.channels,
|
||||||
num_channels, sample_format, buf,
|
data->audio_format.bits, buf,
|
||||||
c_samp, c_samp + num_samples);
|
0, frame->header.blocksize);
|
||||||
|
|
||||||
cmd = decoder_data(data->decoder, data->input_stream,
|
cmd = decoder_data(data->decoder, data->input_stream,
|
||||||
data->chunk,
|
buffer, buffer_size,
|
||||||
num_samples * bytes_per_channel,
|
data->time, data->bit_rate,
|
||||||
data->time, data->bit_rate,
|
data->replay_gain_info);
|
||||||
data->replay_gain_info);
|
switch (cmd) {
|
||||||
switch (cmd) {
|
case DECODE_COMMAND_NONE:
|
||||||
case DECODE_COMMAND_NONE:
|
case DECODE_COMMAND_START:
|
||||||
case DECODE_COMMAND_START:
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case DECODE_COMMAND_STOP:
|
case DECODE_COMMAND_STOP:
|
||||||
return
|
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
||||||
FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
|
||||||
|
|
||||||
case DECODE_COMMAND_SEEK:
|
case DECODE_COMMAND_SEEK:
|
||||||
return
|
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||||
FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
#ifndef MPD_FLAC_COMMON_H
|
#ifndef MPD_FLAC_COMMON_H
|
||||||
#define MPD_FLAC_COMMON_H
|
#define MPD_FLAC_COMMON_H
|
||||||
|
|
||||||
#include "../decoder_api.h"
|
#include "decoder_api.h"
|
||||||
|
#include "pcm_buffer.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@ -145,7 +146,8 @@ typedef size_t flac_read_status_size_t;
|
|||||||
#define FLAC_CHUNK_SIZE 4080
|
#define FLAC_CHUNK_SIZE 4080
|
||||||
|
|
||||||
struct flac_data {
|
struct flac_data {
|
||||||
unsigned char chunk[FLAC_CHUNK_SIZE];
|
struct pcm_buffer buffer;
|
||||||
|
|
||||||
float time;
|
float time;
|
||||||
unsigned int bit_rate;
|
unsigned int bit_rate;
|
||||||
struct audio_format audio_format;
|
struct audio_format audio_format;
|
||||||
|
Loading…
Reference in New Issue
Block a user