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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user