annotate src/audio/mint/SDL_mintaudio.c @ 1107:856f76a099c7

Can use both clocks of FDI interface on Falcon, plus digital output
author Patrice Mandin <patmandin@gmail.com>
date Sun, 07 Aug 2005 12:17:28 +0000
parents 2eca15c3f609
children 12c49532be00
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>
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
31 #include "SDL_types.h"
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include "SDL_audio.h"
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include "SDL_mintaudio.h"
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
35 #include "SDL_mintaudio_stfa.h"
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
37 /* The audio device */
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 SDL_AudioDevice *SDL_MintAudio_device;
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
40 Uint8 *SDL_MintAudio_audiobuf[2]; /* Pointers to buffers */
704
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
41 unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
42 unsigned short SDL_MintAudio_numbuf; /* Buffer to play */
c4803992e09c Small bugfixes
Patrice Mandin <patmandin@gmail.com>
parents: 644
diff changeset
43 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
44 unsigned long SDL_MintAudio_clocktics;
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
45 cookie_stfa_t *SDL_MintAudio_stfa;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
47 /* 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
48
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 void SDL_MintAudio_Callback(void)
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 {
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 Uint8 *buffer;
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
52 SDL_AudioDevice *audio = SDL_MintAudio_device;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
55 memset(buffer, audio->spec.silence, audio->spec.size);
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
56
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
57 if (audio->paused)
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
58 return;
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
59
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
60 if (audio->convert.needed) {
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
61 int silence;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
63 if ( audio->convert.src_format == AUDIO_U8 ) {
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
64 silence = 0x80;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 } else {
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
66 silence = 0;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 }
1034
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
68 memset(audio->convert.buf, silence, audio->convert.len);
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
69 audio->spec.callback(audio->spec.userdata,
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
70 (Uint8 *)audio->convert.buf,audio->convert.len);
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
71 SDL_ConvertAudio(&audio->convert);
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
72 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
73 } else {
2eca15c3f609 clear convert.buf before filling it
Patrice Mandin <patmandin@gmail.com>
parents: 961
diff changeset
74 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
75 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
78 /* 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
79 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
80 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
81 {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
82 int i, p;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
83
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
84 if (MINTAUDIO_freqcount==MINTAUDIO_maxfreqs) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
85 return;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
86 }
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
87
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
88 /* 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
89 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
90 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
91 break;
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 }
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 /* Put all following ones farer */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
96 if (MINTAUDIO_freqcount>0) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
97 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
98 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
99 }
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 /* And insert new one */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
103 MINTAUDIO_frequencies[p].frequency = frequency;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
104 MINTAUDIO_frequencies[p].masterclock = clock;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
105 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
106 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
107
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
108 MINTAUDIO_freqcount++;
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 /* Search for the nearest frequency */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
112 int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq)
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 {
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 int i;
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
116 /* Only 1 freq ? */
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
117 if (MINTAUDIO_freqcount==1) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
118 return 0;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
121 /* Check the array */
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
122 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
123 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
124 MINTAUDIO_frequencies[i+1].frequency)>>1)) {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
125 return i;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 }
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 /* 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
130 return MINTAUDIO_freqcount-1;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 }