Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/pcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val);
* \{
*/

#define SND_PCM_LIMIT_HW_RATE_MIN 4000 /**< minimal allowed rate for hardware */
#define SND_PCM_LIMIT_HW_RATE_MAX 768000 /**< maximal allowed rate for hardware */
#define SND_PCM_LIMIT_HW_CHANNELS_MAX 512 /**< maximal number of channels for hardware */

int snd_pcm_hw_params_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);

int snd_pcm_hw_params_can_mmap_sample_resolution(const snd_pcm_hw_params_t *params);
Expand Down Expand Up @@ -925,6 +929,10 @@ int snd_pcm_hw_params_get_min_align(const snd_pcm_hw_params_t *params, snd_pcm_u
* \{
*/

#define SND_PCM_LIMIT_SW_RATE_MIN SND_PCM_LIMIT_HW_RATE_MIN /**< minimal allowed rate for software, should be not greater than minimal rate allowed by supported hardware */
#define SND_PCM_LIMIT_SW_RATE_MAX SND_PCM_LIMIT_HW_RATE_MAX /**< maximal allowed rate for software, should be not less than maximal rate allowed by supported hardware */
#define SND_PCM_LIMIT_SW_CHANNELS_MAX 10000 /**< maximal number of channels for software, should be not less than maximal number of channels supported by hardware */

size_t snd_pcm_sw_params_sizeof(void);
/** \hideinitializer
* \brief allocate an invalid #snd_pcm_sw_params_t using standard alloca
Expand Down
3 changes: 0 additions & 3 deletions include/pcm_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
* \{
*/

#define SND_PCM_PLUGIN_RATE_MIN 4000 /**< minimal rate for the rate plugin */
#define SND_PCM_PLUGIN_RATE_MAX 768000 /**< maximal rate for the rate plugin */

/* ROUTE_FLOAT should be set to 0 for machines without FP unit - like iPAQ */
#ifdef HAVE_SOFT_FLOAT
#define SND_PCM_PLUGIN_ROUTE_FLOAT 0 /**< use integers for route plugin */
Expand Down
8 changes: 4 additions & 4 deletions src/pcm/pcm_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,17 +726,17 @@ static int snd_pcm_plug_hw_refine_cprepare(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_
err = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_RATE, &rate_min, NULL);
if (err < 0)
return err;
if (rate_min < 4000) {
_snd_pcm_hw_param_set_min(params, SND_PCM_HW_PARAM_RATE, 4000, 0);
if (rate_min < SND_PCM_LIMIT_HW_RATE_MIN) {
_snd_pcm_hw_param_set_min(params, SND_PCM_HW_PARAM_RATE, SND_PCM_LIMIT_HW_RATE_MIN, 0);
if (snd_pcm_hw_param_empty(params, SND_PCM_HW_PARAM_RATE))
return -EINVAL;
}
/* HACK: to avoid overflow in PERIOD_SIZE code */
err = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_CHANNELS, &channels_max, NULL);
if (err < 0)
return err;
if (channels_max > 10000) {
_snd_pcm_hw_param_set_max(params, SND_PCM_HW_PARAM_CHANNELS, 10000, 0);
if (channels_max > SND_PCM_LIMIT_HW_CHANNELS_MAX) {
_snd_pcm_hw_param_set_max(params, SND_PCM_HW_PARAM_CHANNELS, SND_PCM_LIMIT_HW_CHANNELS_MAX, 0);
if (snd_pcm_hw_param_empty(params, SND_PCM_HW_PARAM_CHANNELS))
return -EINVAL;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pcm/pcm_rate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1528,8 +1528,8 @@ int snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
rate->srate = srate;
rate->sformat = sformat;

rate->rate_min = SND_PCM_PLUGIN_RATE_MIN;
rate->rate_max = SND_PCM_PLUGIN_RATE_MAX;
rate->rate_min = SND_PCM_LIMIT_SW_RATE_MIN;
rate->rate_max = SND_PCM_LIMIT_SW_RATE_MAX;
rate->plugin_version = SND_PCM_RATE_PLUGIN_VERSION;

err = snd_pcm_new(&pcm, SND_PCM_TYPE_RATE, name, slave->stream, slave->mode);
Expand Down
6 changes: 3 additions & 3 deletions src/pcm/pcm_rate_linear.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <inttypes.h>


/* LINEAR_DIV needs to be large enough to handle resampling from 768000 -> 8000 */
/* LINEAR_DIV needs to be large enough to handle resampling from SND_PCM_LIMIT_SW_RATE_MAX to SND_PCM_LIMIT_SW_RATE_MIN, like 768000 -> 8000 */
#define LINEAR_DIV_SHIFT 19
#define LINEAR_DIV (1<<LINEAR_DIV_SHIFT)

Expand Down Expand Up @@ -408,8 +408,8 @@ static void linear_close(void *obj)
static int get_supported_rates(ATTRIBUTE_UNUSED void *rate,
unsigned int *rate_min, unsigned int *rate_max)
{
*rate_min = SND_PCM_PLUGIN_RATE_MIN;
*rate_max = SND_PCM_PLUGIN_RATE_MAX;
*rate_min = SND_PCM_LIMIT_SW_RATE_MIN;
*rate_max = SND_PCM_LIMIT_SW_RATE_MAX;
return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions src/pcm/pcm_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ int snd_spcm_init(snd_pcm_t *pcm,
unsigned int buffer_time;

assert(pcm);
assert(rate >= 5000 && rate <= 786000);
assert(channels >= 1 && channels <= 512);
assert(rate >= SND_PCM_LIMIT_HW_RATE_MIN && rate <= SND_PCM_LIMIT_HW_RATE_MAX);
assert(channels >= 1 && channels <= SND_PCM_LIMIT_HW_CHANNELS_MAX);

rrate = rate;
err = set_buffer_time(latency, &buffer_time);
Expand Down Expand Up @@ -227,8 +227,8 @@ int snd_spcm_init_duplex(snd_pcm_t *playback_pcm,

assert(playback_pcm);
assert(capture_pcm);
assert(rate >= 5000 && rate <= 768000);
assert(channels >= 1 && channels <= 512);
assert(rate >= SND_PCM_LIMIT_HW_RATE_MIN && rate <= SND_PCM_LIMIT_HW_RATE_MAX);
assert(channels >= 1 && channels <= SND_PCM_LIMIT_HW_CHANNELS_MAX);

pcms[0] = playback_pcm;
pcms[1] = capture_pcm;
Expand Down
2 changes: 1 addition & 1 deletion test/latency.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ int main(int argc, char *argv[])
break;
case 'r':
err = atoi(optarg);
rate = err >= 4000 && err < 200000 ? err : 44100;
rate = err >= SND_PCM_LIMIT_SW_RATE_MIN && err < SND_PCM_LIMIT_SW_RATE_MAX ? err : 44100;
break;
case 'B':
err = atoi(optarg);
Expand Down
6 changes: 3 additions & 3 deletions test/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,13 +810,13 @@ int main(int argc, char *argv[])
break;
case 'r':
rate = atoi(optarg);
rate = rate < 4000 ? 4000 : rate;
rate = rate > 196000 ? 196000 : rate;
rate = rate < SND_PCM_LIMIT_HW_RATE_MIN ? SND_PCM_LIMIT_HW_RATE_MIN : rate;
rate = rate > SND_PCM_LIMIT_HW_RATE_MAX ? SND_PCM_LIMIT_HW_RATE_MAX : rate;
break;
case 'c':
channels = atoi(optarg);
channels = channels < 1 ? 1 : channels;
channels = channels > 1024 ? 1024 : channels;
channels = channels > SND_PCM_LIMIT_HW_CHANNELS_MAX ? SND_PCM_LIMIT_HW_CHANNELS_MAX : channels;
break;
case 'f':
freq = atoi(optarg);
Expand Down
Loading