Mercurial > sdl-ios-xcode
annotate src/audio/mint/SDL_mintaudio.c @ 769:b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 04 Jan 2004 16:49:27 +0000 |
parents | c4803992e09c |
children | 185acc07127a |
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 | 41 unsigned long SDL_MintAudio_audiosize; /* Length of audio buffer=spec->size */ |
42 unsigned short SDL_MintAudio_numbuf; /* Buffer to play */ | |
43 unsigned short SDL_MintAudio_mutex; | |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
44 cookie_stfa_t *SDL_MintAudio_stfa; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
46 /* 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
|
47 |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 void SDL_MintAudio_Callback(void) |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 { |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 Uint8 *buffer; |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
53 memset(buffer, SDL_MintAudio_device->spec.silence, SDL_MintAudio_device->spec.size); |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
55 if ( ! SDL_MintAudio_device->paused ) { |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
56 if ( SDL_MintAudio_device->convert.needed ) { |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
57 SDL_MintAudio_device->spec.callback(SDL_MintAudio_device->spec.userdata, |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
58 (Uint8 *)SDL_MintAudio_device->convert.buf,SDL_MintAudio_device->convert.len); |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
59 SDL_ConvertAudio(&SDL_MintAudio_device->convert); |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
60 memcpy(buffer, SDL_MintAudio_device->convert.buf, SDL_MintAudio_device->convert.len_cvt); |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 } else { |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
62 SDL_MintAudio_device->spec.callback(SDL_MintAudio_device->spec.userdata, buffer, SDL_MintAudio_device->spec.size); |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 } |
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 } |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
67 /* Simple function to search for the nearest frequency */ |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
68 int SDL_MintAudio_SearchFrequency(_THIS, int falcon_codec, int desired_freq) |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 { |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 int i; |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
72 /* Only 1 freq ? */ |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
73 if (MINTAUDIO_nfreq==1) { |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
74 return(MINTAUDIO_sfreq); |
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 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
77 /* Check the array */ |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
78 for (i=MINTAUDIO_sfreq; i<MINTAUDIO_nfreq-1; i++) { |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
79 /* Remove unusable falcon codec frequencies */ |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
80 if (falcon_codec) { |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
81 if ((i==6) || (i==8) || (i==10)) { |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
82 continue; |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
83 } |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
84 } |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
86 if (desired_freq >= ((MINTAUDIO_hardfreq[i]+MINTAUDIO_hardfreq[i+1])>>1)) { |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
87 return i; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 } |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 } |
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 |
644
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
91 /* Not in the array, give the latest */ |
594422ab8f9f
Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents:
557
diff
changeset
|
92 return MINTAUDIO_nfreq-1; |
398
d219b0e02f5f
Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 } |