From aa813e1f392847c6b403c06ac96a0e7515d53cc6 Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Mon, 15 Jan 2001 15:15:24 +0000 Subject: [PATCH] Uniformed some internal names. Bug fixes --- src/pcm/pcm.c | 14 +++++++------- src/pcm/pcm_adpcm.c | 2 -- src/pcm/pcm_alaw.c | 2 -- src/pcm/pcm_copy.c | 2 -- src/pcm/pcm_file.c | 4 ++-- src/pcm/pcm_linear.c | 2 -- src/pcm/pcm_local.h | 4 ++-- src/pcm/pcm_mmap.c | 10 +++++----- src/pcm/pcm_mulaw.c | 2 -- src/pcm/pcm_multi.c | 2 -- src/pcm/pcm_params.c | 6 +++--- src/pcm/pcm_plug.c | 34 ++++++++++++++++++++-------------- src/pcm/pcm_rate.c | 2 -- src/pcm/pcm_route.c | 5 ++--- src/pcm/pcm_share.c | 2 -- src/pcm/pcm_shm.c | 9 ++++----- 16 files changed, 45 insertions(+), 57 deletions(-) diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 2cbce95e..1a364077 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -572,28 +572,28 @@ snd_pcm_sframes_t snd_pcm_bytes_to_frames(snd_pcm_t *pcm, ssize_t bytes) { assert(pcm); assert(pcm->setup); - return bytes * 8 / pcm->bits_per_frame; + return bytes * 8 / pcm->frame_bits; } ssize_t snd_pcm_frames_to_bytes(snd_pcm_t *pcm, snd_pcm_sframes_t frames) { assert(pcm); assert(pcm->setup); - return frames * pcm->bits_per_frame / 8; + return frames * pcm->frame_bits / 8; } int snd_pcm_bytes_to_samples(snd_pcm_t *pcm, ssize_t bytes) { assert(pcm); assert(pcm->setup); - return bytes * 8 / pcm->bits_per_sample; + return bytes * 8 / pcm->sample_bits; } ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *pcm, int samples) { assert(pcm); assert(pcm->setup); - return samples * pcm->bits_per_sample / 8; + return samples * pcm->sample_bits / 8; } int snd_pcm_open(snd_pcm_t **pcmp, char *name, @@ -739,8 +739,8 @@ void snd_pcm_areas_from_buf(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas, unsigned int channels = pcm->channels; for (channel = 0; channel < channels; ++channel, ++areas) { areas->addr = buf; - areas->first = channel * pcm->bits_per_sample; - areas->step = pcm->bits_per_frame; + areas->first = channel * pcm->sample_bits; + areas->step = pcm->frame_bits; } } @@ -752,7 +752,7 @@ void snd_pcm_areas_from_bufs(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas, for (channel = 0; channel < channels; ++channel, ++areas, ++bufs) { areas->addr = *bufs; areas->first = 0; - areas->step = pcm->bits_per_sample; + areas->step = pcm->sample_bits; } } diff --git a/src/pcm/pcm_adpcm.c b/src/pcm/pcm_adpcm.c index 31c3f76c..d31170e3 100644 --- a/src/pcm/pcm_adpcm.c +++ b/src/pcm/pcm_adpcm.c @@ -419,8 +419,6 @@ static int snd_pcm_adpcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) SND_PCM_HW_PARBIT_TICK_TIME; err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = snd_pcm_hw_params(slave, &sparams); params->cmask = 0; sparams.cmask = ~0U; diff --git a/src/pcm/pcm_alaw.c b/src/pcm/pcm_alaw.c index 1be95dbf..a4167a60 100644 --- a/src/pcm/pcm_alaw.c +++ b/src/pcm/pcm_alaw.c @@ -301,8 +301,6 @@ static int snd_pcm_alaw_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) SND_PCM_HW_PARBIT_TICK_TIME; err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = snd_pcm_hw_params(slave, &sparams); params->cmask = 0; sparams.cmask = ~0U; diff --git a/src/pcm/pcm_copy.c b/src/pcm/pcm_copy.c index e2bb724e..d5773dce 100644 --- a/src/pcm/pcm_copy.c +++ b/src/pcm/pcm_copy.c @@ -76,8 +76,6 @@ static int snd_pcm_copy_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) links = ~SND_PCM_HW_PARBIT_ACCESS; err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = snd_pcm_hw_params(slave, &sparams); params->cmask = 0; sparams.cmask = ~0U; diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index ca2f8c80..3da9043f 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -335,8 +335,8 @@ static int snd_pcm_file_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) for (channel = 0; channel < slave->channels; ++channel) { snd_pcm_channel_area_t *a = &file->wbuf_areas[channel]; a->addr = file->wbuf; - a->first = slave->bits_per_sample * channel; - a->step = slave->bits_per_frame; + a->first = slave->sample_bits * channel; + a->step = slave->frame_bits; } return 0; } diff --git a/src/pcm/pcm_linear.c b/src/pcm/pcm_linear.c index 4c30e9e9..1d331338 100644 --- a/src/pcm/pcm_linear.c +++ b/src/pcm/pcm_linear.c @@ -153,8 +153,6 @@ static int snd_pcm_linear_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) SND_PCM_HW_PARBIT_TICK_TIME; err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = snd_pcm_hw_params(slave, &sparams); params->cmask = 0; sparams.cmask = ~0U; diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index c465d96c..5338b8a3 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -113,8 +113,8 @@ struct _snd_pcm { unsigned int rate_den; /* rate denominator */ snd_pcm_uframes_t fifo_size; /* chip FIFO size in frames */ snd_pcm_uframes_t buffer_size; - unsigned int bits_per_sample; - unsigned int bits_per_frame; + unsigned int sample_bits; + unsigned int frame_bits; snd_pcm_uframes_t *appl_ptr; snd_pcm_uframes_t min_align; volatile snd_pcm_uframes_t *hw_ptr; diff --git a/src/pcm/pcm_mmap.c b/src/pcm/pcm_mmap.c index d362aae6..27c4ebc9 100644 --- a/src/pcm/pcm_mmap.c +++ b/src/pcm/pcm_mmap.c @@ -230,13 +230,13 @@ int snd_pcm_channel_info_shm(snd_pcm_t *pcm, snd_pcm_channel_info_t *info, switch (pcm->access) { case SND_PCM_ACCESS_MMAP_INTERLEAVED: case SND_PCM_ACCESS_RW_INTERLEAVED: - info->first = info->channel * pcm->bits_per_sample; - info->step = pcm->bits_per_frame; + info->first = info->channel * pcm->sample_bits; + info->step = pcm->frame_bits; break; case SND_PCM_ACCESS_MMAP_NONINTERLEAVED: case SND_PCM_ACCESS_RW_NONINTERLEAVED: info->first = 0; - info->step = pcm->bits_per_sample; + info->step = pcm->sample_bits; break; default: assert(0); @@ -281,7 +281,7 @@ int snd_pcm_mmap(snd_pcm_t *pcm) unsigned int c1; if (!i->addr) { char *ptr; - size_t size = i->first + i->step * (pcm->buffer_size - 1) + pcm->bits_per_sample; + size_t size = i->first + i->step * (pcm->buffer_size - 1) + pcm->sample_bits; for (c1 = c + 1; c1 < pcm->channels; ++c1) { snd_pcm_channel_info_t *i1 = &pcm->mmap_channels[c1]; size_t s; @@ -300,7 +300,7 @@ int snd_pcm_mmap(snd_pcm_t *pcm) default: assert(0); } - s = i1->first + i1->step * (pcm->buffer_size - 1) + pcm->bits_per_sample; + s = i1->first + i1->step * (pcm->buffer_size - 1) + pcm->sample_bits; if (s > size) size = s; } diff --git a/src/pcm/pcm_mulaw.c b/src/pcm/pcm_mulaw.c index ff67c6d3..5904c5ae 100644 --- a/src/pcm/pcm_mulaw.c +++ b/src/pcm/pcm_mulaw.c @@ -318,8 +318,6 @@ static int snd_pcm_mulaw_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) SND_PCM_HW_PARBIT_TICK_TIME; err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = snd_pcm_hw_params(slave, &sparams); params->cmask = 0; sparams.cmask = ~0U; diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c index 28719ae8..a6be1e4c 100644 --- a/src/pcm/pcm_multi.c +++ b/src/pcm/pcm_multi.c @@ -212,8 +212,6 @@ static int snd_pcm_multi_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) multi->slaves[k].channels_count, 0); err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = snd_pcm_hw_params(slave, &sparams); params->cmask = 0; sparams.cmask = ~0U; diff --git a/src/pcm/pcm_params.c b/src/pcm/pcm_params.c index 336e45f1..b9cb8a2e 100644 --- a/src/pcm/pcm_params.c +++ b/src/pcm/pcm_params.c @@ -2244,9 +2244,9 @@ int snd_pcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) pcm->period_size = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_PERIOD_SIZE, 0); pcm->buffer_size = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_BUFFER_SIZE, 0); pcm->tick_time = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_TICK_TIME, 0); - pcm->bits_per_sample = snd_pcm_format_physical_width(pcm->format); - pcm->bits_per_frame = pcm->bits_per_sample * pcm->channels; - fb = pcm->bits_per_frame; + pcm->sample_bits = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_SAMPLE_BITS, 0); + pcm->frame_bits = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FRAME_BITS, 0); + fb = pcm->frame_bits; min_align = 1; while (fb % 8) { fb *= 2; diff --git a/src/pcm/pcm_plug.c b/src/pcm/pcm_plug.c index 87b31112..4fb45f6b 100644 --- a/src/pcm/pcm_plug.c +++ b/src/pcm/pcm_plug.c @@ -312,12 +312,15 @@ static int snd_pcm_plug_hw_link(snd_pcm_hw_params_t *params, if (format_never || channels_never || rate_never) { mask_t *mmap_mask = alloca(mask_sizeof()); mask_load(mmap_mask, SND_PCM_ACCBIT_MMAP); - _snd_pcm_hw_param_mask(sparams, SND_PCM_HW_PARAM_ACCESS, - mmap_mask); + err = _snd_pcm_hw_param_mask(sparams, SND_PCM_HW_PARAM_ACCESS, + mmap_mask); + assert(err >= 0); } else mask_union(access_mask, snd_pcm_hw_param_value_mask(sparams, SND_PCM_HW_PARAM_ACCESS)); - _snd_pcm_hw_param_mask(params, SND_PCM_HW_PARAM_ACCESS, - access_mask); + err = _snd_pcm_hw_param_mask(params, SND_PCM_HW_PARAM_ACCESS, + access_mask); + if (err < 0) + return err; sparams->cmask |= scmask; return snd_pcm_generic_hw_link(params, sparams, slave, links); } @@ -391,8 +394,8 @@ static void snd_pcm_plug_clear(snd_pcm_t *pcm) } typedef struct { - unsigned int access; - unsigned int format; + snd_pcm_access_t access; + snd_pcm_format_t format; unsigned int channels; unsigned int rate; } snd_pcm_plug_params_t; @@ -603,18 +606,21 @@ static int snd_pcm_plug_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) clt_params.channels = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_CHANNELS, 0); clt_params.rate = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_RATE, 0); - if (snd_pcm_hw_param_test(params, SND_PCM_HW_PARAM_ACCESS, clt_params.access)) - slv_params.access = clt_params.access; - else - slv_params.access = snd_pcm_hw_param_first(slave, &sparams, SND_PCM_HW_PARAM_ACCESS, 0); slv_params.format = snd_pcm_hw_param_value(&sparams, SND_PCM_HW_PARAM_FORMAT, 0); slv_params.channels = snd_pcm_hw_param_value(&sparams, SND_PCM_HW_PARAM_CHANNELS, 0); slv_params.rate = snd_pcm_hw_param_value(&sparams, SND_PCM_HW_PARAM_RATE, 0); - snd_pcm_plug_clear(pcm); - err = snd_pcm_plug_insert_plugins(pcm, &clt_params, &slv_params); - if (err < 0) - return err; + if (clt_params.format == slv_params.format && + clt_params.channels == slv_params.channels && + clt_params.rate == slv_params.rate && + snd_pcm_hw_param_test(params, SND_PCM_HW_PARAM_ACCESS, clt_params.access)) + slv_params.access = clt_params.access; + else { + slv_params.access = snd_pcm_hw_param_first(slave, &sparams, SND_PCM_HW_PARAM_ACCESS, 0); + err = snd_pcm_plug_insert_plugins(pcm, &clt_params, &slv_params); + if (err < 0) + return err; + } err = snd_pcm_hw_params(plug->slave, params); if (err < 0) { snd_pcm_plug_clear(pcm); diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c index 351d853f..23be3f4e 100644 --- a/src/pcm/pcm_rate.c +++ b/src/pcm/pcm_rate.c @@ -335,8 +335,6 @@ static int snd_pcm_rate_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = snd_pcm_hw_params(slave, &sparams); params->cmask = 0; sparams.cmask = ~0U; diff --git a/src/pcm/pcm_route.c b/src/pcm/pcm_route.c index c9125cb4..761cb82a 100644 --- a/src/pcm/pcm_route.c +++ b/src/pcm/pcm_route.c @@ -499,7 +499,8 @@ static int snd_pcm_route_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) snd_pcm_t *slave = route->plug.slave; int err; snd_pcm_hw_params_t sparams; - unsigned int links = (SND_PCM_HW_PARBIT_PERIODS | + unsigned int links = (SND_PCM_HW_PARBIT_RATE | + SND_PCM_HW_PARBIT_PERIODS | SND_PCM_HW_PARBIT_PERIOD_SIZE | SND_PCM_HW_PARBIT_PERIOD_TIME | SND_PCM_HW_PARBIT_BUFFER_SIZE | @@ -534,8 +535,6 @@ static int snd_pcm_route_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = snd_pcm_hw_params(slave, &sparams); params->cmask = 0; sparams.cmask = ~0U; diff --git a/src/pcm/pcm_share.c b/src/pcm/pcm_share.c index ef7ac47e..99fa5b71 100644 --- a/src/pcm/pcm_share.c +++ b/src/pcm/pcm_share.c @@ -584,8 +584,6 @@ static int snd_pcm_share_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) share->channels_count, 0); err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = snd_pcm_hw_params(slave->pcm, &sparams); params->cmask = 0; sparams.cmask = ~0U; diff --git a/src/pcm/pcm_shm.c b/src/pcm/pcm_shm.c index c6b1e5bb..1da7f338 100644 --- a/src/pcm/pcm_shm.c +++ b/src/pcm/pcm_shm.c @@ -235,13 +235,12 @@ static int snd_pcm_shm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) saccess_mask); err = snd_pcm_hw_params_refine(&sparams, links, params); assert(err >= 0); - err = _snd_pcm_hw_refine(&sparams); - assert(err >= 0); err = _snd_pcm_shm_hw_params(pcm, &sparams); - if (err < 0) { - snd_pcm_hw_params_refine(params, links, &sparams); + params->cmask = 0; + sparams.cmask = ~0U; + snd_pcm_hw_params_refine(params, links, &sparams); + if (err < 0) return err; - } return 0; } -- 2.47.1