diff options
author | Max Kellermann <max@duempel.org> | 2013-08-03 21:00:50 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-08-03 21:37:56 +0200 |
commit | d1e7b4e38136f9342aad76c685a13adf0e69f869 (patch) | |
tree | 49643b937ddfe735511b566a71398da5a945d7aa /src/output | |
parent | 67f591a9ce60651da41afc499bd9a22e25314e35 (diff) | |
download | mpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.tar.gz mpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.tar.xz mpd-d1e7b4e38136f9342aad76c685a13adf0e69f869.zip |
audio_format: convert to C++
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/AlsaOutputPlugin.cxx | 92 | ||||
-rw-r--r-- | src/output/AoOutputPlugin.cxx | 14 | ||||
-rw-r--r-- | src/output/FifoOutputPlugin.cxx | 4 | ||||
-rw-r--r-- | src/output/HttpdInternal.hxx | 4 | ||||
-rw-r--r-- | src/output/HttpdOutputPlugin.cxx | 8 | ||||
-rw-r--r-- | src/output/JackOutputPlugin.cxx | 28 | ||||
-rw-r--r-- | src/output/NullOutputPlugin.cxx | 4 | ||||
-rw-r--r-- | src/output/OSXOutputPlugin.cxx | 23 | ||||
-rw-r--r-- | src/output/OpenALOutputPlugin.cxx | 20 | ||||
-rw-r--r-- | src/output/OssOutputPlugin.cxx | 96 | ||||
-rw-r--r-- | src/output/PipeOutputPlugin.cxx | 2 | ||||
-rw-r--r-- | src/output/PulseOutputPlugin.cxx | 8 | ||||
-rw-r--r-- | src/output/RecorderOutputPlugin.cxx | 2 | ||||
-rw-r--r-- | src/output/RoarOutputPlugin.cxx | 26 | ||||
-rw-r--r-- | src/output/ShoutOutputPlugin.cxx | 11 | ||||
-rw-r--r-- | src/output/SolarisOutputPlugin.cxx | 8 | ||||
-rw-r--r-- | src/output/WinmmOutputPlugin.cxx | 30 |
17 files changed, 191 insertions, 189 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; } diff --git a/src/output/AoOutputPlugin.cxx b/src/output/AoOutputPlugin.cxx index b534ddf08..d25a30973 100644 --- a/src/output/AoOutputPlugin.cxx +++ b/src/output/AoOutputPlugin.cxx @@ -200,18 +200,18 @@ ao_output_close(struct audio_output *ao) } static bool -ao_output_open(struct audio_output *ao, struct audio_format *audio_format, +ao_output_open(struct audio_output *ao, AudioFormat &audio_format, GError **error) { ao_sample_format format = OUR_AO_FORMAT_INITIALIZER; AoOutput *ad = (AoOutput *)ao; - switch (audio_format->format) { - case SAMPLE_FORMAT_S8: + switch (audio_format.format) { + case SampleFormat::S8: format.bits = 8; break; - case SAMPLE_FORMAT_S16: + case SampleFormat::S16: format.bits = 16; break; @@ -219,14 +219,14 @@ ao_output_open(struct audio_output *ao, struct audio_format *audio_format, /* support for 24 bit samples in libao is currently dubious, and until we have sorted that out, convert everything to 16 bit */ - audio_format->format = SAMPLE_FORMAT_S16; + audio_format.format = SampleFormat::S16; format.bits = 16; break; } - format.rate = audio_format->sample_rate; + format.rate = audio_format.sample_rate; format.byte_format = AO_FMT_NATIVE; - format.channels = audio_format->channels; + format.channels = audio_format.channels; ad->device = ao_open_live(ad->driver, &format, ad->options); diff --git a/src/output/FifoOutputPlugin.cxx b/src/output/FifoOutputPlugin.cxx index 1151d9f3a..a0d07c702 100644 --- a/src/output/FifoOutputPlugin.cxx +++ b/src/output/FifoOutputPlugin.cxx @@ -227,12 +227,12 @@ fifo_output_finish(struct audio_output *ao) } static bool -fifo_output_open(struct audio_output *ao, struct audio_format *audio_format, +fifo_output_open(struct audio_output *ao, AudioFormat &audio_format, G_GNUC_UNUSED GError **error) { FifoOutput *fd = (FifoOutput *)ao; - fd->timer = new Timer(*audio_format); + fd->timer = new Timer(audio_format); return true; } diff --git a/src/output/HttpdInternal.hxx b/src/output/HttpdInternal.hxx index c2ac96be5..8bc0c130e 100644 --- a/src/output/HttpdInternal.hxx +++ b/src/output/HttpdInternal.hxx @@ -131,13 +131,13 @@ struct HttpdOutput final : private ServerSocket { /** * Caller must lock the mutex. */ - bool OpenEncoder(struct audio_format *audio_format, + bool OpenEncoder(AudioFormat &audio_format, GError **error_r); /** * Caller must lock the mutex. */ - bool Open(struct audio_format *audio_format, GError **error_r); + bool Open(AudioFormat &audio_format, GError **error_r); /** * Caller must lock the mutex. diff --git a/src/output/HttpdOutputPlugin.cxx b/src/output/HttpdOutputPlugin.cxx index 36bd1aee1..462dd3429 100644 --- a/src/output/HttpdOutputPlugin.cxx +++ b/src/output/HttpdOutputPlugin.cxx @@ -291,7 +291,7 @@ httpd_output_disable(struct audio_output *ao) } inline bool -HttpdOutput::OpenEncoder(struct audio_format *audio_format, GError **error) +HttpdOutput::OpenEncoder(AudioFormat &audio_format, GError **error) { if (!encoder_open(encoder, audio_format, error)) return false; @@ -307,7 +307,7 @@ HttpdOutput::OpenEncoder(struct audio_format *audio_format, GError **error) } inline bool -HttpdOutput::Open(struct audio_format *audio_format, GError **error_r) +HttpdOutput::Open(AudioFormat &audio_format, GError **error_r) { assert(!open); assert(clients.empty()); @@ -320,7 +320,7 @@ HttpdOutput::Open(struct audio_format *audio_format, GError **error_r) /* initialize other attributes */ clients_cnt = 0; - timer = new Timer(*audio_format); + timer = new Timer(audio_format); open = true; @@ -328,7 +328,7 @@ HttpdOutput::Open(struct audio_format *audio_format, GError **error_r) } static bool -httpd_output_open(struct audio_output *ao, struct audio_format *audio_format, +httpd_output_open(struct audio_output *ao, AudioFormat &audio_format, GError **error) { HttpdOutput *httpd = Cast(ao); diff --git a/src/output/JackOutputPlugin.cxx b/src/output/JackOutputPlugin.cxx index 4f21b36f8..6c9ee9335 100644 --- a/src/output/JackOutputPlugin.cxx +++ b/src/output/JackOutputPlugin.cxx @@ -67,7 +67,7 @@ struct JackOutput { size_t ringbuffer_size; /* the current audio format */ - struct audio_format audio_format; + AudioFormat audio_format; /* jack library stuff */ jack_port_t *ports[MAX_PORTS]; @@ -203,18 +203,18 @@ mpd_jack_shutdown(void *arg) } static void -set_audioformat(JackOutput *jd, struct audio_format *audio_format) +set_audioformat(JackOutput *jd, AudioFormat &audio_format) { - audio_format->sample_rate = jack_get_sample_rate(jd->client); + audio_format.sample_rate = jack_get_sample_rate(jd->client); if (jd->num_source_ports == 1) - audio_format->channels = 1; - else if (audio_format->channels > jd->num_source_ports) - audio_format->channels = 2; + audio_format.channels = 1; + else if (audio_format.channels > jd->num_source_ports) + audio_format.channels = 2; - if (audio_format->format != SAMPLE_FORMAT_S16 && - audio_format->format != SAMPLE_FORMAT_S24_P32) - audio_format->format = SAMPLE_FORMAT_S24_P32; + if (audio_format.format != SampleFormat::S16 && + audio_format.format != SampleFormat::S24_P32) + audio_format.format = SampleFormat::S24_P32; } static void @@ -591,7 +591,7 @@ mpd_jack_start(JackOutput *jd, GError **error_r) } static bool -mpd_jack_open(struct audio_output *ao, struct audio_format *audio_format, +mpd_jack_open(struct audio_output *ao, AudioFormat &audio_format, GError **error_r) { JackOutput *jd = (JackOutput *)ao; @@ -607,7 +607,7 @@ mpd_jack_open(struct audio_output *ao, struct audio_format *audio_format, return false; set_audioformat(jd, audio_format); - jd->audio_format = *audio_format; + jd->audio_format = audio_format; if (!mpd_jack_start(jd, error_r)) return false; @@ -684,12 +684,12 @@ mpd_jack_write_samples(JackOutput *jd, const void *src, unsigned num_samples) { switch (jd->audio_format.format) { - case SAMPLE_FORMAT_S16: + case SampleFormat::S16: mpd_jack_write_samples_16(jd, (const int16_t*)src, num_samples); break; - case SAMPLE_FORMAT_S24_P32: + case SampleFormat::S24_P32: mpd_jack_write_samples_24(jd, (const int32_t*)src, num_samples); break; @@ -705,7 +705,7 @@ mpd_jack_play(struct audio_output *ao, const void *chunk, size_t size, GError **error_r) { JackOutput *jd = (JackOutput *)ao; - const size_t frame_size = audio_format_frame_size(&jd->audio_format); + const size_t frame_size = jd->audio_format.GetFrameSize(); size_t space = 0, space1; jd->pause = false; diff --git a/src/output/NullOutputPlugin.cxx b/src/output/NullOutputPlugin.cxx index 07452bbdb..814a9d2e2 100644 --- a/src/output/NullOutputPlugin.cxx +++ b/src/output/NullOutputPlugin.cxx @@ -66,13 +66,13 @@ null_finish(struct audio_output *ao) } static bool -null_open(struct audio_output *ao, struct audio_format *audio_format, +null_open(struct audio_output *ao, AudioFormat &audio_format, gcc_unused GError **error) { NullOutput *nd = (NullOutput *)ao; if (nd->sync) - nd->timer = new Timer(*audio_format); + nd->timer = new Timer(audio_format); return true; } diff --git a/src/output/OSXOutputPlugin.cxx b/src/output/OSXOutputPlugin.cxx index cbd27413f..afe8e064d 100644 --- a/src/output/OSXOutputPlugin.cxx +++ b/src/output/OSXOutputPlugin.cxx @@ -316,30 +316,30 @@ osx_output_close(struct audio_output *ao) } static bool -osx_output_open(struct audio_output *ao, struct audio_format *audio_format, GError **error) +osx_output_open(struct audio_output *ao, AudioFormat &audio_format, GError **error) { OSXOutput *od = (OSXOutput *)ao; AudioStreamBasicDescription stream_description; - stream_description.mSampleRate = audio_format->sample_rate; + stream_description.mSampleRate = audio_format.sample_rate; stream_description.mFormatID = kAudioFormatLinearPCM; stream_description.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger; - switch (audio_format->format) { - case SAMPLE_FORMAT_S8: + switch (audio_format.format) { + case SampleFormat::S8: stream_description.mBitsPerChannel = 8; break; - case SAMPLE_FORMAT_S16: + case SampleFormat::S16: stream_description.mBitsPerChannel = 16; break; - case SAMPLE_FORMAT_S32: + case SampleFormat::S32: stream_description.mBitsPerChannel = 32; break; default: - audio_format->format = SAMPLE_FORMAT_S32; + audio_format.format = SampleFormat::S32; stream_description.mBitsPerChannel = 32; break; } @@ -348,11 +348,10 @@ osx_output_open(struct audio_output *ao, struct audio_format *audio_format, GErr stream_description.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian; #endif - stream_description.mBytesPerPacket = - audio_format_frame_size(audio_format); + stream_description.mBytesPerPacket = audio_format.GetFrameSize(); stream_description.mFramesPerPacket = 1; stream_description.mBytesPerFrame = stream_description.mBytesPerPacket; - stream_description.mChannelsPerFrame = audio_format->channels; + stream_description.mChannelsPerFrame = audio_format.channels; ComponentResult result = AudioUnitSetProperty(od->au, kAudioUnitProperty_StreamFormat, @@ -374,8 +373,8 @@ osx_output_open(struct audio_output *ao, struct audio_format *audio_format, GErr } /* create a buffer of 1s */ - od->buffer = fifo_buffer_new(audio_format->sample_rate * - audio_format_frame_size(audio_format)); + od->buffer = fifo_buffer_new(audio_format.sample_rate * + audio_format.GetFrameSize()); status = AudioOutputUnitStart(od->au); if (status != 0) { diff --git a/src/output/OpenALOutputPlugin.cxx b/src/output/OpenALOutputPlugin.cxx index e68032d75..81c75f6c4 100644 --- a/src/output/OpenALOutputPlugin.cxx +++ b/src/output/OpenALOutputPlugin.cxx @@ -66,26 +66,26 @@ openal_output_quark(void) } static ALenum -openal_audio_format(struct audio_format *audio_format) +openal_audio_format(AudioFormat &audio_format) { - /* note: cannot map SAMPLE_FORMAT_S8 to AL_FORMAT_STEREO8 or + /* note: cannot map SampleFormat::S8 to AL_FORMAT_STEREO8 or AL_FORMAT_MONO8 since OpenAL expects unsigned 8 bit samples, while MPD uses signed samples */ - switch (audio_format->format) { - case SAMPLE_FORMAT_S16: - if (audio_format->channels == 2) + switch (audio_format.format) { + case SampleFormat::S16: + if (audio_format.channels == 2) return AL_FORMAT_STEREO16; - if (audio_format->channels == 1) + if (audio_format.channels == 1) return AL_FORMAT_MONO16; /* fall back to mono */ - audio_format->channels = 1; + audio_format.channels = 1; return openal_audio_format(audio_format); default: /* fall back to 16 bit */ - audio_format->format = SAMPLE_FORMAT_S16; + audio_format.format = SampleFormat::S16; return openal_audio_format(audio_format); } } @@ -169,7 +169,7 @@ openal_finish(struct audio_output *ao) } static bool -openal_open(struct audio_output *ao, struct audio_format *audio_format, +openal_open(struct audio_output *ao, AudioFormat &audio_format, GError **error) { OpenALOutput *od = (OpenALOutput *)ao; @@ -199,7 +199,7 @@ openal_open(struct audio_output *ao, struct audio_format *audio_format, } od->filled = 0; - od->frequency = audio_format->sample_rate; + od->frequency = audio_format.sample_rate; return true; } diff --git a/src/output/OssOutputPlugin.cxx b/src/output/OssOutputPlugin.cxx index 70ffd8bfc..49b02386b 100644 --- a/src/output/OssOutputPlugin.cxx +++ b/src/output/OssOutputPlugin.cxx @@ -70,7 +70,7 @@ struct OssOutput { * The current input audio format. This is needed to reopen * the device after cancel(). */ - struct audio_format audio_format; + AudioFormat audio_format; /** * The current OSS audio format. This is needed to reopen the @@ -308,10 +308,10 @@ oss_try_ioctl(int fd, unsigned long request, int value, * specified number is not supported. */ static bool -oss_setup_channels(int fd, struct audio_format *audio_format, GError **error_r) +oss_setup_channels(int fd, AudioFormat &audio_format, GError **error_r) { const char *const msg = "Failed to set channel count"; - int channels = audio_format->channels; + int channels = audio_format.channels; enum oss_setup_result result = oss_try_ioctl_r(fd, SNDCTL_DSP_CHANNELS, &channels, msg, error_r); switch (result) { @@ -319,7 +319,7 @@ oss_setup_channels(int fd, struct audio_format *audio_format, GError **error_r) if (!audio_valid_channel_count(channels)) break; - audio_format->channels = channels; + audio_format.channels = channels; return true; case ERROR: @@ -330,7 +330,7 @@ oss_setup_channels(int fd, struct audio_format *audio_format, GError **error_r) } for (unsigned i = 1; i < 2; ++i) { - if (i == audio_format->channels) + if (i == audio_format.channels) /* don't try that again */ continue; @@ -342,7 +342,7 @@ oss_setup_channels(int fd, struct audio_format *audio_format, GError **error_r) if (!audio_valid_channel_count(channels)) break; - audio_format->channels = channels; + audio_format.channels = channels; return true; case ERROR: @@ -362,11 +362,11 @@ oss_setup_channels(int fd, struct audio_format *audio_format, GError **error_r) * specified sample rate is not supported. */ static bool -oss_setup_sample_rate(int fd, struct audio_format *audio_format, +oss_setup_sample_rate(int fd, AudioFormat &audio_format, GError **error_r) { const char *const msg = "Failed to set sample rate"; - int sample_rate = audio_format->sample_rate; + int sample_rate = audio_format.sample_rate; enum oss_setup_result result = oss_try_ioctl_r(fd, SNDCTL_DSP_SPEED, &sample_rate, msg, error_r); @@ -375,7 +375,7 @@ oss_setup_sample_rate(int fd, struct audio_format *audio_format, if (!audio_valid_sample_rate(sample_rate)) break; - audio_format->sample_rate = sample_rate; + audio_format.sample_rate = sample_rate; return true; case ERROR: @@ -388,7 +388,7 @@ oss_setup_sample_rate(int fd, struct audio_format *audio_format, static const int sample_rates[] = { 48000, 44100, 0 }; for (unsigned i = 0; sample_rates[i] != 0; ++i) { sample_rate = sample_rates[i]; - if (sample_rate == (int)audio_format->sample_rate) + if (sample_rate == (int)audio_format.sample_rate) continue; result = oss_try_ioctl_r(fd, SNDCTL_DSP_SPEED, &sample_rate, @@ -398,7 +398,7 @@ oss_setup_sample_rate(int fd, struct audio_format *audio_format, if (!audio_valid_sample_rate(sample_rate)) break; - audio_format->sample_rate = sample_rate; + audio_format.sample_rate = sample_rate; return true; case ERROR: @@ -418,28 +418,28 @@ oss_setup_sample_rate(int fd, struct audio_format *audio_format, * AFMT_QUERY if there is no direct counterpart. */ static int -sample_format_to_oss(enum sample_format format) +sample_format_to_oss(SampleFormat format) { switch (format) { - case SAMPLE_FORMAT_UNDEFINED: - case SAMPLE_FORMAT_FLOAT: - case SAMPLE_FORMAT_DSD: + case SampleFormat::UNDEFINED: + case SampleFormat::FLOAT: + case SampleFormat::DSD: return AFMT_QUERY; - case SAMPLE_FORMAT_S8: + case SampleFormat::S8: return AFMT_S8; - case SAMPLE_FORMAT_S16: + case SampleFormat::S16: return AFMT_S16_NE; - case SAMPLE_FORMAT_S24_P32: + case SampleFormat::S24_P32: #ifdef AFMT_S24_NE return AFMT_S24_NE; #else return AFMT_QUERY; #endif - case SAMPLE_FORMAT_S32: + case SampleFormat::S32: #ifdef AFMT_S32_NE return AFMT_S32_NE; #else @@ -452,47 +452,47 @@ sample_format_to_oss(enum sample_format format) /** * Convert an OSS sample format to its MPD counterpart. Returns - * SAMPLE_FORMAT_UNDEFINED if there is no direct counterpart. + * SampleFormat::UNDEFINED if there is no direct counterpart. */ -static enum sample_format +static SampleFormat sample_format_from_oss(int format) { switch (format) { case AFMT_S8: - return SAMPLE_FORMAT_S8; + return SampleFormat::S8; case AFMT_S16_NE: - return SAMPLE_FORMAT_S16; + return SampleFormat::S16; #ifdef AFMT_S24_PACKED case AFMT_S24_PACKED: - return SAMPLE_FORMAT_S24_P32; + return SampleFormat::S24_P32; #endif #ifdef AFMT_S24_NE case AFMT_S24_NE: - return SAMPLE_FORMAT_S24_P32; + return SampleFormat::S24_P32; #endif #ifdef AFMT_S32_NE case AFMT_S32_NE: - return SAMPLE_FORMAT_S32; + return SampleFormat::S32; #endif default: - return SAMPLE_FORMAT_UNDEFINED; + return SampleFormat::UNDEFINED; } } /** * Probe one sample format. * - * @return the selected sample format or SAMPLE_FORMAT_UNDEFINED on + * @return the selected sample format or SampleFormat::UNDEFINED on * error */ static enum oss_setup_result -oss_probe_sample_format(int fd, enum sample_format sample_format, - enum sample_format *sample_format_r, +oss_probe_sample_format(int fd, SampleFormat sample_format, + SampleFormat *sample_format_r, int *oss_format_r, #ifdef AFMT_S24_PACKED PcmExport &pcm_export, @@ -509,7 +509,7 @@ oss_probe_sample_format(int fd, enum sample_format sample_format, "Failed to set sample format", error_r); #ifdef AFMT_S24_PACKED - if (result == UNSUPPORTED && sample_format == SAMPLE_FORMAT_S24_P32) { + if (result == UNSUPPORTED && sample_format == SampleFormat::S24_P32) { /* if the driver doesn't support padded 24 bit, try packed 24 bit */ oss_format = AFMT_S24_PACKED; @@ -523,7 +523,7 @@ oss_probe_sample_format(int fd, enum sample_format sample_format, return result; sample_format = sample_format_from_oss(oss_format); - if (sample_format == SAMPLE_FORMAT_UNDEFINED) + if (sample_format == SampleFormat::UNDEFINED) return UNSUPPORTED; *sample_format_r = sample_format; @@ -544,16 +544,16 @@ oss_probe_sample_format(int fd, enum sample_format sample_format, * specified format is not supported. */ static bool -oss_setup_sample_format(int fd, struct audio_format *audio_format, +oss_setup_sample_format(int fd, AudioFormat &audio_format, int *oss_format_r, #ifdef AFMT_S24_PACKED PcmExport &pcm_export, #endif GError **error_r) { - enum sample_format mpd_format; + SampleFormat mpd_format; enum oss_setup_result result = - oss_probe_sample_format(fd, sample_format(audio_format->format), + oss_probe_sample_format(fd, audio_format.format, &mpd_format, oss_format_r, #ifdef AFMT_S24_PACKED pcm_export, @@ -561,7 +561,7 @@ oss_setup_sample_format(int fd, struct audio_format *audio_format, error_r); switch (result) { case SUCCESS: - audio_format->format = mpd_format; + audio_format.format = mpd_format; return true; case ERROR: @@ -577,17 +577,17 @@ oss_setup_sample_format(int fd, struct audio_format *audio_format, /* the requested sample format is not available - probe for other formats supported by MPD */ - static const enum sample_format sample_formats[] = { - SAMPLE_FORMAT_S24_P32, - SAMPLE_FORMAT_S32, - SAMPLE_FORMAT_S16, - SAMPLE_FORMAT_S8, - SAMPLE_FORMAT_UNDEFINED /* sentinel */ + static const SampleFormat sample_formats[] = { + SampleFormat::S24_P32, + SampleFormat::S32, + SampleFormat::S16, + SampleFormat::S8, + SampleFormat::UNDEFINED /* sentinel */ }; - for (unsigned i = 0; sample_formats[i] != SAMPLE_FORMAT_UNDEFINED; ++i) { + for (unsigned i = 0; sample_formats[i] != SampleFormat::UNDEFINED; ++i) { mpd_format = sample_formats[i]; - if (mpd_format == audio_format->format) + if (mpd_format == audio_format.format) /* don't try that again */ continue; @@ -599,7 +599,7 @@ oss_setup_sample_format(int fd, struct audio_format *audio_format, error_r); switch (result) { case SUCCESS: - audio_format->format = mpd_format; + audio_format.format = mpd_format; return true; case ERROR: @@ -619,7 +619,7 @@ oss_setup_sample_format(int fd, struct audio_format *audio_format, * Sets up the OSS device which was opened before. */ static bool -oss_setup(OssOutput *od, struct audio_format *audio_format, +oss_setup(OssOutput *od, AudioFormat &audio_format, GError **error_r) { return oss_setup_channels(od->fd, audio_format, error_r) && @@ -687,7 +687,7 @@ oss_reopen(OssOutput *od, GError **error_r) } static bool -oss_output_open(struct audio_output *ao, struct audio_format *audio_format, +oss_output_open(struct audio_output *ao, AudioFormat &audio_format, GError **error) { OssOutput *od = (OssOutput *)ao; @@ -705,7 +705,7 @@ oss_output_open(struct audio_output *ao, struct audio_format *audio_format, return false; } - od->audio_format = *audio_format; + od->audio_format = audio_format; return true; } diff --git a/src/output/PipeOutputPlugin.cxx b/src/output/PipeOutputPlugin.cxx index 6e72eff12..f76dd04c1 100644 --- a/src/output/PipeOutputPlugin.cxx +++ b/src/output/PipeOutputPlugin.cxx @@ -95,7 +95,7 @@ pipe_output_finish(struct audio_output *ao) static bool pipe_output_open(struct audio_output *ao, - G_GNUC_UNUSED struct audio_format *audio_format, + G_GNUC_UNUSED AudioFormat &audio_format, G_GNUC_UNUSED GError **error) { PipeOutput *pd = (PipeOutput *)ao; diff --git a/src/output/PulseOutputPlugin.cxx b/src/output/PulseOutputPlugin.cxx index 5098e2adc..65526c8fb 100644 --- a/src/output/PulseOutputPlugin.cxx +++ b/src/output/PulseOutputPlugin.cxx @@ -578,7 +578,7 @@ pulse_output_setup_stream(PulseOutput *po, const pa_sample_spec *ss, } static bool -pulse_output_open(struct audio_output *ao, struct audio_format *audio_format, +pulse_output_open(struct audio_output *ao, AudioFormat &audio_format, GError **error_r) { PulseOutput *po = (PulseOutput *)ao; @@ -615,11 +615,11 @@ pulse_output_open(struct audio_output *ao, struct audio_format *audio_format, /* MPD doesn't support the other pulseaudio sample formats, so we just force MPD to send us everything as 16 bit */ - audio_format->format = SAMPLE_FORMAT_S16; + audio_format.format = SampleFormat::S16; ss.format = PA_SAMPLE_S16NE; - ss.rate = audio_format->sample_rate; - ss.channels = audio_format->channels; + ss.rate = audio_format.sample_rate; + ss.channels = audio_format.channels; /* create a stream .. */ diff --git a/src/output/RecorderOutputPlugin.cxx b/src/output/RecorderOutputPlugin.cxx index 6b31fcbc6..2e77463f0 100644 --- a/src/output/RecorderOutputPlugin.cxx +++ b/src/output/RecorderOutputPlugin.cxx @@ -192,7 +192,7 @@ RecorderOutput::EncoderToFile(GError **error_r) static bool recorder_output_open(struct audio_output *ao, - struct audio_format *audio_format, + AudioFormat &audio_format, GError **error_r) { RecorderOutput *recorder = (RecorderOutput *)ao; diff --git a/src/output/RoarOutputPlugin.cxx b/src/output/RoarOutputPlugin.cxx index 835c7cdd9..bf2bf1789 100644 --- a/src/output/RoarOutputPlugin.cxx +++ b/src/output/RoarOutputPlugin.cxx @@ -144,39 +144,41 @@ roar_finish(struct audio_output *ao) static void roar_use_audio_format(struct roar_audio_info *info, - struct audio_format *audio_format) + AudioFormat &audio_format) { - info->rate = audio_format->sample_rate; - info->channels = audio_format->channels; + info->rate = audio_format.sample_rate; + info->channels = audio_format.channels; info->codec = ROAR_CODEC_PCM_S; - switch (audio_format->format) { - case SAMPLE_FORMAT_UNDEFINED: + switch (audio_format.format) { + case SampleFormat::UNDEFINED: + case SampleFormat::FLOAT: + case SampleFormat::DSD: info->bits = 16; - audio_format->format = SAMPLE_FORMAT_S16; + audio_format.format = SampleFormat::S16; break; - case SAMPLE_FORMAT_S8: + case SampleFormat::S8: info->bits = 8; break; - case SAMPLE_FORMAT_S16: + case SampleFormat::S16: info->bits = 16; break; - case SAMPLE_FORMAT_S24_P32: + case SampleFormat::S24_P32: info->bits = 32; - audio_format->format = SAMPLE_FORMAT_S32; + audio_format.format = SampleFormat::S32; break; - case SAMPLE_FORMAT_S32: + case SampleFormat::S32: info->bits = 32; break; } } static bool -roar_open(struct audio_output *ao, struct audio_format *audio_format, GError **error) +roar_open(struct audio_output *ao, AudioFormat &audio_format, GError **error) { RoarOutput *self = (RoarOutput *)ao; const ScopeLock protect(self->mutex); diff --git a/src/output/ShoutOutputPlugin.cxx b/src/output/ShoutOutputPlugin.cxx index a0f75da1d..fbad24ec8 100644 --- a/src/output/ShoutOutputPlugin.cxx +++ b/src/output/ShoutOutputPlugin.cxx @@ -116,9 +116,8 @@ inline bool ShoutOutput::Configure(const config_param *param, GError **error_r) { - const struct audio_format *audio_format = - &base.config_audio_format; - if (!audio_format_fully_defined(audio_format)) { + const AudioFormat audio_format = base.config_audio_format; + if (!audio_format.IsFullyDefined()) { g_set_error(error_r, shout_output_quark(), 0, "Need full audio format specification"); return nullptr; @@ -269,10 +268,10 @@ ShoutOutput::Configure(const config_param *param, GError **error_r) char temp[11]; memset(temp, 0, sizeof(temp)); - snprintf(temp, sizeof(temp), "%u", audio_format->channels); + snprintf(temp, sizeof(temp), "%u", audio_format.channels); shout_set_audio_info(shout_conn, SHOUT_AI_CHANNELS, temp); - snprintf(temp, sizeof(temp), "%u", audio_format->sample_rate); + snprintf(temp, sizeof(temp), "%u", audio_format.sample_rate); shout_set_audio_info(shout_conn, SHOUT_AI_SAMPLERATE, temp); @@ -428,7 +427,7 @@ shout_connect(ShoutOutput *sd, GError **error) } static bool -my_shout_open_device(struct audio_output *ao, struct audio_format *audio_format, +my_shout_open_device(struct audio_output *ao, AudioFormat &audio_format, GError **error) { ShoutOutput *sd = (ShoutOutput *)ao; diff --git a/src/output/SolarisOutputPlugin.cxx b/src/output/SolarisOutputPlugin.cxx index c20de4a8b..81c793e21 100644 --- a/src/output/SolarisOutputPlugin.cxx +++ b/src/output/SolarisOutputPlugin.cxx @@ -113,7 +113,7 @@ solaris_output_finish(struct audio_output *ao) } static bool -solaris_output_open(struct audio_output *ao, struct audio_format *audio_format, +solaris_output_open(struct audio_output *ao, AudioFormat &audio_format, GError **error) { SolarisOutput *so = (SolarisOutput *)ao; @@ -122,7 +122,7 @@ solaris_output_open(struct audio_output *ao, struct audio_format *audio_format, /* support only 16 bit mono/stereo for now; nothing else has been tested */ - audio_format->format = SAMPLE_FORMAT_S16; + audio_format.format = SampleFormat::S16; /* open the device in non-blocking mode */ @@ -150,8 +150,8 @@ solaris_output_open(struct audio_output *ao, struct audio_format *audio_format, return false; } - info.play.sample_rate = audio_format->sample_rate; - info.play.channels = audio_format->channels; + info.play.sample_rate = audio_format.sample_rate; + info.play.channels = audio_format.channels; info.play.precision = 16; info.play.encoding = AUDIO_ENCODING_LINEAR; diff --git a/src/output/WinmmOutputPlugin.cxx b/src/output/WinmmOutputPlugin.cxx index 2418731a0..de6927bd2 100644 --- a/src/output/WinmmOutputPlugin.cxx +++ b/src/output/WinmmOutputPlugin.cxx @@ -142,7 +142,7 @@ winmm_output_finish(struct audio_output *ao) } static bool -winmm_output_open(struct audio_output *ao, struct audio_format *audio_format, +winmm_output_open(struct audio_output *ao, AudioFormat &audio_format, GError **error_r) { WinmmOutput *wo = (WinmmOutput *)ao; @@ -154,30 +154,32 @@ winmm_output_open(struct audio_output *ao, struct audio_format *audio_format, return false; } - switch (audio_format->format) { - case SAMPLE_FORMAT_S8: - case SAMPLE_FORMAT_S16: + switch (audio_format.format) { + case SampleFormat::S8: + case SampleFormat::S16: break; - case SAMPLE_FORMAT_S24_P32: - case SAMPLE_FORMAT_S32: - case SAMPLE_FORMAT_UNDEFINED: + case SampleFormat::S24_P32: + case SampleFormat::S32: + case SampleFormat::FLOAT: + case SampleFormat::DSD: + case SampleFormat::UNDEFINED: /* we havn't tested formats other than S16 */ - audio_format->format = SAMPLE_FORMAT_S16; + audio_format.format = SampleFormat::S16; break; } - if (audio_format->channels > 2) + if (audio_format.channels > 2) /* same here: more than stereo was not tested */ - audio_format->channels = 2; + audio_format.channels = 2; WAVEFORMATEX format; format.wFormatTag = WAVE_FORMAT_PCM; - format.nChannels = audio_format->channels; - format.nSamplesPerSec = audio_format->sample_rate; - format.nBlockAlign = audio_format_frame_size(audio_format); + format.nChannels = audio_format.channels; + format.nSamplesPerSec = audio_format.sample_rate; + format.nBlockAlign = audio_format.GetFrameSize(); format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; - format.wBitsPerSample = audio_format_sample_size(audio_format) * 8; + format.wBitsPerSample = audio_format.GetSampleSize() * 8; format.cbSize = 0; MMRESULT result = waveOutOpen(&wo->handle, wo->device_id, &format, |