annotate src/audio/mint/SDL_mintaudio.c @ 1361:19418e4422cb

New configure-based build system. Still work in progress, but much improved
author Sam Lantinga <slouken@libsdl.org>
date Thu, 16 Feb 2006 10:11:48 +0000
parents c71e05b4dc2e
children d910939febfa
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
1111
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
29 #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
30
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
31 #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
32 #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
33 #include <mint/mintbind.h>
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include "SDL_audio.h"
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include "SDL_mintaudio.h"
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
37 #include "SDL_mintaudio_stfa.h"
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
39 /* The audio device */
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
41 SDL_AudioDevice *SDL_MintAudio_device;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
42 Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */
704
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
43 unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
44 unsigned short SDL_MintAudio_numbuf; /* Buffer to play */
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
45 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
46 unsigned long SDL_MintAudio_clocktics;
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
47 cookie_stfa_t *SDL_MintAudio_stfa;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48
1111
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
49 /* 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
50 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
51 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
52 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
53 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
54
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
55 /* 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
56
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 void SDL_MintAudio_Callback(void)
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 {
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 Uint8 *buffer;
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
60 SDL_AudioDevice *audio = SDL_MintAudio_device;
398
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 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1116
diff changeset
63 SDL_memset(buffer, audio->spec.silence, audio->spec.size);
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
64
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
65 if (audio->paused)
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
66 return;
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->convert.needed) {
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
69 int silence;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
71 if ( audio->convert.src_format == AUDIO_U8 ) {
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
72 silence = 0x80;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 } else {
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
74 silence = 0;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1116
diff changeset
76 SDL_memset(audio->convert.buf, silence, audio->convert.len);
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
77 audio->spec.callback(audio->spec.userdata,
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
78 (Uint8 *)audio->convert.buf,audio->convert.len);
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
79 SDL_ConvertAudio(&audio->convert);
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1116
diff changeset
80 SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
81 } else {
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
82 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
83 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
86 /* 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
87 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
88 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
89 {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
90 int i, p;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
91
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
92 if (MINTAUDIO_freqcount==MINTAUDIO_maxfreqs) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
93 return;
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
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
96 /* 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
97 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
98 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
99 break;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
100 }
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
101 }
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
102
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
103 /* Put all following ones farer */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
104 if (MINTAUDIO_freqcount>0) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
105 for (i=MINTAUDIO_freqcount; i>p; i--) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1116
diff changeset
106 SDL_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
107 }
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
108 }
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
109
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
110 /* And insert new one */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
111 MINTAUDIO_frequencies[p].frequency = frequency;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
112 MINTAUDIO_frequencies[p].masterclock = clock;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
113 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
114 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
115
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
116 MINTAUDIO_freqcount++;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
117 }
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 /* Search for the nearest frequency */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
120 int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq)
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 {
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 int i;
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
124 /* Only 1 freq ? */
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
125 if (MINTAUDIO_freqcount==1) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
126 return 0;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
129 /* Check the array */
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
130 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
131 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
132 MINTAUDIO_frequencies[i+1].frequency)>>1)) {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
133 return i;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
137 /* 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
138 return MINTAUDIO_freqcount-1;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 }
1111
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
140
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
141 /* 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
142 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
143 {
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
144 SndBufPtr pointers;
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
145 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
146
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
147 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
148 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
149 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
150 continue;
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
151
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
152 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
153 && ( (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
154 {
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
155 /* 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
156 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
157 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
158 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
159 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
160 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
161 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
162 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
163 } else {
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
164 /* 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
165 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
166 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
167 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
168 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
169 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
170 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
171 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
172 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
173
1116
080ed9ef0609 Sleep a bit less in thread
Patrice Mandin <patmandin@gmail.com>
parents: 1111
diff changeset
174 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
175 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
176 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
177 return 0;
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
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
180 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
181 {
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
182 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
183 return;
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_thread_finished)
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 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
189 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
190 Syield();
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
191 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
192 }