pcm/export: move Open() parameters to struct Params

This commit is contained in:
Max Kellermann
2016-02-26 18:54:13 +01:00
parent d3f0b62348
commit f0f3017a76
5 changed files with 58 additions and 30 deletions

View File

@@ -716,22 +716,24 @@ AlsaOutput::SetupDop(const AudioFormat audio_format,
inline bool
AlsaOutput::SetupOrDop(AudioFormat &audio_format, Error &error)
{
bool shift8 = false, packed, reverse_endian;
PcmExport::Params params;
params.alsa_channel_order = true;
const bool dop2 = dop &&
audio_format.format == SampleFormat::DSD;
const bool success = dop2
params.dop = dop && audio_format.format == SampleFormat::DSD;
const bool success = params.dop
? SetupDop(audio_format,
&shift8, &packed, &reverse_endian,
&params.shift8,
&params.pack24, &params.reverse_endian,
error)
: alsa_setup(this, audio_format, &packed, &reverse_endian,
: alsa_setup(this, audio_format,
&params.pack24, &params.reverse_endian,
error);
if (!success)
return false;
pcm_export->Open(audio_format.format,
audio_format.channels,
true, dop2, shift8, packed, reverse_endian);
params);
return true;
}

View File

@@ -537,10 +537,13 @@ oss_probe_sample_format(int fd, SampleFormat sample_format,
*oss_format_r = oss_format;
#ifdef AFMT_S24_PACKED
pcm_export.Open(sample_format, 0, true, false, false,
oss_format == AFMT_S24_PACKED,
oss_format == AFMT_S24_PACKED &&
!IsLittleEndian());
PcmExport::Params params;
params.alsa_channel_order = true;
params.pack24 = oss_format == AFMT_S24_PACKED;
params.reverse_endian = oss_format == AFMT_S24_PACKED &&
!IsLittleEndian();
pcm_export.Open(sample_format, 0, params);
#endif
return SUCCESS;

View File

@@ -32,35 +32,33 @@
void
PcmExport::Open(SampleFormat sample_format, unsigned _channels,
bool _alsa_channel_order,
bool _dop, bool _shift8, bool _pack, bool _reverse_endian)
Params params)
{
assert(audio_valid_sample_format(sample_format));
channels = _channels;
alsa_channel_order = _alsa_channel_order
alsa_channel_order = params.alsa_channel_order
? sample_format
: SampleFormat::UNDEFINED;
#ifdef ENABLE_DSD
assert(!_dop || audio_valid_channel_count(_channels));
dop = _dop && sample_format == SampleFormat::DSD;
assert(!params.dop || audio_valid_channel_count(_channels));
dop = params.dop && sample_format == SampleFormat::DSD;
if (dop)
/* after the conversion to DoP, the DSD
samples are stuffed inside fake 24 bit samples */
sample_format = SampleFormat::S24_P32;
#else
(void)_channels;
(void)_dop;
#endif
shift8 = _shift8 && sample_format == SampleFormat::S24_P32;
pack24 = _pack && sample_format == SampleFormat::S24_P32;
shift8 = params.shift8 && sample_format == SampleFormat::S24_P32;
pack24 = params.pack24 && sample_format == SampleFormat::S24_P32;
assert(!shift8 || !pack24);
reverse_endian = 0;
if (_reverse_endian) {
if (params.reverse_endian) {
size_t sample_size = pack24
? 3
: sample_format_size(sample_format);

View File

@@ -33,6 +33,14 @@ template<typename T> struct ConstBuffer;
* representation which are not supported by the pcm_convert library.
*/
struct PcmExport {
struct Params {
bool alsa_channel_order = false;
bool dop = false;
bool shift8 = false;
bool pack24 = false;
bool reverse_endian = false;
};
/**
* This buffer is used to reorder channels.
*
@@ -117,8 +125,7 @@ struct PcmExport {
* @param channels the number of channels; ignored unless dop is set
*/
void Open(SampleFormat sample_format, unsigned channels,
bool _alsa_channel_order,
bool dop, bool shift8, bool pack, bool reverse_endian);
Params params);
/**
* Calculate the size of one output frame.