30 typedef struct SDL_AudioDevice SDL_AudioDevice; |
30 typedef struct SDL_AudioDevice SDL_AudioDevice; |
31 #define _THIS SDL_AudioDevice *_this |
31 #define _THIS SDL_AudioDevice *_this |
32 |
32 |
33 /* Used by audio targets during DetectDevices() */ |
33 /* Used by audio targets during DetectDevices() */ |
34 typedef void (*SDL_AddAudioDevice)(const char *name); |
34 typedef void (*SDL_AddAudioDevice)(const char *name); |
|
35 |
|
36 /* This is the size of a packet when using SDL_QueueAudio(). We allocate |
|
37 these as necessary and pool them, under the assumption that we'll |
|
38 eventually end up with a handful that keep recycling, meeting whatever |
|
39 the app needs. We keep packing data tightly as more arrives to avoid |
|
40 wasting space, and if we get a giant block of data, we'll split them |
|
41 into multiple packets behind the scenes. My expectation is that most |
|
42 apps will have 2-3 of these in the pool. 8k should cover most needs, but |
|
43 if this is crippling for some embedded system, we can #ifdef this. |
|
44 The system preallocates enough packets for 2 callbacks' worth of data. */ |
|
45 #define SDL_AUDIOBUFFERQUEUE_PACKETLEN (8 * 1024) |
|
46 |
|
47 /* Used by apps that queue audio instead of using the callback. */ |
|
48 typedef struct SDL_AudioBufferQueue |
|
49 { |
|
50 Uint8 data[SDL_AUDIOBUFFERQUEUE_PACKETLEN]; /* packet data. */ |
|
51 Uint32 datalen; /* bytes currently in use in this packet. */ |
|
52 Uint32 startpos; /* bytes currently consumed in this packet. */ |
|
53 struct SDL_AudioBufferQueue *next; /* next item in linked list. */ |
|
54 } SDL_AudioBufferQueue; |
35 |
55 |
36 typedef struct SDL_AudioDriverImpl |
56 typedef struct SDL_AudioDriverImpl |
37 { |
57 { |
38 void (*DetectDevices) (int iscapture, SDL_AddAudioDevice addfn); |
58 void (*DetectDevices) (int iscapture, SDL_AddAudioDevice addfn); |
39 int (*OpenDevice) (_THIS, const char *devname, int iscapture); |
59 int (*OpenDevice) (_THIS, const char *devname, int iscapture); |
117 |
137 |
118 /* A thread to feed the audio device */ |
138 /* A thread to feed the audio device */ |
119 SDL_Thread *thread; |
139 SDL_Thread *thread; |
120 SDL_threadID threadid; |
140 SDL_threadID threadid; |
121 |
141 |
|
142 /* Queued buffers (if app not using callback). */ |
|
143 SDL_AudioBufferQueue *buffer_queue_head; /* device fed from here. */ |
|
144 SDL_AudioBufferQueue *buffer_queue_tail; /* queue fills to here. */ |
|
145 SDL_AudioBufferQueue *buffer_queue_pool; /* these are unused packets. */ |
|
146 Uint32 queued_bytes; /* number of bytes of audio data in the queue. */ |
|
147 |
122 /* * * */ |
148 /* * * */ |
123 /* Data private to this driver */ |
149 /* Data private to this driver */ |
124 struct SDL_PrivateAudioData *hidden; |
150 struct SDL_PrivateAudioData *hidden; |
125 }; |
151 }; |
126 #undef _THIS |
152 #undef _THIS |