annotate libao2/ao_sdl.c @ 21256:ba973742b3ae

Remove config.h, there are multiple files under that name, inviting bugs and confusion. This file only contained two definitions, one commented out, the other never activated.
author diego
date Sun, 26 Nov 2006 15:42:38 +0000
parents f580a7755ac5
children cc6dc96035b8
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.
11750
9b6e480622c4 URL updated.
diego
parents: 10838
diff changeset
5 * (http://www.mplayerhq.hu)
972
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>
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
14 #include <stdlib.h>
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 12027
diff changeset
15 #include <string.h>
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
16
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13887
diff changeset
17 #include "config.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 13887
diff changeset
18 #include "mp_msg.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 13887
diff changeset
19 #include "help_mp.h"
8027
b9da278e4c92 verbose can be negative
arpi
parents: 7908
diff changeset
20
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
21 #include "audio_out.h"
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
22 #include "audio_out_internal.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
23 #include "libaf/af_format.h"
6184
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
24 #include <SDL.h>
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 12027
diff changeset
25 #include "osdep/timer.h"
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
26
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13887
diff changeset
27 #include "libvo/fastmemcpy.h"
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
28
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
29 static ao_info_t info =
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
30 {
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
31 "SDLlib audio output",
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
32 "sdl",
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
33 "Felix Buenemann <atmosfear@users.sourceforge.net>",
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
34 ""
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
35 };
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
36
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
37 LIBAO_EXTERN(sdl)
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
38
12673
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
39 // turn this on if you want to use the slower SDL_MixAudio
12908
7b9b4f07d2c4 automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents: 12714
diff changeset
40 #undef USE_SDL_INTERNAL_MIXER
12673
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
41
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
42 // Samplesize used by the SDLlib AudioSpec struct
12113
07d9c8fa6897 restore old SAMPLESIZE
faust3
parents: 12093
diff changeset
43 #ifdef WIN32
12019
6ede5366bc47 fix compilation with sdl on mingw patch by Nehal <nehalmistry at gmx.net>
faust3
parents: 11750
diff changeset
44 #define SAMPLESIZE 2048
12113
07d9c8fa6897 restore old SAMPLESIZE
faust3
parents: 12093
diff changeset
45 #else
07d9c8fa6897 restore old SAMPLESIZE
faust3
parents: 12093
diff changeset
46 #define SAMPLESIZE 1024
07d9c8fa6897 restore old SAMPLESIZE
faust3
parents: 12093
diff changeset
47 #endif
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
48
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
49 #define CHUNK_SIZE 4096
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
50 #define NUM_CHUNKS 8
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
51 // This type of ring buffer may never fill up completely, at least
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
52 // one byte must always be unused.
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
53 // For performance reasons (alignment etc.) one whole chunk always stays
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
54 // empty, not only one byte.
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
55 #define BUFFSIZE ((NUM_CHUNKS + 1) * CHUNK_SIZE)
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
56
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
57 static unsigned char *buffer;
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
58
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
59 // may only be modified by SDL's playback thread or while it is stopped
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
60 static volatile int read_pos;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
61 // may only be modified by mplayer's thread
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
62 static volatile int write_pos;
12673
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
63 #ifdef USE_SDL_INTERNAL_MIXER
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 12027
diff changeset
64 static unsigned char volume=SDL_MIX_MAXVOLUME;
12673
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
65 #endif
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
66
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
67 // may only be called by mplayer's thread
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
68 // return value may change between immediately following two calls,
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
69 // and the real number of free bytes might be larger!
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 17245
diff changeset
70 static int buf_free(void) {
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
71 int free = read_pos - write_pos - CHUNK_SIZE;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
72 if (free < 0) free += BUFFSIZE;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
73 return free;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
74 }
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
75
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
76 // may only be called by SDL's playback thread
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
77 // return value may change between immediately following two calls,
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
78 // and the real number of buffered bytes might be larger!
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 17245
diff changeset
79 static int buf_used(void) {
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
80 int used = write_pos - read_pos;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
81 if (used < 0) used += BUFFSIZE;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
82 return used;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
83 }
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
84
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
85 static int write_buffer(unsigned char* data,int len){
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
86 int first_len = BUFFSIZE - write_pos;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
87 int free = buf_free();
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
88 if (len > free) len = free;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
89 if (first_len > len) first_len = len;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
90 // till end of buffer
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
91 memcpy (&buffer[write_pos], data, first_len);
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
92 if (len > first_len) { // we have to wrap around
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
93 // remaining part from beginning of buffer
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
94 memcpy (buffer, &data[first_len], len - first_len);
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
95 }
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
96 write_pos = (write_pos + len) % BUFFSIZE;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
97 return len;
972
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 static int read_buffer(unsigned char* data,int len){
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
101 int first_len = BUFFSIZE - read_pos;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
102 int buffered = buf_used();
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
103 if (len > buffered) len = buffered;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
104 if (first_len > len) first_len = len;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
105 // till end of buffer
12673
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
106 #ifdef USE_SDL_INTERNAL_MIXER
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
107 SDL_MixAudio (data, &buffer[read_pos], first_len, volume);
12673
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
108 #else
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
109 memcpy (data, &buffer[read_pos], first_len);
12673
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
110 #endif
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
111 if (len > first_len) { // we have to wrap around
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
112 // remaining part from beginning of buffer
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
113 #ifdef USE_SDL_INTERNAL_MIXER
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
114 SDL_MixAudio (&data[first_len], buffer, len - first_len, volume);
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
115 #else
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
116 memcpy (&data[first_len], buffer, len - first_len);
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
117 #endif
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
118 }
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
119 read_pos = (read_pos + len) % BUFFSIZE;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
120 return len;
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
121 }
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
122
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
123 // end ring buffer stuff
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
124
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
125
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
126 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 8027
diff changeset
127 static int control(int cmd,void *arg){
12673
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
128 #ifdef USE_SDL_INTERNAL_MIXER
6184
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
129 switch (cmd) {
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
130 case AOCONTROL_GET_VOLUME:
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
131 {
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
132 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 12027
diff changeset
133 vol->left = vol->right = volume * 100 / SDL_MIX_MAXVOLUME;
6184
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
134 return CONTROL_OK;
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
135 }
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
136 case AOCONTROL_SET_VOLUME:
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
137 {
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 12027
diff changeset
138 int diff;
6184
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
139 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
140 diff = (vol->left+vol->right) / 2;
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 12027
diff changeset
141 volume = diff * SDL_MIX_MAXVOLUME / 100;
6184
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
142 return CONTROL_OK;
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
143 }
47297acadbfb Add volume control, patch by
atmos4
parents: 3137
diff changeset
144 }
12673
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
145 #endif
c1371fce7267 make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents: 12440
diff changeset
146 return CONTROL_UNKNOWN;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
147 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
148
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
149 // SDL Callback function
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
150 void outputaudio(void *unused, Uint8 *stream, int len) {
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
151 //SDL_MixAudio(stream, read_buffer(buffers, len), len, SDL_MIX_MAXVOLUME);
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
152 //if(!full_buffers) printf("SDL: Buffer underrun!\n");
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
153
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
154 read_buffer(stream, len);
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
155 //printf("SDL: Full Buffers: %i\n", full_buffers);
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
156 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
157
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
158 // open & setup audio device
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
159 // return: 1=success 0=fail
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
160 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
161
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
162 /* SDL Audio Specifications */
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
163 SDL_AudioSpec aspec, obtained;
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
164
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
165 /* Allocate ring-buffer memory */
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
166 buffer = (unsigned char *) malloc(BUFFSIZE);
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
167
14264
cb5fbade8a5c af_fmt2str_short
alex
parents: 14245
diff changeset
168 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_SDL_INFO, rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));
983
cb0e3b29a0dd Several small changes (like driver selection).
atmosfear
parents: 975
diff changeset
169
1189
7c6bcb281966 sdl_adriver liquidated, ao_subdevice used
al3x
parents: 1091
diff changeset
170 if(ao_subdevice) {
7c6bcb281966 sdl_adriver liquidated, ao_subdevice used
al3x
parents: 1091
diff changeset
171 setenv("SDL_AUDIODRIVER", ao_subdevice, 1);
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12908
diff changeset
172 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_SDL_DriverInfo, ao_subdevice);
1189
7c6bcb281966 sdl_adriver liquidated, ao_subdevice used
al3x
parents: 1091
diff changeset
173 }
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1238
diff changeset
174
7660
7ff053498bf2 fill ao_data correctly
arpi
parents: 6956
diff changeset
175 ao_data.channels=channels;
7ff053498bf2 fill ao_data correctly
arpi
parents: 6956
diff changeset
176 ao_data.samplerate=rate;
7ff053498bf2 fill ao_data correctly
arpi
parents: 6956
diff changeset
177 ao_data.format=format;
7ff053498bf2 fill ao_data correctly
arpi
parents: 6956
diff changeset
178
3137
b9ee2d8d7279 Audio delay bugfix
anders
parents: 3095
diff changeset
179 ao_data.bps=channels*rate;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
180 if(format != AF_FORMAT_U8 && format != AF_FORMAT_S8)
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1238
diff changeset
181 ao_data.bps*=2;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
182
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
183 /* The desired audio format (see SDL_AudioSpec) */
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
184 switch(format) {
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
185 case AF_FORMAT_U8:
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
186 aspec.format = AUDIO_U8;
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
187 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
188 case AF_FORMAT_S16_LE:
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
189 aspec.format = AUDIO_S16LSB;
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
190 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
191 case AF_FORMAT_S16_BE:
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
192 aspec.format = AUDIO_S16MSB;
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
193 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
194 case AF_FORMAT_S8:
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
195 aspec.format = AUDIO_S8;
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
196 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
197 case AF_FORMAT_U16_LE:
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
198 aspec.format = AUDIO_U16LSB;
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
199 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
200 case AF_FORMAT_U16_BE:
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
201 aspec.format = AUDIO_U16MSB;
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
202 break;
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
203 default:
12440
56bdb9b7a4bc use fallback for unsupported formats instead of quitting
reimar
parents: 12151
diff changeset
204 aspec.format = AUDIO_S16LSB;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
205 ao_data.format = AF_FORMAT_S16_LE;
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12908
diff changeset
206 mp_msg(MSGT_AO,MSGL_WARN,MSGTR_AO_SDL_UnsupportedAudioFmt, format);
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
207 }
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
208
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
209 /* The desired audio frequency in samples-per-second. */
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
210 aspec.freq = rate;
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
211
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
212 /* Number of channels (mono/stereo) */
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
213 aspec.channels = channels;
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
214
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
215 /* 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
216 aspec.samples = SAMPLESIZE;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
217
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
218 /* 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
219 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
220 aspec.callback = outputaudio;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
221
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
222 /* 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
223 aspec.userdata = NULL;
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
224
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
225 /* initialize the SDL Audio system */
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
226 if (SDL_Init (SDL_INIT_AUDIO/*|SDL_INIT_NOPARACHUTE*/)) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12908
diff changeset
227 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_SDL_CantInit, SDL_GetError());
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
228 return 0;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
229 }
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
230
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
231 /* Open the audio device and start playing sound! */
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
232 if(SDL_OpenAudio(&aspec, &obtained) < 0) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12908
diff changeset
233 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_SDL_CantOpenAudio, SDL_GetError());
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
234 return(0);
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
235 }
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
236
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
237 /* did we got what we wanted ? */
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
238 ao_data.channels=obtained.channels;
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
239 ao_data.samplerate=obtained.freq;
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
240
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
241 switch(obtained.format) {
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
242 case AUDIO_U8 :
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
243 ao_data.format = AF_FORMAT_U8;
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
244 break;
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
245 case AUDIO_S16LSB :
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
246 ao_data.format = AF_FORMAT_S16_LE;
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
247 break;
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
248 case AUDIO_S16MSB :
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
249 ao_data.format = AF_FORMAT_S16_BE;
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
250 break;
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
251 case AUDIO_S8 :
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
252 ao_data.format = AF_FORMAT_S8;
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
253 break;
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
254 case AUDIO_U16LSB :
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
255 ao_data.format = AF_FORMAT_U16_LE;
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
256 break;
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
257 case AUDIO_U16MSB :
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
258 ao_data.format = AF_FORMAT_U16_BE;
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
259 break;
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
260 default:
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12908
diff changeset
261 mp_msg(MSGT_AO,MSGL_WARN,MSGTR_AO_SDL_UnsupportedAudioFmt, obtained.format);
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
262 return 0;
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
263 }
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
264
8027
b9da278e4c92 verbose can be negative
arpi
parents: 7908
diff changeset
265 mp_msg(MSGT_AO,MSGL_V,"SDL: buf size = %d\n",obtained.size);
7908
dc96a3eb9fab Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents: 7897
diff changeset
266 ao_data.buffersize=obtained.size;
13887
48ce49693b3c respect immed uninit flag, initialize ao_data.outburst.
reimar
parents: 13832
diff changeset
267 ao_data.outburst = CHUNK_SIZE;
974
0d4e4da7c126 -abs support
arpi_esp
parents: 972
diff changeset
268
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
269 reset();
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
270 /* unsilence audio, if callback is ready */
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
271 SDL_PauseAudio(0);
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
272
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
273 return 1;
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
274 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
275
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
276 // close audio device
12145
99798c3cdb93 uninit immed flag
alex
parents: 12113
diff changeset
277 static void uninit(int immed){
8027
b9da278e4c92 verbose can be negative
arpi
parents: 7908
diff changeset
278 mp_msg(MSGT_AO,MSGL_V,"SDL: Audio Subsystem shutting down!\n");
13887
48ce49693b3c respect immed uninit flag, initialize ao_data.outburst.
reimar
parents: 13832
diff changeset
279 if (!immed)
14849
d313f591d1a4 aos should respect the immed uninit flag (quit immediatly vs waiting till file
reimar
parents: 14264
diff changeset
280 usec_sleep(get_delay() * 1000 * 1000);
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
281 SDL_CloseAudio();
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
282 SDL_QuitSubSystem(SDL_INIT_AUDIO);
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
283 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
284
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
285 // stop playing and empty buffers (for seeking/pause)
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 17245
diff changeset
286 static void reset(void){
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
287
1091
06fd776f6b59 Lock callback on pause, unlock on resume.
atmosfear
parents: 1070
diff changeset
288 //printf("SDL: reset called!\n");
1066
aecab161d8d6 Better audio format handling.
atmosfear
parents: 1038
diff changeset
289
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
290 SDL_PauseAudio(1);
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
291 /* Reset ring-buffer state */
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
292 read_pos = 0;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
293 write_pos = 0;
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
294 SDL_PauseAudio(0);
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
295 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
296
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
297 // stop playing, keep buffers (for pause)
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 17245
diff changeset
298 static void audio_pause(void)
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
299 {
1070
e45a029db4c3 Better format info.
atmosfear
parents: 1066
diff changeset
300
1091
06fd776f6b59 Lock callback on pause, unlock on resume.
atmosfear
parents: 1070
diff changeset
301 //printf("SDL: audio_pause called!\n");
7897
7674e94baff7 Change SDL_(Un)lockAudio to PauseAudio() (works better)
colin
parents: 7660
diff changeset
302 SDL_PauseAudio(1);
1070
e45a029db4c3 Better format info.
atmosfear
parents: 1066
diff changeset
303
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
304 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
305
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
306 // resume playing, after audio_pause()
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 17245
diff changeset
307 static void audio_resume(void)
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
308 {
1091
06fd776f6b59 Lock callback on pause, unlock on resume.
atmosfear
parents: 1070
diff changeset
309 //printf("SDL: audio_resume called!\n");
7897
7674e94baff7 Change SDL_(Un)lockAudio to PauseAudio() (works better)
colin
parents: 7660
diff changeset
310 SDL_PauseAudio(0);
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
311 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
312
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 993
diff changeset
313
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
314 // return: how many bytes can be played without blocking
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 17245
diff changeset
315 static int get_space(void){
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
316 return buf_free();
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
317 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
318
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
319 // plays 'len' bytes of 'data'
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
320 // it should round it down to outburst*n
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
321 // return: number of bytes played
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
322 static int play(void* data,int len,int flags){
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
323
12151
75fdb659f5bf round len to outburst and increment full_buffers at the correct time, patch by Nehal <nehalmistry at gmx.net>
faust3
parents: 12145
diff changeset
324 len = (len/ao_data.outburst)*ao_data.outburst;
985
95391cf9e994 Microchange =)
atmosfear
parents: 983
diff changeset
325 #if 0
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
326 int ret;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
327
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
328 /* Audio locking prohibits call of outputaudio */
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
329 SDL_LockAudio();
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
330 // copy audio stream into ring-buffer
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
331 ret = write_buffer(data, len);
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
332 SDL_UnlockAudio();
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
333
972
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
334 return ret;
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
335 #else
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
336 return write_buffer(data, len);
b49f89b3ab2e Yea, it worksss!
atmosfear
parents: 966
diff changeset
337 #endif
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
338 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
339
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1238
diff changeset
340 // return: delay in seconds between first and last sample in buffer
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 17245
diff changeset
341 static float get_delay(void){
13832
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
342 int buffered = BUFFSIZE - CHUNK_SIZE - buf_free(); // could be less
2f8cfe66dbfd Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents: 13383
diff changeset
343 return (float)(buffered + ao_data.buffersize)/(float)ao_data.bps;
966
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
344 }
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
345
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
346
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
347
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
348
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
349
69b4f944ce08 Added support for sdl audio out (buggy pre-alpha).
atmosfear
parents:
diff changeset
350