decoder/audiofile: make variables more local
This commit is contained in:
parent
107321e385
commit
49b63e084f
@ -34,9 +34,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* pick 1020 since its devisible for 8,16,24, and 32-bit audio */
|
|
||||||
#define CHUNK_SIZE 1020
|
|
||||||
|
|
||||||
static constexpr Domain audiofile_domain("audiofile");
|
static constexpr Domain audiofile_domain("audiofile");
|
||||||
|
|
||||||
struct AudioFileInputStream {
|
struct AudioFileInputStream {
|
||||||
@ -172,69 +169,68 @@ audiofile_setup_sample_format(AFfilehandle af_fp)
|
|||||||
static void
|
static void
|
||||||
audiofile_stream_decode(Decoder &decoder, InputStream &is)
|
audiofile_stream_decode(Decoder &decoder, InputStream &is)
|
||||||
{
|
{
|
||||||
AFvirtualfile *vf;
|
|
||||||
int fs;
|
|
||||||
AFfilehandle af_fp;
|
|
||||||
AudioFormat audio_format;
|
|
||||||
uint16_t bit_rate;
|
|
||||||
int ret;
|
|
||||||
char chunk[CHUNK_SIZE];
|
|
||||||
|
|
||||||
if (!is.IsSeekable()) {
|
if (!is.IsSeekable()) {
|
||||||
LogWarning(audiofile_domain, "not seekable");
|
LogWarning(audiofile_domain, "not seekable");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioFileInputStream afis{&decoder, is};
|
AudioFileInputStream afis{&decoder, is};
|
||||||
vf = setup_virtual_fops(afis);
|
AFvirtualfile *const vf = setup_virtual_fops(afis);
|
||||||
|
|
||||||
af_fp = afOpenVirtualFile(vf, "r", nullptr);
|
const AFfilehandle fh = afOpenVirtualFile(vf, "r", nullptr);
|
||||||
if (af_fp == AF_NULL_FILEHANDLE) {
|
if (fh == AF_NULL_FILEHANDLE) {
|
||||||
LogWarning(audiofile_domain, "failed to input stream");
|
LogWarning(audiofile_domain, "failed to input stream");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error error;
|
Error error;
|
||||||
|
AudioFormat audio_format;
|
||||||
if (!audio_format_init_checked(audio_format,
|
if (!audio_format_init_checked(audio_format,
|
||||||
afGetRate(af_fp, AF_DEFAULT_TRACK),
|
afGetRate(fh, AF_DEFAULT_TRACK),
|
||||||
audiofile_setup_sample_format(af_fp),
|
audiofile_setup_sample_format(fh),
|
||||||
afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK),
|
afGetVirtualChannels(fh, AF_DEFAULT_TRACK),
|
||||||
error)) {
|
error)) {
|
||||||
LogError(error);
|
LogError(error);
|
||||||
afCloseFile(af_fp);
|
afCloseFile(fh);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double total_time = audiofile_get_duration(af_fp);
|
const double total_time = audiofile_get_duration(fh);
|
||||||
|
|
||||||
bit_rate = (uint16_t)(is.GetSize() * 8.0 / total_time / 1000.0 + 0.5);
|
const uint16_t kbit_rate = (uint16_t)
|
||||||
|
(is.GetSize() * 8.0 / total_time / 1000.0 + 0.5);
|
||||||
|
|
||||||
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
|
const unsigned frame_size = (unsigned)
|
||||||
|
afGetVirtualFrameSize(fh, AF_DEFAULT_TRACK, true);
|
||||||
|
|
||||||
decoder_initialized(decoder, audio_format, true, total_time);
|
decoder_initialized(decoder, audio_format, true, total_time);
|
||||||
|
|
||||||
DecoderCommand cmd;
|
DecoderCommand cmd;
|
||||||
do {
|
do {
|
||||||
ret = afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk,
|
/* pick 1020 since its divisible for 8,16,24, and
|
||||||
CHUNK_SIZE / fs);
|
32-bit audio */
|
||||||
if (ret <= 0)
|
char chunk[1020];
|
||||||
|
const int nframes =
|
||||||
|
afReadFrames(fh, AF_DEFAULT_TRACK, chunk,
|
||||||
|
sizeof(chunk) / frame_size);
|
||||||
|
if (nframes <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
cmd = decoder_data(decoder, nullptr,
|
cmd = decoder_data(decoder, nullptr,
|
||||||
chunk, ret * fs,
|
chunk, nframes * frame_size,
|
||||||
bit_rate);
|
kbit_rate);
|
||||||
|
|
||||||
if (cmd == DecoderCommand::SEEK) {
|
if (cmd == DecoderCommand::SEEK) {
|
||||||
AFframecount frame = decoder_seek_where(decoder) *
|
AFframecount frame = decoder_seek_where(decoder) *
|
||||||
audio_format.sample_rate;
|
audio_format.sample_rate;
|
||||||
afSeekFrame(af_fp, AF_DEFAULT_TRACK, frame);
|
afSeekFrame(fh, AF_DEFAULT_TRACK, frame);
|
||||||
|
|
||||||
decoder_command_finished(decoder);
|
decoder_command_finished(decoder);
|
||||||
cmd = DecoderCommand::NONE;
|
cmd = DecoderCommand::NONE;
|
||||||
}
|
}
|
||||||
} while (cmd == DecoderCommand::NONE);
|
} while (cmd == DecoderCommand::NONE);
|
||||||
|
|
||||||
afCloseFile(af_fp);
|
afCloseFile(fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
|
Loading…
Reference in New Issue
Block a user