annotate src/audio/mint/SDL_mintaudio.c @ 968:4675910b0b7b

Date: Mon, 11 Oct 2004 15:17:27 +0300 (EEST) From: Hannu Savolainen Subject: Re: SDL uses obsolete OSS features I did some work on getting OSS to work better with SDL. There have been some problems with select which should be fixed now. I'm having some problems in understanding what is the purpose of the DSP_WaitAudio() routine. I added a return to the very beginning of this routine and commendted out the define for USE_BLOCKING_WRITES. At least lbreakout2 seems to work as well as earlier. The latencies are the same. An ordinary blocking write does exactly the same thing than DSP_WaitAudio does. So I would recommend using the USE_BLOCKING_WRITES approach and removing everything from the DSP_WaitAudio routine. Also enabling USE_BLOCKING_WRITES makes it possible to simplify DSP_PlayAudio() because you don't need to handle the partial writes (the do-while loop). Attached is a patch against SDL-1.2.7. After these changes SDL will use OSS as it's designed to be used (make it as simple as possible). This code should work with all OSS implementations because it uses only the very fundamental features that have been there since the jurassic times.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 12 Nov 2004 21:39:04 +0000
parents 185acc07127a
children 2eca15c3f609
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;
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
54 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
55
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
56 if ( ! SDL_MintAudio_device->paused ) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
57 if ( SDL_MintAudio_device->convert.needed ) {
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
58 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
59 (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
60 SDL_ConvertAudio(&SDL_MintAudio_device->convert);
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
61 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
62 } else {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
63 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
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 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
68 /* Add a new frequency/clock/predivisor to the current list */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
69 void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock, Uint32 prediv)
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
70 {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
71 int i, p;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
72
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
73 if (MINTAUDIO_freqcount==MINTAUDIO_maxfreqs) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
74 return;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
75 }
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
76
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
77 /* 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
78 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
79 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
80 break;
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 }
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 /* Put all following ones farer */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
85 if (MINTAUDIO_freqcount>0) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
86 for (i=MINTAUDIO_freqcount; i>p; i--) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
87 MINTAUDIO_frequencies[i].frequency = MINTAUDIO_frequencies[i-1].frequency;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
88 MINTAUDIO_frequencies[i].masterclock = MINTAUDIO_frequencies[i-1].masterclock;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
89 MINTAUDIO_frequencies[i].predivisor = MINTAUDIO_frequencies[i-1].predivisor;
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 }
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 /* And insert new one */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
94 MINTAUDIO_frequencies[p].frequency = frequency;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
95 MINTAUDIO_frequencies[p].masterclock = clock;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
96 MINTAUDIO_frequencies[p].predivisor = prediv;
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
97
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
98 MINTAUDIO_freqcount++;
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 /* Search for the nearest frequency */
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
102 int SDL_MintAudio_SearchFrequency(_THIS, int desired_freq)
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 {
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 int i;
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
106 /* Only 1 freq ? */
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
107 if (MINTAUDIO_freqcount==1) {
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
108 return 0;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
111 /* Check the array */
961
185acc07127a Date: Fri, 29 Oct 2004 11:47:09 +0200
Patrice Mandin <patmandin@gmail.com>
parents: 769
diff changeset
112 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
113 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
114 MINTAUDIO_frequencies[i+1].frequency)>>1)) {
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
115 return i;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 }
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118
644
594422ab8f9f Atari MiNT: added more audio drivers
Patrice Mandin <patmandin@gmail.com>
parents: 557
diff changeset
119 /* 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
120 return MINTAUDIO_freqcount-1;
398
d219b0e02f5f Added Atari audio support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 }