diff options
author | Max Kellermann <max@duempel.org> | 2009-11-10 17:11:34 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-12-02 22:29:50 +0100 |
commit | c412d6251e9cd3abe735b7622af4003502e54f72 (patch) | |
tree | 7344c13f62e4cc788c830c05d21bb7b5b47f5866 /src/output | |
parent | 68c2cfbb4067b2292e1ff1d4e7716ff370903f84 (diff) | |
download | mpd-c412d6251e9cd3abe735b7622af4003502e54f72.tar.gz mpd-c412d6251e9cd3abe735b7622af4003502e54f72.tar.xz mpd-c412d6251e9cd3abe735b7622af4003502e54f72.zip |
audio_format: changed "bits" to "enum sample_format"
This patch prepares support for floating point samples (and probably
other formats). It changes the meaning of the "bits" attribute from a
bit count to a symbolic value.
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/alsa_plugin.c | 73 | ||||
-rw-r--r-- | src/output/ao_plugin.c | 23 | ||||
-rw-r--r-- | src/output/jack_output_plugin.c | 11 | ||||
-rw-r--r-- | src/output/mvp_plugin.c | 12 | ||||
-rw-r--r-- | src/output/openal_plugin.c | 20 | ||||
-rw-r--r-- | src/output/oss_plugin.c | 9 | ||||
-rw-r--r-- | src/output/osx_plugin.c | 19 | ||||
-rw-r--r-- | src/output/pulse_output_plugin.c | 2 | ||||
-rw-r--r-- | src/output/solaris_output_plugin.c | 4 |
9 files changed, 108 insertions, 65 deletions
diff --git a/src/output/alsa_plugin.c b/src/output/alsa_plugin.c index 2c642015d..b7325de07 100644 --- a/src/output/alsa_plugin.c +++ b/src/output/alsa_plugin.c @@ -185,13 +185,22 @@ alsa_test_default_device(void) static snd_pcm_format_t get_bitformat(const struct audio_format *af) { - switch (af->bits) { - case 8: return SND_PCM_FORMAT_S8; - case 16: return SND_PCM_FORMAT_S16; - case 24: return SND_PCM_FORMAT_S24; - case 32: return SND_PCM_FORMAT_S32; + switch (af->format) { + case SAMPLE_FORMAT_S8: + return SND_PCM_FORMAT_S8; + + case SAMPLE_FORMAT_S16: + return SND_PCM_FORMAT_S16; + + case SAMPLE_FORMAT_S24_P32: + return SND_PCM_FORMAT_S24; + + case SAMPLE_FORMAT_S32: + return SND_PCM_FORMAT_S32; + + default: + return SND_PCM_FORMAT_UNKNOWN; } - return SND_PCM_FORMAT_UNKNOWN; } static snd_pcm_format_t @@ -264,61 +273,67 @@ configure_hw: err = snd_pcm_hw_params_set_format(ad->pcm, hwparams, byteswap_bitformat(bitformat)); if (err == 0) { - g_debug("ALSA device \"%s\": converting %u bit to reverse-endian\n", - alsa_device(ad), audio_format->bits); + g_debug("ALSA device \"%s\": converting format %s to reverse-endian", + alsa_device(ad), + sample_format_to_string(audio_format->format)); audio_format->reverse_endian = 1; } } - if (err == -EINVAL && (audio_format->bits == 24 || - audio_format->bits == 16)) { + if (err == -EINVAL && (audio_format->format == SAMPLE_FORMAT_S24_P32 || + audio_format->format == SAMPLE_FORMAT_S16)) { /* fall back to 32 bit, let pcm_convert.c do the conversion */ err = snd_pcm_hw_params_set_format(ad->pcm, hwparams, SND_PCM_FORMAT_S32); if (err == 0) { - g_debug("ALSA device \"%s\": converting %u bit to 32 bit\n", - alsa_device(ad), audio_format->bits); - audio_format->bits = 32; + g_debug("ALSA device \"%s\": converting format %s to 32 bit\n", + alsa_device(ad), + sample_format_to_string(audio_format->format)); + audio_format->format = SAMPLE_FORMAT_S32; } } - if (err == -EINVAL && (audio_format->bits == 24 || - audio_format->bits == 16)) { + if (err == -EINVAL && (audio_format->format == SAMPLE_FORMAT_S24_P32 || + audio_format->format == SAMPLE_FORMAT_S16)) { /* fall back to 32 bit, let pcm_convert.c do the conversion */ err = snd_pcm_hw_params_set_format(ad->pcm, hwparams, byteswap_bitformat(SND_PCM_FORMAT_S32)); if (err == 0) { - g_debug("ALSA device \"%s\": converting %u bit to 32 bit backward-endian\n", - alsa_device(ad), audio_format->bits); - audio_format->bits = 32; + g_debug("ALSA device \"%s\": converting format %s to 32 bit backward-endian\n", + alsa_device(ad), + sample_format_to_string(audio_format->format)); + audio_format->format = SAMPLE_FORMAT_S32; audio_format->reverse_endian = 1; } } - if (err == -EINVAL && audio_format->bits != 16) { + if (err == -EINVAL && audio_format->format != SAMPLE_FORMAT_S16) { /* fall back to 16 bit, let pcm_convert.c do the conversion */ err = snd_pcm_hw_params_set_format(ad->pcm, hwparams, SND_PCM_FORMAT_S16); if (err == 0) { - g_debug("ALSA device \"%s\": converting %u bit to 16 bit\n", - alsa_device(ad), audio_format->bits); - audio_format->bits = 16; + g_debug("ALSA device \"%s\": converting format %s to 16 bit\n", + alsa_device(ad), + sample_format_to_string(audio_format->format)); + audio_format->format = SAMPLE_FORMAT_S16; } } - if (err == -EINVAL && audio_format->bits != 16) { + if (err == -EINVAL && audio_format->format != SAMPLE_FORMAT_S16) { /* fall back to 16 bit, let pcm_convert.c do the conversion */ err = snd_pcm_hw_params_set_format(ad->pcm, hwparams, byteswap_bitformat(SND_PCM_FORMAT_S16)); if (err == 0) { - g_debug("ALSA device \"%s\": converting %u bit to 16 bit backward-endian\n", - alsa_device(ad), audio_format->bits); - audio_format->bits = 16; + g_debug("ALSA device \"%s\": converting format %s to 16 bit backward-endian\n", + alsa_device(ad), + sample_format_to_string(audio_format->format)); + audio_format->format = SAMPLE_FORMAT_S16; audio_format->reverse_endian = 1; } } if (err < 0) { g_set_error(error, alsa_output_quark(), err, - "ALSA device \"%s\" does not support %u bit audio: %s", - alsa_device(ad), audio_format->bits, + "ALSA device \"%s\" does not support format %s: %s", + alsa_device(ad), + sample_format_to_string(audio_format->format), snd_strerror(-err)); return false; } @@ -449,7 +464,7 @@ alsa_open(void *data, struct audio_format *audio_format, GError **error) /* sample format is not supported by this plugin - fall back to 16 bit samples */ - audio_format->bits = 16; + audio_format->format = SAMPLE_FORMAT_S16; bitformat = SND_PCM_FORMAT_S16; } diff --git a/src/output/ao_plugin.c b/src/output/ao_plugin.c index d69175272..7afca0db2 100644 --- a/src/output/ao_plugin.c +++ b/src/output/ao_plugin.c @@ -170,13 +170,24 @@ ao_output_open(void *data, struct audio_format *audio_format, ao_sample_format format; struct ao_data *ad = (struct ao_data *)data; - /* support for 24 bit samples in libao is currently dubious, - and until we have sorted that out, resample everything to - 16 bit */ - if (audio_format->bits > 16) - audio_format->bits = 16; + switch (audio_format->format) { + case SAMPLE_FORMAT_S8: + format.bits = 8; + break; + + case SAMPLE_FORMAT_S16: + format.bits = 16; + break; + + default: + /* 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; + format.bits = 16; + break; + } - format.bits = audio_format->bits; format.rate = audio_format->sample_rate; format.byte_format = AO_FMT_NATIVE; format.channels = audio_format->channels; diff --git a/src/output/jack_output_plugin.c b/src/output/jack_output_plugin.c index 7e5a52993..f50bc37d0 100644 --- a/src/output/jack_output_plugin.c +++ b/src/output/jack_output_plugin.c @@ -157,8 +157,9 @@ set_audioformat(struct jack_data *jd, struct audio_format *audio_format) else if (audio_format->channels > jd->num_source_ports) audio_format->channels = 2; - if (audio_format->bits != 16 && audio_format->bits != 24) - audio_format->bits = 24; + if (audio_format->format != SAMPLE_FORMAT_S16 && + audio_format->format != SAMPLE_FORMAT_S24_P32) + audio_format->format = SAMPLE_FORMAT_S24_P32; } static void @@ -606,13 +607,13 @@ static void mpd_jack_write_samples(struct jack_data *jd, const void *src, unsigned num_samples) { - switch (jd->audio_format.bits) { - case 16: + switch (jd->audio_format.format) { + case SAMPLE_FORMAT_S16: mpd_jack_write_samples_16(jd, (const int16_t*)src, num_samples); break; - case 24: + case SAMPLE_FORMAT_S24_P32: mpd_jack_write_samples_24(jd, (const int32_t*)src, num_samples); break; diff --git a/src/output/mvp_plugin.c b/src/output/mvp_plugin.c index 5a9a9b48b..86f147e5a 100644 --- a/src/output/mvp_plugin.c +++ b/src/output/mvp_plugin.c @@ -172,19 +172,19 @@ mvp_set_pcm_params(struct mvp_data *md, struct audio_format *audio_format, } /* 0,1=24bit(24) , 2,3=16bit */ - switch (audio_format->bits) { - case 16: + switch (audio_format->format) { + case SAMPLE_FORMAT_S16: mix[1] = 2; break; - case 24: + case SAMPLE_FORMAT_S24_P32: mix[1] = 0; break; default: - g_debug("unsupported sample format %u - falling back to stereo", - audio_format->bits); - audio_format->bits = 16; + g_debug("unsupported sample format %s - falling back to 16 bit", + sample_format_to_string(audio_format->format)); + audio_format->format = SAMPLE_FORMAT_S16; mix[1] = 2; break; } diff --git a/src/output/openal_plugin.c b/src/output/openal_plugin.c index 8fda110e1..0aded4d9a 100644 --- a/src/output/openal_plugin.c +++ b/src/output/openal_plugin.c @@ -58,25 +58,29 @@ openal_output_quark(void) static ALenum openal_audio_format(struct audio_format *audio_format) { - /* Only 8 and 16 bit samples are supported */ - if (audio_format->bits != 16 && audio_format->bits != 8) - audio_format->bits = 16; - - switch (audio_format->bits) - { - case 16: + switch (audio_format->format) { + case SAMPLE_FORMAT_S16: if (audio_format->channels == 2) return AL_FORMAT_STEREO16; if (audio_format->channels == 1) return AL_FORMAT_MONO16; break; - case 8: + case SAMPLE_FORMAT_S8: if (audio_format->channels == 2) return AL_FORMAT_STEREO8; if (audio_format->channels == 1) return AL_FORMAT_MONO8; break; + + default: + /* fall back to 16 bit */ + audio_format->format = SAMPLE_FORMAT_S16; + if (audio_format->channels == 2) + return AL_FORMAT_STEREO16; + if (audio_format->channels == 1) + return AL_FORMAT_MONO16; + break; } return 0; diff --git a/src/output/oss_plugin.c b/src/output/oss_plugin.c index b02d7d62e..f16374e39 100644 --- a/src/output/oss_plugin.c +++ b/src/output/oss_plugin.c @@ -490,17 +490,18 @@ oss_setup(struct oss_data *od, GError **error) } od->audio_format.sample_rate = tmp; - switch (od->audio_format.bits) { - case 8: + switch (od->audio_format.format) { + case SAMPLE_FORMAT_S8: tmp = AFMT_S8; break; - case 16: + + case SAMPLE_FORMAT_S16: tmp = AFMT_S16_MPD; break; default: /* not supported by OSS - fall back to 16 bit */ - od->audio_format.bits = 16; + od->audio_format.format = SAMPLE_FORMAT_S16; tmp = AFMT_S16_MPD; break; } diff --git a/src/output/osx_plugin.c b/src/output/osx_plugin.c index afcd143b3..22b742ee5 100644 --- a/src/output/osx_plugin.c +++ b/src/output/osx_plugin.c @@ -166,9 +166,6 @@ osx_output_open(void *data, struct audio_format *audio_format, GError **error) OSStatus status; ComponentResult result; - if (audio_format->bits > 16) - audio_format->bits = 16; - desc.componentType = kAudioUnitType_Output; desc.componentSubType = kAudioUnitSubType_DefaultOutput; desc.componentManufacturer = kAudioUnitManufacturer_Apple; @@ -226,7 +223,21 @@ osx_output_open(void *data, struct audio_format *audio_format, GError **error) stream_description.mFramesPerPacket = 1; stream_description.mBytesPerFrame = stream_description.mBytesPerPacket; stream_description.mChannelsPerFrame = audio_format->channels; - stream_description.mBitsPerChannel = audio_format->bits; + + switch (audio_format->format) { + case SAMPLE_FORMAT_S8: + stream_description.mBitsPerChannel = 8; + break; + + case SAMPLE_FORMAT_S16: + stream_description.mBitsPerChannel = 16; + break; + + default: + audio_format->format = SAMPLE_FORMAT_S16; + stream_description.mBitsPerChannel = 16; + break; + } result = AudioUnitSetProperty(od->au, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, diff --git a/src/output/pulse_output_plugin.c b/src/output/pulse_output_plugin.c index 3da1b3593..a64157920 100644 --- a/src/output/pulse_output_plugin.c +++ b/src/output/pulse_output_plugin.c @@ -467,7 +467,7 @@ pulse_output_open(void *data, 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->bits = 16; + audio_format->format = SAMPLE_FORMAT_S16; ss.format = PA_SAMPLE_S16NE; ss.rate = audio_format->sample_rate; diff --git a/src/output/solaris_output_plugin.c b/src/output/solaris_output_plugin.c index b187630ee..fe84068f1 100644 --- a/src/output/solaris_output_plugin.c +++ b/src/output/solaris_output_plugin.c @@ -89,7 +89,7 @@ solaris_output_open(void *data, struct audio_format *audio_format, /* support only 16 bit mono/stereo for now; nothing else has been tested */ - audio_format->bits = 16; + audio_format->format = SAMPLE_FORMAT_S16; /* open the device in non-blocking mode */ @@ -119,7 +119,7 @@ solaris_output_open(void *data, struct audio_format *audio_format, info.play.sample_rate = audio_format->sample_rate; info.play.channels = audio_format->channels; - info.play.precision = audio_format->bits; + info.play.precision = 16; info.play.encoding = AUDIO_ENCODING_LINEAR; ret = ioctl(so->fd, AUDIO_SETINFO, &info); |