Skip to content

Commit ebe7b24

Browse files
mekanixchristosmarg
authored andcommitted
sound examples: Check if setting property was successful
MFC after: 1 week Reviewed by: christos Differential Revision: https://reviews.freebsd.org/D54038
1 parent b986aa0 commit ebe7b24

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

share/examples/sound/oss.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,28 @@ oss_init(struct config *config)
112112
}
113113

114114
/* Set sample format */
115-
if (ioctl(config->fd, SNDCTL_DSP_SETFMT, &config->format) < 0)
115+
tmp = config->format;
116+
if (ioctl(config->fd, SNDCTL_DSP_SETFMT, &tmp) < 0)
116117
err(1, "Unable to set sample format");
118+
if (tmp != config->format)
119+
warnx("Format: requested=%08x, got=%08x", config->format, tmp);
120+
config->format = tmp;
117121

118122
/* Set sample channels */
119-
if (ioctl(config->fd, SNDCTL_DSP_CHANNELS, &config->audio_info.max_channels) < 0)
123+
tmp = config->audio_info.max_channels;
124+
if (ioctl(config->fd, SNDCTL_DSP_CHANNELS, &tmp) < 0)
120125
err(1, "Unable to set channels");
126+
if (tmp != config->audio_info.max_channels)
127+
warnx("Channels: requested=%d, got=%d", config->audio_info.max_channels, tmp);
128+
config->audio_info.max_channels = tmp;
121129

122130
/* Set sample rate */
131+
tmp = config->sample_rate;
123132
if (ioctl(config->fd, SNDCTL_DSP_SPEED, &config->sample_rate) < 0)
124133
err(1, "Unable to set sample rate");
134+
if (tmp != config->sample_rate)
135+
warnx("Sample rate: requested=%d, got=%d", config->sample_rate, tmp);
136+
config->sample_rate = tmp;
125137

126138
/* Calculate sample size */
127139
switch (config->format) {
@@ -197,10 +209,12 @@ oss_init(struct config *config)
197209
config->chsamples = config->sample_count / config->audio_info.max_channels;
198210

199211
printf("bytes: %d, fragments: %d, fragsize: %d, fragstotal: %d, "
200-
"samples: %d\n",
212+
"samples: %d, channels: %d, sample size: %d, sample rate: %d, "
213+
"format: %08x\n",
201214
config->buffer_info.bytes, config->buffer_info.fragments,
202215
config->buffer_info.fragsize, config->buffer_info.fragstotal,
203-
config->sample_count);
216+
config->sample_count, config->audio_info.max_channels,
217+
config->sample_size, config->sample_rate, config->format);
204218

205219
/* Set trigger direction and mmap protection */
206220
switch (config->mode & O_ACCMODE) {

share/examples/sound/simple.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* SUCH DAMAGE.
3030
*/
3131

32+
#include <sys/soundcard.h>
3233
#include "oss.h"
3334

3435
/*
@@ -115,6 +116,9 @@ main(int argc, char *argv[])
115116
int rc, bytes;
116117

117118
oss_init(&config);
119+
if (config.format != AFMT_S32_NE)
120+
errx(1, "Device doesn't support signed 32bit samples. "
121+
"Check with 'sndctl' if it can be configured for 's32le' format.");
118122
bytes = config.buffer_info.bytes;
119123
channels = malloc(bytes);
120124

0 commit comments

Comments
 (0)