aboutsummaryrefslogtreecommitdiffstats
path: root/src/output/AlsaOutputPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-03 21:00:50 +0200
committerMax Kellermann <max@duempel.org>2013-08-03 21:37:56 +0200
commitd1e7b4e38136f9342aad76c685a13adf0e69f869 (patch)
tree49643b937ddfe735511b566a71398da5a945d7aa /src/output/AlsaOutputPlugin.cxx
parent67f591a9ce60651da41afc499bd9a22e25314e35 (diff)
downloadmpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.tar.gz
mpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.tar.xz
mpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.zip
audio_format: convert to C++
Diffstat (limited to 'src/output/AlsaOutputPlugin.cxx')
-rw-r--r--src/output/AlsaOutputPlugin.cxx92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/output/AlsaOutputPlugin.cxx b/src/output/AlsaOutputPlugin.cxx
index 7d0e9e09c..0e70babb6 100644
--- a/src/output/AlsaOutputPlugin.cxx
+++ b/src/output/AlsaOutputPlugin.cxx
@@ -233,26 +233,26 @@ alsa_test_default_device(void)
}
static snd_pcm_format_t
-get_bitformat(enum sample_format sample_format)
+get_bitformat(SampleFormat sample_format)
{
switch (sample_format) {
- case SAMPLE_FORMAT_UNDEFINED:
- case SAMPLE_FORMAT_DSD:
+ case SampleFormat::UNDEFINED:
+ case SampleFormat::DSD:
return SND_PCM_FORMAT_UNKNOWN;
- case SAMPLE_FORMAT_S8:
+ case SampleFormat::S8:
return SND_PCM_FORMAT_S8;
- case SAMPLE_FORMAT_S16:
+ case SampleFormat::S16:
return SND_PCM_FORMAT_S16;
- case SAMPLE_FORMAT_S24_P32:
+ case SampleFormat::S24_P32:
return SND_PCM_FORMAT_S24;
- case SAMPLE_FORMAT_S32:
+ case SampleFormat::S32:
return SND_PCM_FORMAT_S32;
- case SAMPLE_FORMAT_FLOAT:
+ case SampleFormat::FLOAT:
return SND_PCM_FORMAT_FLOAT;
}
@@ -324,7 +324,7 @@ alsa_try_format_or_packed(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
*/
static int
alsa_output_try_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
- enum sample_format sample_format,
+ SampleFormat sample_format,
bool *packed_r, bool *reverse_endian_r)
{
snd_pcm_format_t alsa_format = get_bitformat(sample_format);
@@ -355,36 +355,36 @@ alsa_output_try_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
*/
static int
alsa_output_setup_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
- struct audio_format *audio_format,
+ AudioFormat &audio_format,
bool *packed_r, bool *reverse_endian_r)
{
/* try the input format first */
int err = alsa_output_try_format(pcm, hwparams,
- sample_format(audio_format->format),
+ audio_format.format,
packed_r, reverse_endian_r);
/* if unsupported by the hardware, try other formats */
- static const enum sample_format probe_formats[] = {
- SAMPLE_FORMAT_S24_P32,
- SAMPLE_FORMAT_S32,
- SAMPLE_FORMAT_S16,
- SAMPLE_FORMAT_S8,
- SAMPLE_FORMAT_UNDEFINED,
+ static const SampleFormat probe_formats[] = {
+ SampleFormat::S24_P32,
+ SampleFormat::S32,
+ SampleFormat::S16,
+ SampleFormat::S8,
+ SampleFormat::UNDEFINED,
};
for (unsigned i = 0;
- err == -EINVAL && probe_formats[i] != SAMPLE_FORMAT_UNDEFINED;
+ err == -EINVAL && probe_formats[i] != SampleFormat::UNDEFINED;
++i) {
- const enum sample_format mpd_format = probe_formats[i];
- if (mpd_format == audio_format->format)
+ const SampleFormat mpd_format = probe_formats[i];
+ if (mpd_format == audio_format.format)
continue;
err = alsa_output_try_format(pcm, hwparams, mpd_format,
packed_r, reverse_endian_r);
if (err == 0)
- audio_format->format = mpd_format;
+ audio_format.format = mpd_format;
}
return err;
@@ -395,11 +395,11 @@ alsa_output_setup_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
* the configured settings and the audio format.
*/
static bool
-alsa_setup(AlsaOutput *ad, struct audio_format *audio_format,
+alsa_setup(AlsaOutput *ad, AudioFormat &audio_format,
bool *packed_r, bool *reverse_endian_r, GError **error)
{
- unsigned int sample_rate = audio_format->sample_rate;
- unsigned int channels = audio_format->channels;
+ unsigned int sample_rate = audio_format.sample_rate;
+ unsigned int channels = audio_format.channels;
int err;
const char *cmd = NULL;
int retry = MPD_ALSA_RETRY_NR;
@@ -443,7 +443,7 @@ configure_hw:
g_set_error(error, alsa_output_quark(), err,
"ALSA device \"%s\" does not support format %s: %s",
alsa_device(ad),
- sample_format_to_string(sample_format(audio_format->format)),
+ sample_format_to_string(audio_format.format),
snd_strerror(-err));
return false;
}
@@ -458,21 +458,21 @@ configure_hw:
if (err < 0) {
g_set_error(error, alsa_output_quark(), err,
"ALSA device \"%s\" does not support %i channels: %s",
- alsa_device(ad), (int)audio_format->channels,
+ alsa_device(ad), (int)audio_format.channels,
snd_strerror(-err));
return false;
}
- audio_format->channels = (int8_t)channels;
+ audio_format.channels = (int8_t)channels;
err = snd_pcm_hw_params_set_rate_near(ad->pcm, hwparams,
&sample_rate, NULL);
if (err < 0 || sample_rate == 0) {
g_set_error(error, alsa_output_quark(), err,
"ALSA device \"%s\" does not support %u Hz audio",
- alsa_device(ad), audio_format->sample_rate);
+ alsa_device(ad), audio_format.sample_rate);
return false;
}
- audio_format->sample_rate = sample_rate;
+ audio_format.sample_rate = sample_rate;
snd_pcm_uframes_t buffer_size_min, buffer_size_max;
snd_pcm_hw_params_get_buffer_size_min(hwparams, &buffer_size_min);
@@ -603,22 +603,22 @@ error:
}
static bool
-alsa_setup_dsd(AlsaOutput *ad, struct audio_format *audio_format,
+alsa_setup_dsd(AlsaOutput *ad, const AudioFormat audio_format,
bool *shift8_r, bool *packed_r, bool *reverse_endian_r,
GError **error_r)
{
assert(ad->dsd_usb);
- assert(audio_format->format == SAMPLE_FORMAT_DSD);
+ assert(audio_format.format == SampleFormat::DSD);
/* pass 24 bit to alsa_setup() */
- struct audio_format usb_format = *audio_format;
- usb_format.format = SAMPLE_FORMAT_S24_P32;
+ AudioFormat usb_format = audio_format;
+ usb_format.format = SampleFormat::S24_P32;
usb_format.sample_rate /= 2;
- const struct audio_format check = usb_format;
+ const AudioFormat check = usb_format;
- if (!alsa_setup(ad, &usb_format, packed_r, reverse_endian_r, error_r))
+ if (!alsa_setup(ad, usb_format, packed_r, reverse_endian_r, error_r))
return false;
/* if the device allows only 32 bit, shift all DSD-over-USB
@@ -626,11 +626,11 @@ alsa_setup_dsd(AlsaOutput *ad, struct audio_format *audio_format,
the DSD-over-USB documentation does not specify whether
this is legal, but there is anecdotical evidence that this
is possible (and the only option for some devices) */
- *shift8_r = usb_format.format == SAMPLE_FORMAT_S32;
- if (usb_format.format == SAMPLE_FORMAT_S32)
- usb_format.format = SAMPLE_FORMAT_S24_P32;
+ *shift8_r = usb_format.format == SampleFormat::S32;
+ if (usb_format.format == SampleFormat::S32)
+ usb_format.format = SampleFormat::S24_P32;
- if (!audio_format_equals(&usb_format, &check)) {
+ if (usb_format != check) {
/* no bit-perfect playback, which is required
for DSD over USB */
g_set_error(error_r, alsa_output_quark(), 0,
@@ -644,13 +644,13 @@ alsa_setup_dsd(AlsaOutput *ad, struct audio_format *audio_format,
}
static bool
-alsa_setup_or_dsd(AlsaOutput *ad, struct audio_format *audio_format,
+alsa_setup_or_dsd(AlsaOutput *ad, AudioFormat &audio_format,
GError **error_r)
{
bool shift8 = false, packed, reverse_endian;
const bool dsd_usb = ad->dsd_usb &&
- audio_format->format == SAMPLE_FORMAT_DSD;
+ audio_format.format == SampleFormat::DSD;
const bool success = dsd_usb
? alsa_setup_dsd(ad, audio_format,
&shift8, &packed, &reverse_endian,
@@ -660,14 +660,14 @@ alsa_setup_or_dsd(AlsaOutput *ad, struct audio_format *audio_format,
if (!success)
return false;
- ad->pcm_export->Open(sample_format(audio_format->format),
- audio_format->channels,
+ ad->pcm_export->Open(audio_format.format,
+ audio_format.channels,
dsd_usb, shift8, packed, reverse_endian);
return true;
}
static bool
-alsa_open(struct audio_output *ao, struct audio_format *audio_format, GError **error)
+alsa_open(struct audio_output *ao, AudioFormat &audio_format, GError **error)
{
AlsaOutput *ad = (AlsaOutput *)ao;
@@ -688,8 +688,8 @@ alsa_open(struct audio_output *ao, struct audio_format *audio_format, GError **e
return false;
}
- ad->in_frame_size = audio_format_frame_size(audio_format);
- ad->out_frame_size = ad->pcm_export->GetFrameSize(*audio_format);
+ ad->in_frame_size = audio_format.GetFrameSize();
+ ad->out_frame_size = ad->pcm_export->GetFrameSize(audio_format);
return true;
}