annotate src/audio/qsa/SDL_qsa_audio.c @ 3152:7f3341cccf42 gsoc2009_ps3

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