sound examples: Check if setting property was successful
MFC after: 1 week Reviewed by: christos Differential Revision: https://reviews.freebsd.org/D54038
This commit is contained in:
committed by
Christos Margiolis
parent
b986aa05a8
commit
ebe7b24166
@@ -112,16 +112,28 @@ oss_init(struct config *config)
|
||||
}
|
||||
|
||||
/* Set sample format */
|
||||
if (ioctl(config->fd, SNDCTL_DSP_SETFMT, &config->format) < 0)
|
||||
tmp = config->format;
|
||||
if (ioctl(config->fd, SNDCTL_DSP_SETFMT, &tmp) < 0)
|
||||
err(1, "Unable to set sample format");
|
||||
if (tmp != config->format)
|
||||
warnx("Format: requested=%08x, got=%08x", config->format, tmp);
|
||||
config->format = tmp;
|
||||
|
||||
/* Set sample channels */
|
||||
if (ioctl(config->fd, SNDCTL_DSP_CHANNELS, &config->audio_info.max_channels) < 0)
|
||||
tmp = config->audio_info.max_channels;
|
||||
if (ioctl(config->fd, SNDCTL_DSP_CHANNELS, &tmp) < 0)
|
||||
err(1, "Unable to set channels");
|
||||
if (tmp != config->audio_info.max_channels)
|
||||
warnx("Channels: requested=%d, got=%d", config->audio_info.max_channels, tmp);
|
||||
config->audio_info.max_channels = tmp;
|
||||
|
||||
/* Set sample rate */
|
||||
tmp = config->sample_rate;
|
||||
if (ioctl(config->fd, SNDCTL_DSP_SPEED, &config->sample_rate) < 0)
|
||||
err(1, "Unable to set sample rate");
|
||||
if (tmp != config->sample_rate)
|
||||
warnx("Sample rate: requested=%d, got=%d", config->sample_rate, tmp);
|
||||
config->sample_rate = tmp;
|
||||
|
||||
/* Calculate sample size */
|
||||
switch (config->format) {
|
||||
@@ -197,10 +209,12 @@ oss_init(struct config *config)
|
||||
config->chsamples = config->sample_count / config->audio_info.max_channels;
|
||||
|
||||
printf("bytes: %d, fragments: %d, fragsize: %d, fragstotal: %d, "
|
||||
"samples: %d\n",
|
||||
"samples: %d, channels: %d, sample size: %d, sample rate: %d, "
|
||||
"format: %08x\n",
|
||||
config->buffer_info.bytes, config->buffer_info.fragments,
|
||||
config->buffer_info.fragsize, config->buffer_info.fragstotal,
|
||||
config->sample_count);
|
||||
config->sample_count, config->audio_info.max_channels,
|
||||
config->sample_size, config->sample_rate, config->format);
|
||||
|
||||
/* Set trigger direction and mmap protection */
|
||||
switch (config->mode & O_ACCMODE) {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/soundcard.h>
|
||||
#include "oss.h"
|
||||
|
||||
/*
|
||||
@@ -115,6 +116,9 @@ main(int argc, char *argv[])
|
||||
int rc, bytes;
|
||||
|
||||
oss_init(&config);
|
||||
if (config.format != AFMT_S32_NE)
|
||||
errx(1, "Device doesn't support signed 32bit samples. "
|
||||
"Check with 'sndctl' if it can be configured for 's32le' format.");
|
||||
bytes = config.buffer_info.bytes;
|
||||
channels = malloc(bytes);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user