ReactOS 0.4.15-dev-8227-g32d615f
rdpsnd_libao.c File Reference
#include "rdesktop.h"
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <ao/ao.h>
#include <sys/time.h>
Include dependency graph for rdpsnd_libao.c:

Go to the source code of this file.

Classes

struct  audio_packet
 

Macros

#define MAX_QUEUE   10
 
#define WAVEOUTBUF   16
 

Functions

BOOL wave_out_open (void)
 
void wave_out_close (void)
 
BOOL wave_out_format_supported (WAVEFORMATEX *pwfx)
 
BOOL wave_out_set_format (WAVEFORMATEX *pwfx)
 
void wave_out_volume (uint16 left, uint16 right)
 
void wave_out_write (STREAM s, uint16 tick, uint8 index)
 
void wave_out_play (void)
 

Variables

int This dsp_
 
ao_device * o_device = NULL
 
int default_driver
 
int g_samplerate
 
int This channels
 
BOOL This dsp_bu = False
 
static BOOL g_reopened
 
static short g_samplewidth
 
static struct audio_packet packet_queue [MAX_QUEUE]
 
static unsigned int queue_hi
 
static unsigned int queue_lo
 

Macro Definition Documentation

◆ MAX_QUEUE

#define MAX_QUEUE   10

Definition at line 30 of file rdpsnd_libao.c.

◆ WAVEOUTBUF

#define WAVEOUTBUF   16

Definition at line 31 of file rdpsnd_libao.c.

Function Documentation

◆ wave_out_close()

void wave_out_close ( void  )

Definition at line 80 of file rdpsnd_libao.c.

81{
82 /* Ack all remaining packets */
83 while (queue_lo != queue_hi)
84 {
87 queue_lo = (queue_lo + 1) % MAX_QUEUE;
88 }
89
90 if (o_device != NULL)
91 ao_close(o_device);
92
93 ao_shutdown();
94}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
GLdouble s
Definition: gl.h:2039
GLuint index
Definition: glext.h:6031
void rdpsnd_send_completion(RDPCLIENT *This, uint16 tick, uint8 packet_index)
Definition: rdpsnd.c:55
static unsigned int queue_lo
Definition: rdpsnd_libao.c:48
ao_device * o_device
Definition: rdpsnd_libao.c:34
static unsigned int queue_hi
Definition: rdpsnd_libao.c:48
#define MAX_QUEUE
Definition: rdpsnd_libao.c:30
static struct audio_packet packet_queue[MAX_QUEUE]

Referenced by rdpsnd_process(), and rdpsnd_process_negotiate().

◆ wave_out_format_supported()

BOOL wave_out_format_supported ( WAVEFORMATEX pwfx)

Definition at line 97 of file rdpsnd_libao.c.

98{
99 if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
100 return False;
101 if ((pwfx->nChannels != 1) && (pwfx->nChannels != 2))
102 return False;
103 if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
104 return False;
105 /* The only common denominator between libao output drivers is a sample-rate of
106 44100, we need to upsample 22050 to it */
107 if ((pwfx->nSamplesPerSec != 44100) && (pwfx->nSamplesPerSec != 22050))
108 return False;
109
110 return True;
111}
#define WAVE_FORMAT_PCM
Definition: constants.h:425
#define False
Definition: types.h:25
#define True
Definition: types.h:24
WORD wBitsPerSample
Definition: audioclient.idl:45
DWORD nSamplesPerSec
Definition: audioclient.idl:42

Referenced by rdpsnd_process_negotiate().

◆ wave_out_open()

BOOL wave_out_open ( void  )

Definition at line 51 of file rdpsnd_libao.c.

52{
53 ao_sample_format format;
54
55 ao_initialize();
56 default_driver = ao_default_driver_id();
57
58 format.bits = 16;
59 format.channels = 2;
60 This->channels = 2;
61 format.rate = 44100;
62 g_samplerate = 44100;
63 format.byte_format = AO_FMT_LITTLE;
64
65 o_device = ao_open_live(default_driver, &format, NULL);
66 if (o_device == NULL)
67 {
68 return False;
69 }
70
71 This->dsp_ = 0;
72 queue_lo = queue_hi = 0;
73
75
76 return True;
77}
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
int g_samplerate
Definition: rdpsnd_libao.c:36
static BOOL g_reopened
Definition: rdpsnd_libao.c:39
int default_driver
Definition: rdpsnd_libao.c:35

Referenced by rdpsnd_process(), and rdpsnd_process_negotiate().

◆ wave_out_play()

void wave_out_play ( void  )

Definition at line 174 of file rdpsnd_libao.c.

175{
176 struct audio_packet *packet;
177 STREAM out;
178 char outbuf[WAVEOUTBUF];
179 int offset, len, i;
180 static long prev_s, prev_us;
181 unsigned int duration;
182 struct timeval tv;
183 int next_tick;
184
185 if (g_reopened)
186 {
188 gettimeofday(&tv, NULL);
189 prev_s = tv.tv_sec;
190 prev_us = tv.tv_usec;
191 }
192
193 if (queue_lo == queue_hi)
194 {
195 This->dsp_bu = 0;
196 return;
197 }
198
200 out = &packet->s;
201
202 if (((queue_lo + 1) % MAX_QUEUE) != queue_hi)
203 {
204 next_tick = packet_queue[(queue_lo + 1) % MAX_QUEUE].tick;
205 }
206 else
207 {
208 next_tick = (packet->tick + 65535) % 65536;
209 }
210
211 len = 0;
212
213 if (g_samplerate == 22050)
214 {
215 /* Resample to 44100 */
216 for (i = 0; (i < ((WAVEOUTBUF / 4) * (3 - g_samplewidth))) && (out->p < out->end);
217 i++)
218 {
219 /* On a stereo-channel we must make sure that left and right
220 does not get mixed up, so we need to expand the sample-
221 data with channels in mind: 1234 -> 12123434
222 If we have a mono-channel, we can expand the data by simply
223 doubling the sample-data: 1234 -> 11223344 */
224 if (This->channels == 2)
225 offset = ((i * 2) - (i & 1)) * g_samplewidth;
226 else
227 offset = (i * 2) * g_samplewidth;
228
229 memcpy(&outbuf[offset], out->p, g_samplewidth);
230 memcpy(&outbuf[This->channels * g_samplewidth + offset], out->p, g_samplewidth);
231
232 out->p += g_samplewidth;
233 len += 2 * g_samplewidth;
234 }
235 }
236 else
237 {
238 len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF;
239 memcpy(outbuf, out->p, len);
240 out->p += len;
241 }
242
243 ao_play(o_device, outbuf, len);
244
245 gettimeofday(&tv, NULL);
246
247 duration = ((tv.tv_sec - prev_s) * 1000000 + (tv.tv_usec - prev_us)) / 1000;
248
249 if (packet->tick > next_tick)
250 next_tick += 65536;
251
252 if ((out->p == out->end) || duration > next_tick - packet->tick + 500)
253 {
254 prev_s = tv.tv_sec;
255 prev_us = tv.tv_usec;
256
257 if (abs((next_tick - packet->tick) - duration) > 20)
258 {
259 DEBUG(("duration: %d, calc: %d, ", duration, next_tick - packet->tick));
260 DEBUG(("last: %d, is: %d, should: %d\n", packet->tick,
261 (packet->tick + duration) % 65536, next_tick % 65536));
262 }
263
264 /* Until all drivers are using the windows sound-ticks, we need to
265 substract the 50 ticks added later by rdpsnd.c */
266 rdpsnd_send_completion(((packet->tick + duration) % 65536) - 50, packet->index);
267 free(out->data);
268 queue_lo = (queue_lo + 1) % MAX_QUEUE;
269 }
270
271 This->dsp_bu = 1;
272 return;
273}
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159
#define DEBUG(args)
Definition: rdesktop.h:129
#define abs(i)
Definition: fconv.c:206
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static short g_samplewidth
Definition: rdpsnd_libao.c:40
#define WAVEOUTBUF
Definition: rdpsnd_libao.c:31
static FILE * out
Definition: regtests2xml.c:44
Definition: dhcpd.h:135
Definition: parse.h:23

Referenced by QMyMainWindow::soundSend(), ui_select(), and wave_out_write().

◆ wave_out_set_format()

BOOL wave_out_set_format ( WAVEFORMATEX pwfx)

Definition at line 114 of file rdpsnd_libao.c.

115{
116 ao_sample_format format;
117
118 format.bits = pwfx->wBitsPerSample;
119 format.channels = pwfx->nChannels;
120 This->channels = pwfx->nChannels;
121 format.rate = 44100;
123 format.byte_format = AO_FMT_LITTLE;
124
125 g_samplewidth = pwfx->wBitsPerSample / 8;
126
127 if (o_device != NULL)
128 ao_close(o_device);
129
130 o_device = ao_open_live(default_driver, &format, NULL);
131 if (o_device == NULL)
132 {
133 return False;
134 }
135
137
138 return True;
139}

Referenced by rdpsnd_process().

◆ wave_out_volume()

void wave_out_volume ( uint16  left,
uint16  right 
)

Definition at line 142 of file rdpsnd_libao.c.

143{
144 warning("volume changes not supported with libao-output\n");
145}
#define warning(s)
Definition: debug.h:83

Referenced by rdpsnd_process().

◆ wave_out_write()

void wave_out_write ( STREAM  s,
uint16  tick,
uint8  index 
)

Definition at line 148 of file rdpsnd_libao.c.

149{
151 unsigned int next_hi = (queue_hi + 1) % MAX_QUEUE;
152
153 if (next_hi == queue_lo)
154 {
155 error("No space to queue audio packet\n");
156 return;
157 }
158
159 queue_hi = next_hi;
160
161 packet->s = *s;
162 packet->tick = tick;
163 packet->index = index;
164 packet->s.p += 4;
165
166 /* we steal the data buffer from s, give it a new one */
167 s->data = malloc(s->size);
168
169 if (!This->dsp_bu)
171}
#define index(s, c)
Definition: various.h:29
#define malloc
Definition: debug_ros.c:4
#define error(str)
Definition: mkdosfs.c:1605
void wave_out_play(void)
Definition: rdpsnd_libao.c:174

Referenced by rdpsnd_process().

Variable Documentation

◆ channels

◆ default_driver

int default_driver

Definition at line 35 of file rdpsnd_libao.c.

Referenced by wave_out_open(), and wave_out_set_format().

◆ dsp_

int This dsp_

Definition at line 33 of file rdpsnd_libao.c.

◆ dsp_bu

BOOL This dsp_bu = False

Definition at line 38 of file rdpsnd_libao.c.

◆ g_reopened

BOOL g_reopened
static

Definition at line 39 of file rdpsnd_libao.c.

Referenced by wave_out_open(), wave_out_play(), and wave_out_set_format().

◆ g_samplerate

int g_samplerate

Definition at line 36 of file rdpsnd_libao.c.

Referenced by wave_out_open(), wave_out_play(), and wave_out_set_format().

◆ g_samplewidth

short g_samplewidth
static

Definition at line 40 of file rdpsnd_libao.c.

Referenced by wave_out_play(), and wave_out_set_format().

◆ o_device

ao_device* o_device = NULL

Definition at line 34 of file rdpsnd_libao.c.

Referenced by wave_out_close(), wave_out_open(), wave_out_play(), and wave_out_set_format().

◆ packet_queue

◆ queue_hi

unsigned int queue_hi
static

Definition at line 48 of file rdpsnd_libao.c.

Referenced by wave_out_close(), wave_out_open(), wave_out_play(), and wave_out_write().

◆ queue_lo

unsigned int queue_lo
static

Definition at line 48 of file rdpsnd_libao.c.

Referenced by wave_out_close(), wave_out_open(), wave_out_play(), and wave_out_write().