Home | History | Annotate | Download | only in alsa_utils

Lines Matching refs:profile

61 static void profile_reset(alsa_device_profile* profile)
63 profile->card = profile->device = -1;
66 profile->formats[0] = PCM_FORMAT_INVALID;
67 profile->sample_rates[0] = 0;
68 profile->channel_counts[0] = 0;
70 profile->min_period_size = profile->max_period_size = 0;
71 profile->min_channel_count = profile->max_channel_count = DEFAULT_CHANNEL_COUNT;
73 profile->is_valid = false;
76 void profile_init(alsa_device_profile* profile, int direction)
78 profile->direction = direction;
79 profile_reset(profile);
82 bool profile_is_initialized(alsa_device_profile* profile)
84 return profile->card >= 0 && profile->device >= 0;
87 bool profile_is_valid(alsa_device_profile* profile) {
88 return profile->is_valid;
91 bool profile_is_cached_for(alsa_device_profile* profile, int card, int device) {
92 return card == profile->card && device == profile->device;
95 void profile_decache(alsa_device_profile* profile) {
96 profile_reset(profile);
110 unsigned profile_calc_min_period_size(alsa_device_profile* profile, unsigned sample_rate)
112 ALOGV("profile_calc_min_period_size(%p, rate:%d)", profile, sample_rate);
113 if (profile == NULL) {
119 if (num_sample_frames < profile->min_period_size) {
120 num_sample_frames = profile->min_period_size;
126 unsigned int profile_get_period_size(alsa_device_profile* profile, unsigned sample_rate)
128 unsigned int period_size = profile_calc_min_period_size(profile, sample_rate);
136 unsigned profile_get_default_sample_rate(alsa_device_profile* profile)
142 return profile_is_valid(profile) ? profile->sample_rates[0] : DEFAULT_SAMPLE_RATE;
145 bool profile_is_sample_rate_valid(alsa_device_profile* profile, unsigned rate)
147 if (profile_is_valid(profile)) {
149 for (index = 0; profile->sample_rates[index] != 0; index++) {
150 if (profile->sample_rates[index] == rate) {
164 enum pcm_format profile_get_default_format(alsa_device_profile* profile)
169 return profile_is_valid(profile) ? profile->formats[0] : DEFAULT_SAMPLE_FORMAT;
172 bool profile_is_format_valid(alsa_device_profile* profile, enum pcm_format fmt) {
173 if (profile_is_valid(profile)) {
175 for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) {
176 if (profile->formats[index] == fmt) {
190 unsigned profile_get_default_channel_count(alsa_device_profile* profile)
192 return profile_is_valid(profile) ? profile->channel_counts[0] : DEFAULT_CHANNEL_COUNT;
195 unsigned profile_get_closest_channel_count(alsa_device_profile* profile, unsigned count)
197 if (profile_is_valid(profile)) {
198 if (count < profile->min_channel_count) {
199 return profile->min_channel_count;
200 } else if (count > profile->max_channel_count) {
201 return profile->max_channel_count;
210 bool profile_is_channel_count_valid(alsa_device_profile* profile, unsigned count)
212 if (profile_is_initialized(profile)) {
213 return count >= profile->min_channel_count && count <= profile->max_channel_count;
219 static bool profile_test_sample_rate(alsa_device_profile* profile, unsigned rate)
221 struct pcm_config config = profile->default_config;
225 struct pcm * pcm = pcm_open(profile->card, profile->device,
226 profile->direction, &config);
236 static unsigned profile_enum_sample_rates(alsa_device_profile* profile, unsigned min, unsigned max)
242 num_entries < ARRAY_SIZE(profile->sample_rates) - 1;
245 && profile_test_sample_rate(profile, std_sample_rates[index])) {
246 profile->sample_rates[num_entries++] = std_sample_rates[index];
249 profile->sample_rates[num_entries] = 0; /* terminate */
253 static unsigned profile_enum_sample_formats(alsa_device_profile* profile, struct pcm_mask * mask)
273 profile->formats[num_written++] = format;
274 if (num_written == ARRAY_SIZE(profile->formats) - 1) {
285 profile->formats[num_written] = PCM_FORMAT_INVALID;
289 static unsigned profile_enum_channel_counts(alsa_device_profile* profile, unsigned min,
300 num_counts < ARRAY_SIZE(profile->channel_counts) - 1;
304 profile_test_channel_count(profile, channel_counts[index])*/) {
305 profile->channel_counts[num_counts++] = std_channel_counts[index];
312 profile->channel_counts[num_counts++] = std_channel_counts[0];
314 profile->channel_counts[num_counts] = 0;
321 static int read_alsa_device_config(alsa_device_profile * profile, struct pcm_config * config)
324 profile->card, profile->device, profile->direction);
326 if (profile->card < 0 || profile->device < 0) {
331 pcm_params_get(profile->card, profile->device, profile->direction);
336 profile->min_period_size = pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIOD_SIZE);
337 profile->max_period_size = pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIOD_SIZE);
339 profile->min_channel_count = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS);
340 profile->max_channel_count = pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS);
354 if (profile->direction == PCM_OUT &&
367 config->period_size = profile_calc_min_period_size(profile, config->rate);
382 bool profile_read_device_info(alsa_device_profile* profile)
384 if (!profile_is_initialized(profile)) {
389 read_alsa_device_config(profile, &profile->default_config);
391 profile->default_config.channels, profile->default_config.rate,
392 profile->default_config.format, profile->default_config.period_count,
393 profile->default_config.period_size);
395 struct pcm_params * alsa_hw_params = pcm_params_get(profile->card,
396 profile->device,
397 profile->direction);
404 profile_enum_sample_formats(profile, format_mask);
408 profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS),
413 profile, pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE),
416 profile->is_valid = true;
421 char * profile_get_sample_rate_strs(alsa_device_profile* profile)
436 for (index = 0; profile->sample_rates[index] != 0; index++) {
437 snprintf(numBuffer, sizeof(numBuffer), "%u", profile->sample_rates[index]);
454 char * profile_get_format_strs(alsa_device_profile* profile)
467 for (index = 0; profile->formats[index] != PCM_FORMAT_INVALID; index++) {
469 if (buffSize - curStrLen < strlen(format_string_map[profile->formats[index]])
479 curStrLen = strlcat(buffer, format_string_map[profile->formats[index]], buffSize);
485 char * profile_get_channel_count_strs(alsa_device_profile* profile)
521 const bool isOutProfile = profile->direction == PCM_OUT;
550 (channel_count = profile->channel_counts[index]) != 0;
585 void profile_dump(const alsa_device_profile* profile, int fd)
587 if (profile == NULL) {
588 dprintf(fd, " %s\n", "No USB Profile");
592 if (!profile->is_valid) {
593 dprintf(fd, " Profile is INVALID");
598 profile->card, profile->device, profile->direction == PCM_OUT ? "OUT" : "IN");
603 profile->formats[fmtIndex] != PCM_FORMAT_INVALID && fmtIndex < MAX_PROFILE_FORMATS;
605 dprintf(fd, "%d ", profile->formats[fmtIndex]);
612 profile->sample_rates[rateIndex] != 0 && rateIndex < MAX_PROFILE_SAMPLE_RATES;
614 dprintf(fd, "%u ", profile->sample_rates[rateIndex]);
621 profile->channel_counts[cntIndex] != 0 && cntIndex < MAX_PROFILE_CHANNEL_COUNTS;
623 dprintf(fd, "%u ", profile->channel_counts[cntIndex]);
628 profile->min_period_size,profile-> max_period_size);
630 profile->min_channel_count, profile->max_channel_count);
634 dprintf(fd, " channels: %d\n", profile->default_config.channels);
635 dprintf(fd, " rate: %d\n", profile->default_config.rate);
636 dprintf(fd, " period_size: %d\n", profile->default_config.period_size);
637 dprintf(fd, " period_count: %d\n", profile->default_config.period_count);
638 dprintf(fd, " format: %d\n", profile->default_config.format);