annotate src/audio/qsa/SDL_qsa_audio.c @ 4745:0aaa54fbd2bc

Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
author dewyatt
date Tue, 06 Jul 2010 02:06:17 -0400
parents 4160ba33b597
children b530ef003506
rev   line source
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
6 modify it under the terms of the GNU Lesser General Public
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
13 Lesser General Public License for more details.
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
15 You should have received a copy of the GNU Lesser General Public
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
16 License along with this library; if not, write to the Free Software
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #include "SDL_config.h"
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include <errno.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include <unistd.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #include <fcntl.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include <signal.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include <sys/types.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include <sys/time.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <sched.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include <sys/select.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include <sys/neutrino.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include <sys/asoundlib.h>
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include "SDL_timer.h"
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include "SDL_audio.h"
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include "../SDL_audiomem.h"
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include "../SDL_audio_c.h"
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include "SDL_qsa_audio.h"
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 /* The tag name used by QSA audio framework */
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 #define DRIVER_NAME "qsa"
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 /* default channel communication parameters */
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #define DEFAULT_CPARAMS_RATE 44100
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #define DEFAULT_CPARAMS_VOICES 1
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 #define DEFAULT_CPARAMS_FRAG_SIZE 4096
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 #define DEFAULT_CPARAMS_FRAGS_MIN 1
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 #define DEFAULT_CPARAMS_FRAGS_MAX 1
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 #define QSA_NO_WORKAROUNDS 0x00000000
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 #define QSA_MMAP_WORKAROUND 0x00000001
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 struct BuggyCards
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
58 char *cardname;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 unsigned long bugtype;
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 };
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 #define QSA_WA_CARDS 3
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 #define QSA_MAX_CARD_NAME_LENGTH 33
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
65 struct BuggyCards buggycards[QSA_WA_CARDS] = {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
66 {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
67 {"Vortex 8820", QSA_MMAP_WORKAROUND},
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
68 {"Vortex 8830", QSA_MMAP_WORKAROUND},
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 };
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 /* List of found devices */
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 #define QSA_MAX_DEVICES 32
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
73 #define QSA_MAX_NAME_LENGTH 81+16 /* Hardcoded in QSA, can't be changed */
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 typedef struct _QSA_Device
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
77 char name[QSA_MAX_NAME_LENGTH]; /* Long audio device name for SDL */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
78 int cardno;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
79 int deviceno;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 } QSA_Device;
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 QSA_Device qsa_playback_device[QSA_MAX_DEVICES];
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
83 uint32_t qsa_playback_devices;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 QSA_Device qsa_capture_device[QSA_MAX_DEVICES];
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
86 uint32_t qsa_capture_devices;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
88 static inline void
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
89 QSA_SetError(const char *fn, int status)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
91 SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 /* card names check to apply the workarounds */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
95 static int
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
96 QSA_CheckBuggyCards(_THIS, unsigned long checkfor)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
98 char scardname[QSA_MAX_CARD_NAME_LENGTH];
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
99 int it;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
101 if (snd_card_get_name
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
102 (this->hidden->cardno, scardname, QSA_MAX_CARD_NAME_LENGTH - 1) < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
103 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
104 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
106 for (it = 0; it < QSA_WA_CARDS; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
107 if (SDL_strcmp(buggycards[it].cardname, scardname) == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
108 if (buggycards[it].bugtype == checkfor) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
109 return 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
110 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
111 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
112 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
113
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
114 return 0;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
117 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
118 QSA_ThreadInit(_THIS)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
120 struct sched_param param;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
121 int status;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
123 /* Increase default 10 priority to 25 to avoid jerky sound */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
124 status = SchedGet(0, 0, &param);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
125 param.sched_priority = param.sched_curpriority + 15;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
126 status = SchedSet(0, 0, SCHED_NOCHANGE, &param);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 /* PCM channel parameters initialize function */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
130 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
131 QSA_InitAudioParams(snd_pcm_channel_params_t * cpars)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
133 SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
135 cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
136 cpars->mode = SND_PCM_MODE_BLOCK;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
137 cpars->start_mode = SND_PCM_START_DATA;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
138 cpars->stop_mode = SND_PCM_STOP_STOP;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
139 cpars->format.format = SND_PCM_SFMT_S16_LE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
140 cpars->format.interleave = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
141 cpars->format.rate = DEFAULT_CPARAMS_RATE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
142 cpars->format.voices = DEFAULT_CPARAMS_VOICES;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
143 cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
144 cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
145 cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 /* This function waits until it is possible to write a full sound buffer */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
149 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
150 QSA_WaitDevice(_THIS)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
152 fd_set wfds;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
153 fd_set rfds;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
154 int selectret;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
155 struct timeval timeout;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
157 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
158 FD_ZERO(&wfds);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
159 FD_SET(this->hidden->audio_fd, &wfds);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
160 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
161 FD_ZERO(&rfds);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
162 FD_SET(this->hidden->audio_fd, &rfds);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
163 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
165 do {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
166 /* Setup timeout for playing one fragment equal to 2 seconds */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
167 /* If timeout occured than something wrong with hardware or driver */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
168 /* For example, Vortex 8820 audio driver stucks on second DAC because */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
169 /* it doesn't exist ! */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
170 timeout.tv_sec = 2;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
171 timeout.tv_usec = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
172 this->hidden->timeout_on_wait = 0;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
174 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
175 selectret =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
176 select(this->hidden->audio_fd + 1, NULL, &wfds, NULL,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
177 &timeout);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
178 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
179 selectret =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
180 select(this->hidden->audio_fd + 1, &rfds, NULL, NULL,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
181 &timeout);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
182 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
183
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
184 switch (selectret) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
185 case -1:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
186 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
187 SDL_SetError("QSA: select() failed: %s\n", strerror(errno));
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
188 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
189 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
190 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
191 case 0:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
192 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
193 SDL_SetError("QSA: timeout on buffer waiting occured\n");
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
194 this->hidden->timeout_on_wait = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
195 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
196 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
197 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
198 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
199 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
200 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
201 if (FD_ISSET(this->hidden->audio_fd, &wfds)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
202 return;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
204 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
205 if (FD_ISSET(this->hidden->audio_fd, &rfds)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
206 return;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
208 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
209 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
210 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
211 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
212 } while (1);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
215 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
216 QSA_PlayDevice(_THIS)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
218 snd_pcm_channel_status_t cstatus;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
219 int written;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
220 int status;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
221 int towrite;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
222 void *pcmbuffer;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
224 if ((!this->enabled) || (!this->hidden)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
225 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
226 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
228 towrite = this->spec.size;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
229 pcmbuffer = this->hidden->pcm_buf;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
231 /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
232 do {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
233 written =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
234 snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
235 towrite);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
236 if (written != towrite) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
237 /* Check if samples playback got stuck somewhere in hardware or in */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
238 /* the audio device driver */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
239 if ((errno == EAGAIN) && (written == 0)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
240 if (this->hidden->timeout_on_wait != 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
241 SDL_SetError("QSA: buffer playback timeout\n");
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
242 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
243 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
246 /* Check for errors or conditions */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
247 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
248 /* Let a little CPU time go by and try to write again */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
249 SDL_Delay(1);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
251 /* if we wrote some data */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
252 towrite -= written;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
253 pcmbuffer += written * this->spec.channels;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
254 continue;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
255 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
256 if ((errno == EINVAL) || (errno == EIO)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
257 SDL_memset(&cstatus, 0, sizeof(cstatus));
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
258 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
259 cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
260 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
261 cstatus.channel = SND_PCM_CHANNEL_CAPTURE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
262 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
264 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
265 snd_pcm_plugin_status(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
266 &cstatus);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
267 if (status < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
268 QSA_SetError("snd_pcm_plugin_status", status);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
269 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
270 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
272 if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) ||
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
273 (cstatus.status == SND_PCM_STATUS_READY)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
274 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
275 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
276 snd_pcm_plugin_prepare(this->hidden->
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
277 audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
278 SND_PCM_CHANNEL_PLAYBACK);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
279 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
280 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
281 snd_pcm_plugin_prepare(this->hidden->
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
282 audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
283 SND_PCM_CHANNEL_CAPTURE);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
284 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
285 if (status < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
286 QSA_SetError("snd_pcm_plugin_prepare", status);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
287 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
288 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
289 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
290 continue;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
291 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
292 return;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
293 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
295 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
296 /* we wrote all remaining data */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
297 towrite -= written;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
298 pcmbuffer += written * this->spec.channels;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
299 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
300 } while ((towrite > 0) && (this->enabled));
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
302 /* If we couldn't write, assume fatal error for now */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
303 if (towrite != 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
304 this->enabled = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
305 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
308 static Uint8 *
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
309 QSA_GetDeviceBuf(_THIS)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
311 return this->hidden->pcm_buf;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
314 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
315 QSA_CloseDevice(_THIS)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
317 if (this->hidden != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
318 if (this->hidden->audio_handle != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
319 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
320 /* Finish playing available samples */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
321 snd_pcm_plugin_flush(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
322 SND_PCM_CHANNEL_PLAYBACK);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
323 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
324 /* Cancel unread samples during capture */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
325 snd_pcm_plugin_flush(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
326 SND_PCM_CHANNEL_CAPTURE);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
327 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
328 snd_pcm_close(this->hidden->audio_handle);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
329 this->hidden->audio_handle = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
330 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
332 if (this->hidden->pcm_buf != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
333 SDL_FreeAudioMem(this->hidden->pcm_buf);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
334 this->hidden->pcm_buf = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
335 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
337 SDL_free(this->hidden);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
338 this->hidden = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
339 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
342 static int
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
343 QSA_OpenDevice(_THIS, const char *devname, int iscapture)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
345 int status = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
346 int format = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
347 SDL_AudioFormat test_format = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
348 int found = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
349 snd_pcm_channel_setup_t csetup;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
350 snd_pcm_channel_params_t cparams;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
352 /* Initialize all variables that we clean on shutdown */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
353 this->hidden =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
354 (struct SDL_PrivateAudioData *) SDL_calloc(1,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
355 (sizeof
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
356 (struct
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
357 SDL_PrivateAudioData)));
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
358 if (this->hidden == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
359 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
360 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
361 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
362 SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
364 /* Initialize channel transfer parameters to default */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
365 QSA_InitAudioParams(&cparams);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
367 /* Initialize channel direction: capture or playback */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
368 this->hidden->iscapture = iscapture;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
370 /* Find deviceid and cardid by device name for playback */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
371 if ((!this->hidden->iscapture) && (devname != NULL)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
372 uint32_t device;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
373 int32_t status;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
375 /* Search in the playback devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
376 device = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
377 do {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
378 status = SDL_strcmp(qsa_playback_device[device].name, devname);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
379 if (status == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
380 /* Found requested device */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
381 this->hidden->deviceno = qsa_playback_device[device].deviceno;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
382 this->hidden->cardno = qsa_playback_device[device].cardno;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
383 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
384 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
385 device++;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
386 if (device >= qsa_playback_devices) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
387 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
388 SDL_SetError("No such playback device");
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
389 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
390 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
391 } while (1);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
392 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
394 /* Find deviceid and cardid by device name for capture */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
395 if ((this->hidden->iscapture) && (devname != NULL)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
396 /* Search in the capture devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
397 uint32_t device;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
398 int32_t status;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
400 /* Searching in the playback devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
401 device = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
402 do {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
403 status = SDL_strcmp(qsa_capture_device[device].name, devname);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
404 if (status == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
405 /* Found requested device */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
406 this->hidden->deviceno = qsa_capture_device[device].deviceno;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
407 this->hidden->cardno = qsa_capture_device[device].cardno;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
408 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
409 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
410 device++;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
411 if (device >= qsa_capture_devices) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
412 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
413 SDL_SetError("No such capture device");
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
414 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
415 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
416 } while (1);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
417 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
419 /* Check if SDL requested default audio device */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
420 if (devname == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
421 /* Open system default audio device */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
422 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
423 status = snd_pcm_open_preferred(&this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
424 &this->hidden->cardno,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
425 &this->hidden->deviceno,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
426 SND_PCM_OPEN_PLAYBACK);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
427 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
428 status = snd_pcm_open_preferred(&this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
429 &this->hidden->cardno,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
430 &this->hidden->deviceno,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
431 SND_PCM_OPEN_CAPTURE);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
432 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
433 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
434 /* Open requested audio device */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
435 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
436 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
437 snd_pcm_open(&this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
438 this->hidden->cardno, this->hidden->deviceno,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
439 SND_PCM_OPEN_PLAYBACK);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
440 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
441 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
442 snd_pcm_open(&this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
443 this->hidden->cardno, this->hidden->deviceno,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
444 SND_PCM_OPEN_CAPTURE);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
445 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
446 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
448 /* Check if requested device is opened */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
449 if (status < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
450 this->hidden->audio_handle = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
451 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
452 QSA_SetError("snd_pcm_open", status);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
453 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
454 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
456 if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
457 /* Disable QSA MMAP plugin for buggy audio drivers */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
458 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
459 snd_pcm_plugin_set_disable(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
460 PLUGIN_DISABLE_MMAP);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
461 if (status < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
462 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
463 QSA_SetError("snd_pcm_plugin_set_disable", status);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
464 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
465 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
466 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
468 /* Try for a closest match on audio format */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
469 format = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
470 /* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
471 found = 0;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
473 for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
474 /* if match found set format to equivalent QSA format */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
475 switch (test_format) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
476 case AUDIO_U8:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
477 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
478 format = SND_PCM_SFMT_U8;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
479 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
480 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
481 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
482 case AUDIO_S8:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
483 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
484 format = SND_PCM_SFMT_S8;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
485 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
486 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
487 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
488 case AUDIO_S16LSB:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
489 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
490 format = SND_PCM_SFMT_S16_LE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
491 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
492 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
493 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
494 case AUDIO_S16MSB:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
495 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
496 format = SND_PCM_SFMT_S16_BE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
497 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
498 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
499 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
500 case AUDIO_U16LSB:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
501 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
502 format = SND_PCM_SFMT_U16_LE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
503 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
504 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
505 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
506 case AUDIO_U16MSB:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
507 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
508 format = SND_PCM_SFMT_U16_BE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
509 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
510 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
511 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
512 case AUDIO_S32LSB:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
513 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
514 format = SND_PCM_SFMT_S32_LE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
515 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
516 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
517 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
518 case AUDIO_S32MSB:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
519 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
520 format = SND_PCM_SFMT_S32_BE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
521 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
522 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
523 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
524 case AUDIO_F32LSB:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
525 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
526 format = SND_PCM_SFMT_FLOAT_LE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
527 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
528 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
529 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
530 case AUDIO_F32MSB:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
531 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
532 format = SND_PCM_SFMT_FLOAT_BE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
533 found = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
534 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
535 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
536 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
537 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
538 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
539 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
540 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
542 if (!found) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
543 test_format = SDL_NextAudioFormat();
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
544 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
545 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
547 /* assumes test_format not 0 on success */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
548 if (test_format == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
549 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
550 SDL_SetError("QSA: Couldn't find any hardware audio formats");
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
551 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
552 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
554 this->spec.format = test_format;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
556 /* Set the audio format */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
557 cparams.format.format = format;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
559 /* Set mono/stereo/4ch/6ch/8ch audio */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
560 cparams.format.voices = this->spec.channels;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
562 /* Set rate */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
563 cparams.format.rate = this->spec.freq;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
565 /* Setup the transfer parameters according to cparams */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
566 status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
567 if (status < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
568 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
569 QSA_SetError("snd_pcm_channel_params", status);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
570 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
571 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
573 /* Make sure channel is setup right one last time */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
574 SDL_memset(&csetup, '\0', sizeof(csetup));
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
575 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
576 csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
577 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
578 csetup.channel = SND_PCM_CHANNEL_CAPTURE;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
579 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
581 /* Setup an audio channel */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
582 if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
583 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
584 SDL_SetError("QSA: Unable to setup channel\n");
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
585 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
586 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
588 /* Calculate the final parameters for this audio specification */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
589 SDL_CalculateAudioSpec(&this->spec);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
591 this->hidden->pcm_len = this->spec.size;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
593 if (this->hidden->pcm_len == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
594 this->hidden->pcm_len =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
595 csetup.buf.block.frag_size * this->spec.channels *
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
596 (snd_pcm_format_width(format) / 8);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
597 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
599 /*
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
600 * Allocate memory to the audio buffer and initialize with silence
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
601 * (Note that buffer size must be a multiple of fragment size, so find
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
602 * closest multiple)
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
603 */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
604 this->hidden->pcm_buf =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
605 (Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
606 if (this->hidden->pcm_buf == NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
607 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
608 SDL_OutOfMemory();
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
609 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
610 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
611 SDL_memset(this->hidden->pcm_buf, this->spec.silence,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
612 this->hidden->pcm_len);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
614 /* get the file descriptor */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
615 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
616 this->hidden->audio_fd =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
617 snd_pcm_file_descriptor(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
618 SND_PCM_CHANNEL_PLAYBACK);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
619 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
620 this->hidden->audio_fd =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
621 snd_pcm_file_descriptor(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
622 SND_PCM_CHANNEL_CAPTURE);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
623 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
625 if (this->hidden->audio_fd < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
626 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
627 QSA_SetError("snd_pcm_file_descriptor", status);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
628 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
629 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
631 /* Prepare an audio channel */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
632 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
633 /* Prepare audio playback */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
634 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
635 snd_pcm_plugin_prepare(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
636 SND_PCM_CHANNEL_PLAYBACK);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
637 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
638 /* Prepare audio capture */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
639 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
640 snd_pcm_plugin_prepare(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
641 SND_PCM_CHANNEL_CAPTURE);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
642 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
643
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
644 if (status < 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
645 QSA_CloseDevice(this);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
646 QSA_SetError("snd_pcm_plugin_prepare", status);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
647 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
648 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
649
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
650 /* We're really ready to rock and roll. :-) */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
651 return 1;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
652 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
653
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
654 int
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
655 QSA_DetectDevices(int iscapture)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
656 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
657 uint32_t it;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
658 uint32_t cards;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
659 uint32_t devices;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
660 int32_t status;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
661
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
662 /* Detect amount of available devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
663 /* this value can be changed in the runtime */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
664 cards = snd_cards();
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
665
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
666 /* If io-audio manager is not running we will get 0 as number */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
667 /* of available audio devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
668 if (cards == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
669 /* We have no any available audio devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
670 return 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
671 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
672
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
673 /* Find requested devices by type */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
674 if (!iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
675 /* Playback devices enumeration requested */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
676 for (it = 0; it < cards; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
677 devices = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
678 do {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
679 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
680 snd_card_get_longname(it,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
681 qsa_playback_device
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
682 [qsa_playback_devices].name,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
683 QSA_MAX_NAME_LENGTH);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
684 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
685 snd_pcm_t *handle;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
686
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
687 /* Add device number to device name */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
688 sprintf(qsa_playback_device[qsa_playback_devices].name +
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
689 SDL_strlen(qsa_playback_device
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
690 [qsa_playback_devices].name), " d%d",
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
691 devices);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
692
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
693 /* Store associated card number id */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
694 qsa_playback_device[qsa_playback_devices].cardno = it;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
695
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
696 /* Check if this device id could play anything */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
697 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
698 snd_pcm_open(&handle, it, devices,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
699 SND_PCM_OPEN_PLAYBACK);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
700 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
701 qsa_playback_device[qsa_playback_devices].deviceno =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
702 devices;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
703 status = snd_pcm_close(handle);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
704 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
705 qsa_playback_devices++;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
706 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
707 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
708 /* Check if we got end of devices list */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
709 if (status == -ENOENT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
710 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
711 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
712 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
713 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
714 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
715 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
716
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
717 /* Check if we reached maximum devices count */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
718 if (qsa_playback_devices >= QSA_MAX_DEVICES) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
719 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
720 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
721 devices++;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
722 } while (1);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
723
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
724 /* Check if we reached maximum devices count */
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
725 if (qsa_playback_devices >= QSA_MAX_DEVICES) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
726 break;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
727 }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
728 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
729 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
730 /* Capture devices enumeration requested */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
731 for (it = 0; it < cards; it++) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
732 devices = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
733 do {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
734 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
735 snd_card_get_longname(it,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
736 qsa_capture_device
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
737 [qsa_capture_devices].name,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
738 QSA_MAX_NAME_LENGTH);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
739 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
740 snd_pcm_t *handle;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
741
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
742 /* Add device number to device name */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
743 sprintf(qsa_capture_device[qsa_capture_devices].name +
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
744 SDL_strlen(qsa_capture_device
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
745 [qsa_capture_devices].name), " d%d",
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
746 devices);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
747
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
748 /* Store associated card number id */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
749 qsa_capture_device[qsa_capture_devices].cardno = it;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
750
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
751 /* Check if this device id could play anything */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
752 status =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
753 snd_pcm_open(&handle, it, devices,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
754 SND_PCM_OPEN_CAPTURE);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
755 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
756 qsa_capture_device[qsa_capture_devices].deviceno =
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
757 devices;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
758 status = snd_pcm_close(handle);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
759 if (status == EOK) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
760 qsa_capture_devices++;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
761 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
762 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
763 /* Check if we got end of devices list */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
764 if (status == -ENOENT) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
765 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
766 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
767 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
768
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
769 /* Check if we reached maximum devices count */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
770 if (qsa_capture_devices >= QSA_MAX_DEVICES) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
771 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
772 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
773 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
774 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
775 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
776 devices++;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
777 } while (1);
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
778
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
779 /* Check if we reached maximum devices count */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
780 if (qsa_capture_devices >= QSA_MAX_DEVICES) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
781 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
782 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
783 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
784 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
785
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
786 /* Return amount of available playback or capture devices */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
787 if (!iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
788 return qsa_playback_devices;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
789 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
790 return qsa_capture_devices;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
791 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
792 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
793
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
794 const char *
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
795 QSA_GetDeviceName(int index, int iscapture)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
796 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
797 if (!iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
798 if (index >= qsa_playback_devices) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
799 return "No such playback device";
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
800 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
801
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
802 return qsa_playback_device[index].name;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
803 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
804 if (index >= qsa_capture_devices) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
805 return "No such capture device";
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
806 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
807
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
808 return qsa_capture_device[index].name;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
809 }
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
810 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
811
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
812 void
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
813 QSA_WaitDone(_THIS)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
814 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
815 if (!this->hidden->iscapture) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
816 if (this->hidden->audio_handle != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
817 /* Wait till last fragment is played and stop channel */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
818 snd_pcm_plugin_flush(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
819 SND_PCM_CHANNEL_PLAYBACK);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
820 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
821 } else {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
822 if (this->hidden->audio_handle != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
823 /* Discard all unread data and stop channel */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
824 snd_pcm_plugin_flush(this->hidden->audio_handle,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
825 SND_PCM_CHANNEL_CAPTURE);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
826 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
827 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
828 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
829
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
830 void
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
831 QSA_Deinitialize(void)
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
832 {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
833 /* Clear devices array on shutdown */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
834 SDL_memset(qsa_playback_device, 0x00,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
835 sizeof(QSA_Device) * QSA_MAX_DEVICES);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
836 SDL_memset(qsa_capture_device, 0x00,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
837 sizeof(QSA_Device) * QSA_MAX_DEVICES);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
838 qsa_playback_devices = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
839 qsa_capture_devices = 0;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
840 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
841
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
842 static int
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
843 QSA_Init(SDL_AudioDriverImpl * impl)
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
844 {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
845 snd_pcm_t *handle = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
846 int32_t status = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
847
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
848 /* Clear devices array */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
849 SDL_memset(qsa_playback_device, 0x00,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
850 sizeof(QSA_Device) * QSA_MAX_DEVICES);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
851 SDL_memset(qsa_capture_device, 0x00,
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
852 sizeof(QSA_Device) * QSA_MAX_DEVICES);
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
853 qsa_playback_devices = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
854 qsa_capture_devices = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
855
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
856 /* Set function pointers */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
857 /* DeviceLock and DeviceUnlock functions are used default, */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
858 /* provided by SDL, which uses pthread_mutex for lock/unlock */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
859 impl->DetectDevices = QSA_DetectDevices;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
860 impl->GetDeviceName = QSA_GetDeviceName;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
861 impl->OpenDevice = QSA_OpenDevice;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
862 impl->ThreadInit = QSA_ThreadInit;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
863 impl->WaitDevice = QSA_WaitDevice;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
864 impl->PlayDevice = QSA_PlayDevice;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
865 impl->GetDeviceBuf = QSA_GetDeviceBuf;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
866 impl->CloseDevice = QSA_CloseDevice;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
867 impl->WaitDone = QSA_WaitDone;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
868 impl->Deinitialize = QSA_Deinitialize;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
869 impl->LockDevice = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
870 impl->UnlockDevice = NULL;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
871
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
872 impl->OnlyHasDefaultOutputDevice = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
873 impl->ProvidesOwnCallbackThread = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
874 impl->SkipMixerLock = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
875 impl->HasCaptureSupport = 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
876 impl->OnlyHasDefaultOutputDevice = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
877 impl->OnlyHasDefaultInputDevice = 0;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
878
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
879 /* Check if io-audio manager is running or not */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
880 status = snd_cards();
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
881 if (status == 0) {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
882 /* if no, return immediately */
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
883 return 1;
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
884 }
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
885
3699
4160ba33b597 Removed test for "driver is valid, but doesn't see any audio devices."
Ryan C. Gordon <icculus@icculus.org>
parents: 3697
diff changeset
886 return 1; /* this audio target is available. */
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
887 }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
888
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
889 AudioBootStrap QSAAUDIO_bootstrap = {
Sam Lantinga <slouken@libsdl.org>
parents: 3123
diff changeset
890 DRIVER_NAME, "QNX QSA Audio", QSA_Init, 0
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
891 };
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
892
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
893 /* vi: set ts=4 sw=4 expandtab: */