annotate src/audio/mint/SDL_mintaudio_gsxb.c @ 1510:720f8bb49d7d

Win32 fixes
author Sam Lantinga <slouken@libsdl.org>
date Mon, 13 Mar 2006 02:06:33 +0000
parents a8181c4040b8
children 782fd950bd46 c121d94672cb 405a192b68e7
rev   line source
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
1 /*
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 704
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
4
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
9
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
13 Library General Public License for more details.
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
14
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
18
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
19 Sam Lantinga
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
20 slouken@libsdl.org
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
23
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
24 /*
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
25 MiNT audio driver
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
26 using XBIOS functions (GSXB compatible driver)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
27
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
28 Patrice Mandin
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
29 */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
30
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
31 /* Mint includes */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
32 #include <mint/osbind.h>
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
33 #include <mint/falcon.h>
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
34 #include <mint/cookie.h>
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
35
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
36 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
37 #include "../SDL_audio_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
38 #include "../SDL_sysaudio.h"
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
39
1412
a8181c4040b8 Fixed include files
Patrice Mandin <patmandin@gmail.com>
parents: 1402
diff changeset
40 #include "../../video/ataricommon/SDL_atarimxalloc_c.h"
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
41
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
42 #include "SDL_mintaudio.h"
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
43 #include "SDL_mintaudio_gsxb.h"
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
44
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
45 /*--- Defines ---*/
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
46
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
47 #define MINT_AUDIO_DRIVER_NAME "mint_gsxb"
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
48
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
49 /* Debug print info */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
50 #define DEBUG_NAME "audio:gsxb: "
962
176240cf4405 Forgot to disable debug messages
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
51 #if 0
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
52 #define DEBUG_PRINT(what) \
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
53 { \
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
54 printf what; \
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
55 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
56 #else
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
57 #define DEBUG_PRINT(what)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
58 #endif
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
59
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
60 /*--- Static variables ---*/
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
61
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
62 static unsigned long cookie_snd, cookie_gsxb;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
63
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
64 /*--- Audio driver functions ---*/
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
65
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
66 static void Mint_CloseAudio(_THIS);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
67 static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
68 static void Mint_LockAudio(_THIS);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
69 static void Mint_UnlockAudio(_THIS);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
70
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
71 /* To check/init hardware audio */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
72 static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
73 static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
74
1097
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
75 /* GSXB callbacks */
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
76 static void Mint_GsxbInterrupt(void);
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
77 static void Mint_GsxbNullInterrupt(void);
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
78
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
79 /*--- Audio driver bootstrap functions ---*/
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
80
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
81 static int Audio_Available(void)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
82 {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
83 const char *envr = SDL_getenv("SDL_AUDIODRIVER");
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
84
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
85 /* Check if user asked a different audio driver */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
86 if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
87 DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
88 return(0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
89 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
90
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
91 /* Cookie _SND present ? if not, assume ST machine */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
92 if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
93 cookie_snd = SND_PSG;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
94 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
95
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
96 /* Check if we have 16 bits audio */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
97 if ((cookie_snd & SND_16BIT)==0) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
98 DEBUG_PRINT((DEBUG_NAME "no 16 bits sound\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
99 return(0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
100 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
101
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
102 /* Cookie GSXB present ? */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
103 cookie_gsxb = (Getcookie(C_GSXB, &cookie_gsxb) == C_FOUND);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
104
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
105 /* Is it GSXB ? */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
106 if (((cookie_snd & SND_GSXB)==0) || (cookie_gsxb==0)) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
107 DEBUG_PRINT((DEBUG_NAME "no GSXB audio\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
108 return(0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
109 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
110
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
111 /* Check if audio is lockable */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
112 if (Locksnd()!=1) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
113 DEBUG_PRINT((DEBUG_NAME "audio locked by other application\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
114 return(0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
115 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
116
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
117 Unlocksnd();
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
118
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
119 DEBUG_PRINT((DEBUG_NAME "GSXB audio available!\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
120 return(1);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
121 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
122
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
123 static void Audio_DeleteDevice(SDL_AudioDevice *device)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
124 {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
125 SDL_free(device->hidden);
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
126 SDL_free(device);
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
127 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
128
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
129 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
130 {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
131 SDL_AudioDevice *this;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
132
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
133 /* Initialize all variables that we clean on shutdown */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
134 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
135 if ( this ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
136 SDL_memset(this, 0, (sizeof *this));
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
137 this->hidden = (struct SDL_PrivateAudioData *)
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
138 SDL_malloc((sizeof *this->hidden));
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
139 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
140 if ( (this == NULL) || (this->hidden == NULL) ) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
141 SDL_OutOfMemory();
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
142 if ( this ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
143 SDL_free(this);
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
144 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
145 return(0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
146 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
147 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
148
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
149 /* Set the function pointers */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
150 this->OpenAudio = Mint_OpenAudio;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
151 this->CloseAudio = Mint_CloseAudio;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
152 this->LockAudio = Mint_LockAudio;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
153 this->UnlockAudio = Mint_UnlockAudio;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
154 this->free = Audio_DeleteDevice;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
155
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
156 return this;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
157 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
158
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
159 AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
160 MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver",
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
161 Audio_Available, Audio_CreateDevice
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
162 };
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
163
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
164 static void Mint_LockAudio(_THIS)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
165 {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
166 /* Stop replay */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
167 Buffoper(0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
168 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
169
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
170 static void Mint_UnlockAudio(_THIS)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
171 {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
172 /* Restart replay */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
173 Buffoper(SB_PLA_ENA|SB_PLA_RPT);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
174 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
175
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
176 static void Mint_CloseAudio(_THIS)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
177 {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
178 /* Stop replay */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
179 Buffoper(0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
180
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
181 /* Uninstall interrupt */
1097
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
182 if (NSetinterrupt(2, SI_NONE, Mint_GsxbNullInterrupt)<0) {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
183 DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
184 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
185
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
186 /* Wait if currently playing sound */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
187 while (SDL_MintAudio_mutex != 0) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
188 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
189
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
190 /* Clear buffers */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
191 if (SDL_MintAudio_audiobuf[0]) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
192 Mfree(SDL_MintAudio_audiobuf[0]);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
193 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
194 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
195
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
196 /* Unlock sound system */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
197 Unlocksnd();
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
198 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
199
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
200 static int Mint_CheckAudio(_THIS, SDL_AudioSpec *spec)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
201 {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
202 long snd_format;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
203 int i, resolution, format_signed, format_bigendian;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
204
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
205 resolution = spec->format & 0x00ff;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
206 format_signed = ((spec->format & 0x8000)!=0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
207 format_bigendian = ((spec->format & 0x1000)!=0);
704
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
208
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
209 DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",spec->format & 0x00ff));
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
210 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
211 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0)));
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
212 DEBUG_PRINT(("channels=%d, ", spec->channels));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
213 DEBUG_PRINT(("freq=%d\n", spec->freq));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
214
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
215 /* Check formats available */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
216 snd_format = Sndstatus(SND_QUERYFORMATS);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
217 switch (resolution) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
218 case 8:
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
219 if ((snd_format & SND_FORMAT8)==0) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
220 SDL_SetError("Mint_CheckAudio: 8 bits samples not supported");
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
221 return -1;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
222 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
223 snd_format = Sndstatus(SND_QUERY8BIT);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
224 break;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
225 case 16:
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
226 if ((snd_format & SND_FORMAT16)==0) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
227 SDL_SetError("Mint_CheckAudio: 16 bits samples not supported");
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
228 return -1;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
229 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
230 snd_format = Sndstatus(SND_QUERY16BIT);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
231 break;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
232 default:
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
233 SDL_SetError("Mint_CheckAudio: Unsupported sample resolution");
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
234 return -1;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
235 break;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
236 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
237
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
238 /* Check signed/unsigned format */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
239 if (format_signed) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
240 if (snd_format & SND_FORMATSIGNED) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
241 /* Ok */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
242 } else if (snd_format & SND_FORMATUNSIGNED) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
243 /* Give unsigned format */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
244 spec->format = spec->format & (~0x8000);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
245 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
246 } else {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
247 if (snd_format & SND_FORMATUNSIGNED) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
248 /* Ok */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
249 } else if (snd_format & SND_FORMATSIGNED) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
250 /* Give signed format */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
251 spec->format |= 0x8000;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
252 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
253 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
254
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
255 if (format_bigendian) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
256 if (snd_format & SND_FORMATBIGENDIAN) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
257 /* Ok */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
258 } else if (snd_format & SND_FORMATLITTLEENDIAN) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
259 /* Give little endian format */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
260 spec->format = spec->format & (~0x1000);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
261 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
262 } else {
704
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
263 if (snd_format & SND_FORMATLITTLEENDIAN) {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
264 /* Ok */
704
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
265 } else if (snd_format & SND_FORMATBIGENDIAN) {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
266 /* Give big endian format */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
267 spec->format |= 0x1000;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
268 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
269 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
270
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
271 /* Calculate and select the closest frequency */
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
272 MINTAUDIO_freqcount=0;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
273 for (i=1;i<4;i++) {
1107
856f76a099c7 Can use both clocks of FDI interface on Falcon, plus digital output
Patrice Mandin <patmandin@gmail.com>
parents: 1097
diff changeset
274 SDL_MintAudio_AddFrequency(this,
856f76a099c7 Can use both clocks of FDI interface on Falcon, plus digital output
Patrice Mandin <patmandin@gmail.com>
parents: 1097
diff changeset
275 MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(1<<i)), MASTERCLOCK_44K,
856f76a099c7 Can use both clocks of FDI interface on Falcon, plus digital output
Patrice Mandin <patmandin@gmail.com>
parents: 1097
diff changeset
276 (1<<i)-1, -1);
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
277 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
278
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
279 #if 1
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
280 for (i=0; i<MINTAUDIO_freqcount; i++) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
281 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n",
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
282 i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock,
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
283 MINTAUDIO_frequencies[i].predivisor
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
284 ));
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
285 }
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
286 #endif
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
287
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
288 MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq);
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
289 spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
290
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
291 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
292 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
704
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
293 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0)));
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
294 DEBUG_PRINT(("channels=%d, ", spec->channels));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
295 DEBUG_PRINT(("freq=%d\n", spec->freq));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
296
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
297 return 0;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
298 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
299
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
300 static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
301 {
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
302 int channels_mode, prediv;
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
303 void *buffer;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
304
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
305 /* Stop currently playing sound */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
306 Buffoper(0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
307
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
308 /* Set replay tracks */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
309 Settracks(0,0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
310 Setmontracks(0);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
311
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
312 /* Select replay format */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
313 switch (spec->format & 0xff) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
314 case 8:
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
315 if (spec->channels==2) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
316 channels_mode=STEREO8;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
317 } else {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
318 channels_mode=MONO8;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
319 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
320 break;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
321 case 16:
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
322 if (spec->channels==2) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
323 channels_mode=STEREO16;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
324 } else {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
325 channels_mode=MONO16;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
326 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
327 break;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
328 default:
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
329 channels_mode=STEREO16;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
330 break;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
331 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
332 if (Setmode(channels_mode)<0) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
333 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
334 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
335
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
336 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
337 Devconnect(DMAPLAY, DAC, CLKEXT, prediv, 1);
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
338
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
339 /* Set buffer */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
340 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
341 if (Setbuffer(0, buffer, buffer + spec->size)<0) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
342 DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
343 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
344
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
345 /* Install interrupt */
1097
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
346 if (NSetinterrupt(2, SI_PLAY, Mint_GsxbInterrupt)<0) {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
347 DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
348 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
349
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
350 /* Go */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
351 Buffoper(SB_PLA_ENA|SB_PLA_RPT);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
352 DEBUG_PRINT((DEBUG_NAME "hardware initialized\n"));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
353 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
354
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
355 static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec)
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
356 {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
357 /* Lock sound system */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
358 if (Locksnd()!=1) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
359 SDL_SetError("Mint_OpenAudio: Audio system already in use");
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
360 return(-1);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
361 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
362
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
363 SDL_MintAudio_device = this;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
364
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
365 /* Check audio capabilities */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
366 if (Mint_CheckAudio(this, spec)==-1) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
367 return -1;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
368 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
369
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
370 SDL_CalculateAudioSpec(spec);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
371
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
372 /* Allocate memory for audio buffers in DMA-able RAM */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
373 DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
374
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
375 SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
376 if (SDL_MintAudio_audiobuf[0]==NULL) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
377 SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
378 return (-1);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
379 }
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
380 SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
381 SDL_MintAudio_numbuf=0;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1107
diff changeset
382 SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
383 SDL_MintAudio_audiosize = spec->size;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
384 SDL_MintAudio_mutex = 0;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
385
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
386 DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0]));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
387 DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1]));
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
388
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
389 /* Setup audio hardware */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
390 Mint_InitAudio(this, spec);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
391
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
392 return(1); /* We don't use threaded audio */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
diff changeset
393 }
1097
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
394
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
395 static void Mint_GsxbInterrupt(void)
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
396 {
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
397 Uint8 *newbuf;
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
398
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
399 if (SDL_MintAudio_mutex)
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
400 return;
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
401
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
402 SDL_MintAudio_mutex=1;
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
403
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
404 SDL_MintAudio_numbuf ^= 1;
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
405 SDL_MintAudio_Callback();
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
406 newbuf = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
407 Setbuffer(0, newbuf, newbuf + SDL_MintAudio_audiosize);
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
408
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
409 SDL_MintAudio_mutex=0;
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
410 }
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
411
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
412 static void Mint_GsxbNullInterrupt(void)
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
413 {
c83fa1c650dd Move GSXB callback to C source
Patrice Mandin <patmandin@gmail.com>
parents: 962
diff changeset
414 }