annotate src/audio/mint/SDL_mintaudio.c @ 3848:4de14c915f4c SDL-1.2

Updated the snapshot build target to reflect the new source location
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:23:11 +0000
parents 63a45a87a57e
children 782fd950bd46 c121d94672cb e958a003b69b
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 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
22 #include "SDL_config.h"
644
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 /*
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
25 Audio interrupt variables and callback function
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
26
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
27 Patrice Mandin
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
28 */
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
29
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
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include "SDL_audio.h"
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include "SDL_mintaudio.h"
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
38 #include "SDL_mintaudio_stfa.h"
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
40 /* The audio device */
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 SDL_AudioDevice *SDL_MintAudio_device;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
43 Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */
704
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
44 unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */
1819
63a45a87a57e Forgot to declare volatile stuff also in c file
Patrice Mandin <patmandin@gmail.com>
parents: 1402
diff changeset
45 volatile unsigned short SDL_MintAudio_numbuf; /* Buffer to play */
63a45a87a57e Forgot to declare volatile stuff also in c file
Patrice Mandin <patmandin@gmail.com>
parents: 1402
diff changeset
46 volatile unsigned short SDL_MintAudio_mutex;
63a45a87a57e Forgot to declare volatile stuff also in c file
Patrice Mandin <patmandin@gmail.com>
parents: 1402
diff changeset
47 volatile unsigned long SDL_MintAudio_clocktics;
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
48 cookie_stfa_t *SDL_MintAudio_stfa;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49
1111
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
50 /* 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
51 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
52 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
53 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
54 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
55
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
56 /* 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
57
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 void SDL_MintAudio_Callback(void)
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 Uint8 *buffer;
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
61 SDL_AudioDevice *audio = SDL_MintAudio_device;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 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
64 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
65
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
66 if (audio->paused)
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
67 return;
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
68
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
69 if (audio->convert.needed) {
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
70 int silence;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
72 if ( audio->convert.src_format == AUDIO_U8 ) {
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
73 silence = 0x80;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 } else {
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
75 silence = 0;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1116
diff changeset
77 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
78 audio->spec.callback(audio->spec.userdata,
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
79 (Uint8 *)audio->convert.buf,audio->convert.len);
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
80 SDL_ConvertAudio(&audio->convert);
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1116
diff changeset
81 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
82 } else {
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
83 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
84 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
87 /* 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
88 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
89 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
90 {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
91 int i, p;
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 if (MINTAUDIO_freqcount==MINTAUDIO_maxfreqs) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
94 return;
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
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
97 /* 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
98 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
99 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
100 break;
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
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
104 /* Put all following ones farer */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
105 if (MINTAUDIO_freqcount>0) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
106 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
107 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
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
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
111 /* And insert new one */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
112 MINTAUDIO_frequencies[p].frequency = frequency;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
113 MINTAUDIO_frequencies[p].masterclock = clock;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
114 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
115 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
116
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
117 MINTAUDIO_freqcount++;
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
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
120 /* Search for the nearest frequency */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
121 int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq)
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 {
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 int i;
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
125 /* Only 1 freq ? */
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
126 if (MINTAUDIO_freqcount==1) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
127 return 0;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
130 /* Check the array */
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
131 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
132 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
133 MINTAUDIO_frequencies[i+1].frequency)>>1)) {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
134 return i;
398
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 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
138 /* 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
139 return MINTAUDIO_freqcount-1;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 }
1111
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
141
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
142 /* 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
143 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
144 {
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
145 SndBufPtr pointers;
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
146 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
147
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
148 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
149 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
150 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
151 continue;
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
152
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
153 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
154 && ( (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
155 {
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
156 /* 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
157 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
158 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
159 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
160 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
161 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
162 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
163 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
164 } else {
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
165 /* 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
166 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
167 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
168 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
169 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
170 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
171 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
172 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
173 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
174
1116
080ed9ef0609 Sleep a bit less in thread
Patrice Mandin <patmandin@gmail.com>
parents: 1111
diff changeset
175 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
176 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
177 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
178 return 0;
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
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
181 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
182 {
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
183 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
184 return;
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
185
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
186 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
187 return;
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
188
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
189 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
190 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
191 Syield();
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
192 }
12c49532be00 Use MiNT thread to update DMA pointers instead of unusable MFP interrupt
Patrice Mandin <patmandin@gmail.com>
parents: 1107
diff changeset
193 }