annotate libao2/ao_sdl.c @ 986:fadb8eeff7a8

commitus interruptus
author gabucino
date Mon, 04 Jun 2001 08:06:20 +0000
parents 95391cf9e994
children dfa641c44d4a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
1 /*
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
2 * ao_sdl.c - libao2 SDLlib Audio Output Driver for MPlayer
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
3 *
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
4 * This driver is under the same license as MPlayer.
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
5 * (http://mplayer.sf.net)
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
6 *
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
7 * Copyleft 2001 by Felix Bünemann (atmosfear@users.sf.net)
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
8 *
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
9 * Thanks to Arpi for nice ringbuffer-code!
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
10 *
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
11 */
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
12
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
13 #include <stdio.h>
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
14
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
15 #include "audio_out.h"
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
16 #include "audio_out_internal.h"
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
17
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
18 #include "../libvo/fastmemcpy.h"
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
19
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
20 static ao_info_t info =
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
21 {
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
22 "SDLlib audio output",
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
23 "sdl",
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
24 "Felix Buenemann <atmosfear@users.sourceforge.net>",
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
25 ""
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
26 };
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
27
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
28 LIBAO_EXTERN(sdl)
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
29
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
30 // there are some globals:
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
31 // ao_samplerate
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
32 // ao_channels
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
33 // ao_format
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
34 // ao_bps
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
35 // ao_outburst
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
36 // ao_buffersize
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
37
983
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
38 extern int verbose;
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
39 /* audio driver to be used by SDLlib */
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
40 char *sdl_adriver;
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
41
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
42 // Samplesize used by the SDLlib AudioSpec struct
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
43 #define SAMPLESIZE 512
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
44
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
45 // General purpose Ring-buffering routines
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
46
974
0d4e4da7c126 -abs support
arpi_esp
parents: 972
diff changeset
47 #define BUFFSIZE 4096
0d4e4da7c126 -abs support
arpi_esp
parents: 972
diff changeset
48 #define NUM_BUFS 16
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
49
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
50 static unsigned char *buffer[NUM_BUFS];
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
51
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
52 static unsigned int buf_read=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
53 static unsigned int buf_write=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
54 static unsigned int buf_read_pos=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
55 static unsigned int buf_write_pos=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
56
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
57 static int full_buffers=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
58 static int buffered_bytes=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
59
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
60 static int write_buffer(unsigned char* data,int len){
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
61 int len2=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
62 int x;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
63 while(len>0){
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
64 if(full_buffers==NUM_BUFS) break;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
65 x=BUFFSIZE-buf_write_pos;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
66 if(x>len) x=len;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
67 memcpy(buffer[buf_write]+buf_write_pos,data+len2,x);
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
68 len2+=x; len-=x;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
69 buffered_bytes+=x; buf_write_pos+=x;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
70 if(buf_write_pos>=BUFFSIZE){
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
71 // block is full, find next!
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
72 buf_write=(buf_write+1)%NUM_BUFS;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
73 ++full_buffers;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
74 buf_write_pos=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
75 }
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
76 }
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
77 return len2;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
78 }
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
79
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
80 static int read_buffer(unsigned char* data,int len){
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
81 int len2=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
82 int x;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
83 while(len>0){
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
84 if(full_buffers==0) break; // no more data buffered!
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
85 x=BUFFSIZE-buf_read_pos;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
86 if(x>len) x=len;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
87 memcpy(data+len2,buffer[buf_read]+buf_read_pos,x);
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
88 len2+=x; len-=x;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
89 buffered_bytes-=x; buf_read_pos+=x;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
90 if(buf_read_pos>=BUFFSIZE){
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
91 // block is empty, find next!
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
92 buf_read=(buf_read+1)%NUM_BUFS;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
93 --full_buffers;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
94 buf_read_pos=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
95 }
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
96 }
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
97 return len2;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
98 }
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
99
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
100 // end ring buffer stuff
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
101
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
102 #ifdef __FreeBSD__
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
103 #include <SDL11/SDL.h>
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
104 #else
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
105 #include <SDL/SDL.h>
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
106 #endif
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
107
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
108 // to set/get/query special features/parameters
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
109 static int control(int cmd,int arg){
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
110 return -1;
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
111 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
112
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
113 // SDL Callback function
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
114 void outputaudio(void *unused, Uint8 *stream, int len) {
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
115 //SDL_MixAudio(stream, read_buffer(buffers, len), len, SDL_MIX_MAXVOLUME);
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
116 read_buffer(stream, len);
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
117 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
118
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
119 // open & setup audio device
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
120 // return: 1=success 0=fail
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
121 static int init(int rate,int channels,int format,int flags){
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
122
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
123 /* SDL Audio Specifications */
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
124 SDL_AudioSpec aspec;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
125
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
126 int i;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
127 /* Allocate ring-buffer memory */
983
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
128 for(i=0;i<NUM_BUFS;i++) buffer[i]=(unsigned char *) malloc(BUFFSIZE);
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
129
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
130 printf("SDL: Samplerate: %iHz Channels: %s Format %iBit\n", rate, (channels > 1) ? "Stereo" : "Mono", format);
983
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
131
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
132 if(sdl_adriver) {
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
133 setenv("SDL_AUDIODRIVER", sdl_adriver, 1);
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
134 printf("SDL: using %s audio driver\n", sdl_adriver);
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
135 }
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
136
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
137
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
138 /* The desired audio frequency in samples-per-second. */
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
139 aspec.freq = rate;
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
140
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
141 /* The desired audio format (see SDL_AudioSpec) */
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
142 aspec.format = (format == 16) ? AUDIO_S16 : AUDIO_U8;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
143
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
144 /* Number of channels (mono/stereo) */
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
145 aspec.channels = channels;
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
146
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
147 /* The desired size of the audio buffer in samples. This number should be a power of two, and may be adjusted by the audio driver to a value more suitable for the hardware. Good values seem to range between 512 and 8192 inclusive, depending on the application and CPU speed. Smaller values yield faster response time, but can lead to underflow if the application is doing heavy processing and cannot fill the audio buffer in time. A stereo sample consists of both right and left channels in LR ordering. Note that the number of samples is directly related to time by the following formula: ms = (samples*1000)/freq */
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
148 aspec.samples = SAMPLESIZE;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
149
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
150 /* This should be set to a function that will be called when the audio device is ready for more data. It is passed a pointer to the audio buffer, and the length in bytes of the audio buffer. This function usually runs in a separate thread, and so you should protect data structures that it accesses by calling SDL_LockAudio and SDL_UnlockAudio in your code. The callback prototype is:
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
151 void callback(void *userdata, Uint8 *stream, int len); userdata is the pointer stored in userdata field of the SDL_AudioSpec. stream is a pointer to the audio buffer you want to fill with information and len is the length of the audio buffer in bytes. */
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
152 aspec.callback = outputaudio;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
153
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
154 /* This pointer is passed as the first parameter to the callback function. */
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
155 aspec.userdata = NULL;
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
156
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
157 /* initialize the SDL Audio system */
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
158 if (SDL_Init (SDL_INIT_AUDIO/*|SDL_INIT_NOPARACHUTE*/)) {
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
159 printf("SDL: Initializing of SDL Audio failed: %s.\n", SDL_GetError());
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
160 return 0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
161 }
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
162
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
163 /* Open the audio device and start playing sound! */
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
164 if(SDL_OpenAudio(&aspec, NULL) < 0) {
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
165 printf("SDL: Unable to open audio: %s\n", SDL_GetError());
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
166 return(0);
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
167 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
168
983
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
169 if(verbose) printf("SDL: buf size = %d\n",aspec.size);
975
65353ed24ac5 -abs support - fixed
arpi_esp
parents: 974
diff changeset
170 if(ao_buffersize==-1) ao_buffersize=aspec.size;
974
0d4e4da7c126 -abs support
arpi_esp
parents: 972
diff changeset
171
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
172 /* unsilence audio, if callback is ready */
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
173 SDL_PauseAudio(0);
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
174
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
175 return 1;
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
176 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
177
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
178 // close audio device
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
179 static void uninit(){
983
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
180 if(verbose) printf("SDL: Audio Subsystem shutting down!\n");
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
181 SDL_CloseAudio();
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
182 SDL_QuitSubSystem(SDL_INIT_AUDIO);
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
183 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
184
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
185 // stop playing and empty buffers (for seeking/pause)
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
186 static void reset(){
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
187
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
188 /* Reset ring-buffer state */
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
189 buf_read=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
190 buf_write=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
191 buf_read_pos=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
192 buf_write_pos=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
193
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
194 full_buffers=0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
195 buffered_bytes=0;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
196
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
197 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
198
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
199 // return: how many bytes can be played without blocking
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
200 static int get_space(){
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
201 return (NUM_BUFS-full_buffers)*BUFFSIZE - buf_write_pos;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
202 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
203
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
204 // plays 'len' bytes of 'data'
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
205 // it should round it down to outburst*n
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
206 // return: number of bytes played
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
207 static int play(void* data,int len,int flags){
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
208
985
95391cf9e994 Microchange =)
atmosfear
parents: 983
diff changeset
209 #if 0
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
210 int ret;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
211
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
212 /* Audio locking prohibits call of outputaudio */
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
213 SDL_LockAudio();
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
214 // copy audio stream into ring-buffer
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
215 ret = write_buffer(data, len);
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
216 SDL_UnlockAudio();
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
217
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
218 return ret;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
219 #else
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
220 return write_buffer(data, len);
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
221 #endif
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
222 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
223
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
224 // return: how many unplayed bytes are in the buffer
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
225 static int get_delay(){
974
0d4e4da7c126 -abs support
arpi_esp
parents: 972
diff changeset
226 return buffered_bytes + ao_buffersize;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
227 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
228
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
229
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
230
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
231
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
232
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
233