21 #include "../../SDL_internal.h" 23 #if SDL_AUDIO_DRIVER_OSS 34 #include <sys/ioctl.h> 37 #if SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H 39 #include <soundcard.h> 42 #include <sys/soundcard.h> 47 #include "../SDL_audiomem.h" 48 #include "../SDL_audio_c.h" 49 #include "../SDL_audiodev_c.h" 54 DSP_DetectDevices(
void)
61 DSP_CloseDevice(
_THIS)
63 if (this->hidden !=
NULL) {
65 this->hidden->mixbuf =
NULL;
66 if (this->hidden->audio_fd >= 0) {
67 close(this->hidden->audio_fd);
68 this->hidden->audio_fd = -1;
77 DSP_OpenDevice(
_THIS,
void *handle,
const char *devname,
int iscapture)
87 if (devname ==
NULL) {
89 if (devname ==
NULL) {
106 if (this->hidden ==
NULL) {
109 SDL_memset(this->hidden, 0, (
sizeof *this->hidden));
112 this->hidden->audio_fd = open(devname, flags, 0);
113 if (this->hidden->audio_fd < 0) {
114 DSP_CloseDevice(
this);
115 return SDL_SetError(
"Couldn't open %s: %s", devname, strerror(errno));
117 this->hidden->mixbuf =
NULL;
122 ctlflags = fcntl(this->hidden->audio_fd, F_GETFL);
123 ctlflags &= ~O_NONBLOCK;
124 if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) {
125 DSP_CloseDevice(
this);
126 return SDL_SetError(
"Couldn't set audio blocking mode");
131 if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
132 perror(
"SNDCTL_DSP_GETFMTS");
133 DSP_CloseDevice(
this);
140 !format && test_format;) {
142 fprintf(stderr,
"Trying format 0x%4.4x\n", test_format);
144 switch (test_format) {
146 if (value & AFMT_U8) {
151 if (value & AFMT_S16_LE) {
152 format = AFMT_S16_LE;
156 if (value & AFMT_S16_BE) {
157 format = AFMT_S16_BE;
166 if (value & AFMT_S8) {
171 if (value & AFMT_U16_LE) {
172 format = AFMT_U16_LE;
176 if (value & AFMT_U16_BE) {
177 format = AFMT_U16_BE;
190 DSP_CloseDevice(
this);
191 return SDL_SetError(
"Couldn't find any hardware audio formats");
197 if ((ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
199 perror(
"SNDCTL_DSP_SETFMT");
200 DSP_CloseDevice(
this);
206 if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
207 perror(
"SNDCTL_DSP_CHANNELS");
208 DSP_CloseDevice(
this);
209 return SDL_SetError(
"Cannot set the number of channels");
215 if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
216 perror(
"SNDCTL_DSP_SPEED");
217 DSP_CloseDevice(
this);
226 for (frag_spec = 0; (0x01U << frag_spec) < this->
spec.
size; ++frag_spec);
227 if ((0x01U << frag_spec) != this->
spec.
size) {
228 DSP_CloseDevice(
this);
229 return SDL_SetError(
"Fragment size must be a power of two");
231 frag_spec |= 0x00020000;
235 fprintf(stderr,
"Requesting %d fragments of size %d\n",
236 (frag_spec >> 16), 1 << (frag_spec & 0xFFFF));
238 if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) {
239 perror(
"SNDCTL_DSP_SETFRAGMENT");
244 ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETOSPACE, &info);
245 fprintf(stderr,
"fragments = %d\n", info.fragments);
246 fprintf(stderr,
"fragstotal = %d\n", info.fragstotal);
247 fprintf(stderr,
"fragsize = %d\n", info.fragsize);
248 fprintf(stderr,
"bytes = %d\n", info.bytes);
253 this->hidden->mixlen = this->
spec.
size;
255 if (this->hidden->mixbuf ==
NULL) {
256 DSP_CloseDevice(
this);
259 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
267 DSP_PlayDevice(
_THIS)
270 const int mixlen = this->hidden->mixlen;
271 if (write(this->hidden->audio_fd, mixbuf, mixlen) == -1) {
272 perror(
"Audio write");
276 fprintf(stderr,
"Wrote %d bytes of audio data\n", mixlen);
281 DSP_GetDeviceBuf(
_THIS)
283 return (this->hidden->mixbuf);
303 "dsp",
"OSS /dev/dsp standard audio", DSP_Init, 0
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
void(* DetectDevices)(void)
void(* PlayDevice)(_THIS)
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
Uint16 SDL_AudioFormat
Audio format flags.
SDL_AudioFormat SDL_NextAudioFormat(void)
#define SDL_GetAudioDeviceName
void SDL_EnumUnixAudioDevices(const int classic, int(*test)(int))
GLsizei const GLfloat * value
#define OPEN_FLAGS_OUTPUT
uint8_t Uint8
An unsigned 8-bit integer type.
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
#define SDL_AllocAudioMem
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
#define SDL_OutOfMemory()
AudioBootStrap DSP_bootstrap
void(* CloseDevice)(_THIS)
int AllowsArbitraryDeviceNames
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Uint8 *(* GetDeviceBuf)(_THIS)