Mercurial > sdl-ios-xcode
annotate src/audio/mint/SDL_mintaudio.c @ 1228:f4a3a4129d04
From Mike Frysinger and/or Gentoo:
- libsdl-SDL_stretch-PIC.patch
ignoring the general fact of how SDL_stretch relies on executing dynamic code,
the inline asm should let gcc handle the a details for getting the actual
address for _copy_row as it will do the right thing
test case: http://dev.gentoo.org/~vapier/libsdl/sdl-stretch.tar.bz2
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 05 Jan 2006 07:20:12 +0000 |
parents | 080ed9ef0609 |
children | 3692456e7b0f |
rev | line source |
---|---|
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
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:
557
diff
changeset
|
4 |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
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:
557
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:
557
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:
557
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:
557
diff
changeset
|
9 |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
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:
557
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:
557
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:
557
diff
changeset
|
13 Library General Public License for more details. |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
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:
557
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:
557
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:
557
diff
changeset
|
18 |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
19 Sam Lantinga |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
20 slouken@libsdl.org |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
21 */ |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
22 |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
23 /* |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
24 Audio interrupt variables and callback function |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
25 |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
26 Patrice Mandin |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
27 */ |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
28 |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #include <string.h> |
1111
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
30 #include <unistd.h> |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
31 |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
32 #include <mint/osbind.h> |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
33 #include <mint/falcon.h> |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
34 #include <mint/mintbind.h> |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
36 #include "SDL_types.h" |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 #include "SDL_audio.h" |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 #include "SDL_mintaudio.h" |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
40 #include "SDL_mintaudio_stfa.h" |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
42 /* The audio device */ |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
44 SDL_AudioDevice *SDL_MintAudio_device; |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
45 Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */ |
704 | 46 unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */ |
47 unsigned short SDL_MintAudio_numbuf; /* Buffer to play */ | |
48 unsigned short SDL_MintAudio_mutex; | |
961
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
49 unsigned long SDL_MintAudio_clocktics; |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
50 cookie_stfa_t *SDL_MintAudio_stfa; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
1111
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
52 /* MiNT thread variables */ |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
53 SDL_bool SDL_MintAudio_mint_present; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
54 SDL_bool SDL_MintAudio_quit_thread; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
55 SDL_bool SDL_MintAudio_thread_finished; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
56 long SDL_MintAudio_thread_pid; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
57 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
58 /* The callback function, called by each driver whenever needed */ |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 void SDL_MintAudio_Callback(void) |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 { |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 Uint8 *buffer; |
1034
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
63 SDL_AudioDevice *audio = SDL_MintAudio_device; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; |
1034
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
66 memset(buffer, audio->spec.silence, audio->spec.size); |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
67 |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
68 if (audio->paused) |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
69 return; |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
70 |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
71 if (audio->convert.needed) { |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
72 int silence; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
1034
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
74 if ( audio->convert.src_format == AUDIO_U8 ) { |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
75 silence = 0x80; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 } else { |
1034
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
77 silence = 0; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 } |
1034
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
79 memset(audio->convert.buf, silence, audio->convert.len); |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
80 audio->spec.callback(audio->spec.userdata, |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
81 (Uint8 *)audio->convert.buf,audio->convert.len); |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
82 SDL_ConvertAudio(&audio->convert); |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
83 memcpy(buffer, audio->convert.buf, audio->convert.len_cvt); |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
84 } else { |
2eca15c3f609
clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents:
961
diff
changeset
|
85 audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size); |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 } |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 } |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
961
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
89 /* Add a new frequency/clock/predivisor to the current list */ |
1107
856f76a099c7
Can use both clocks of FDI interface on Falcon, plus digital output
Patrice Mandin <patmandin@gmail.com>
parents:
1034
diff
changeset
|
90 void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, |
856f76a099c7
Can use both clocks of FDI interface on Falcon, plus digital output
Patrice Mandin <patmandin@gmail.com>
parents:
1034
diff
changeset
|
91 Uint32 prediv, int gpio_bits) |
961
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
92 { |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
93 int i, p; |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
94 |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
95 if (MINTAUDIO_freqcount==MINTAUDIO_maxfreqs) { |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
96 return; |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
97 } |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
98 |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
99 /* Search where to insert the frequency (highest first) */ |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
100 for (p=0; p<MINTAUDIO_freqcount; p++) { |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
101 if (frequency > MINTAUDIO_frequencies[p].frequency) { |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
102 break; |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
103 } |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
104 } |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
105 |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
106 /* Put all following ones farer */ |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
107 if (MINTAUDIO_freqcount>0) { |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
108 for (i=MINTAUDIO_freqcount; i>p; i--) { |
1107
856f76a099c7
Can use both clocks of FDI interface on Falcon, plus digital output
Patrice Mandin <patmandin@gmail.com>
parents:
1034
diff
changeset
|
109 memcpy(&MINTAUDIO_frequencies[i], &MINTAUDIO_frequencies[i-1], sizeof(mint_frequency_t)); |
961
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
110 } |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
111 } |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
112 |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
113 /* And insert new one */ |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
114 MINTAUDIO_frequencies[p].frequency = frequency; |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
115 MINTAUDIO_frequencies[p].masterclock = clock; |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
116 MINTAUDIO_frequencies[p].predivisor = prediv; |
1107
856f76a099c7
Can use both clocks of FDI interface on Falcon, plus digital output
Patrice Mandin <patmandin@gmail.com>
parents:
1034
diff
changeset
|
117 MINTAUDIO_frequencies[p].gpio_bits = gpio_bits; |
961
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
118 |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
119 MINTAUDIO_freqcount++; |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
120 } |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
121 |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
122 /* Search for the nearest frequency */ |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
123 int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq) |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 { |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 int i; |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
127 /* Only 1 freq ? */ |
961
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
128 if (MINTAUDIO_freqcount==1) { |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
129 return 0; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 } |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
132 /* Check the array */ |
961
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
133 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
|
134 if (desired_freq >= ((MINTAUDIO_frequencies[i].frequency+ |
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
135 MINTAUDIO_frequencies[i+1].frequency)>>1)) { |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
136 return i; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 } |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 } |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
140 /* Not in the array, give the latest */ |
961
185acc07127a
Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents:
769
diff
changeset
|
141 return MINTAUDIO_freqcount-1; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 } |
1111
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
143 |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
144 /* The thread function, used under MiNT with xbios */ |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
145 int SDL_MintAudio_Thread(long param) |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
146 { |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
147 SndBufPtr pointers; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
148 SDL_bool buffers_filled[2] = {SDL_FALSE, SDL_FALSE}; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
149 |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
150 SDL_MintAudio_thread_finished = SDL_FALSE; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
151 while (!SDL_MintAudio_quit_thread) { |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
152 if (Buffptr(&pointers)!=0) |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
153 continue; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
154 |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
155 if (( (unsigned long)pointers.play>=(unsigned long)SDL_MintAudio_audiobuf[0]) |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
156 && ( (unsigned long)pointers.play<=(unsigned long)SDL_MintAudio_audiobuf[1])) |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
157 { |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
158 /* DMA is reading buffer #0, setup buffer #1 if not already done */ |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
159 if (!buffers_filled[1]) { |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
160 SDL_MintAudio_numbuf = 1; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
161 SDL_MintAudio_Callback(); |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
162 Setbuffer(0, SDL_MintAudio_audiobuf[1], SDL_MintAudio_audiobuf[1] + SDL_MintAudio_audiosize); |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
163 buffers_filled[1]=SDL_TRUE; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
164 buffers_filled[0]=SDL_FALSE; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
165 } |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
166 } else { |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
167 /* DMA is reading buffer #1, setup buffer #0 if not already done */ |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
168 if (!buffers_filled[0]) { |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
169 SDL_MintAudio_numbuf = 0; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
170 SDL_MintAudio_Callback(); |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
171 Setbuffer(0, SDL_MintAudio_audiobuf[0], SDL_MintAudio_audiobuf[0] + SDL_MintAudio_audiosize); |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
172 buffers_filled[0]=SDL_TRUE; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
173 buffers_filled[1]=SDL_FALSE; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
174 } |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
175 } |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
176 |
1116
080ed9ef0609
Sleep a bit less in thread
Patrice Mandin <patmandin@gmail.com>
parents:
1111
diff
changeset
|
177 usleep(100); |
1111
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
178 } |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
179 SDL_MintAudio_thread_finished = SDL_TRUE; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
180 return 0; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
181 } |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
182 |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
183 void SDL_MintAudio_WaitThread(void) |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
184 { |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
185 if (!SDL_MintAudio_mint_present) |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
186 return; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
187 |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
188 if (SDL_MintAudio_thread_finished) |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
189 return; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
190 |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
191 SDL_MintAudio_quit_thread = SDL_TRUE; |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
192 while (!SDL_MintAudio_thread_finished) { |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
193 Syield(); |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
194 } |
12c49532be00
Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents:
1107
diff
changeset
|
195 } |