/[rdesktop]/jpeg/rdesktop/trunk/rdpsnd_dsp.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /jpeg/rdesktop/trunk/rdpsnd_dsp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1265 - (show annotations)
Sun Sep 17 20:06:37 2006 UTC (17 years, 8 months ago) by stargo
Original Path: sourceforge.net/trunk/rdesktop/rdpsnd_dsp.c
File MIME type: text/plain
File size: 3339 byte(s)
Recover missing 4 bytes in audio-stream thanks to a hint in an old
email from Robert Sanders <esquimaux73@mailblocks.com>:

I found a trick that seems to solve this.  Basically, I copy the last
4 bytes of the RDPSND_WRITE command that precedes the sample data.
It's not being used by anything else.  I can't tell whether this is
some trick to "pre-load" the sample buffer, or some error in
rdesktop's interpretation of the RDP sound protocol.

1 /*
2 rdesktop: A Remote Desktop Protocol client.
3 Sound DSP routines
4 Copyright (C) Michael Gernoth 2006
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "rdesktop.h"
22 #include "rdpsnd.h"
23 #include "rdpsnd_dsp.h"
24
25 #define MAX_VOLUME 65535
26
27 static uint16 softvol_left = MAX_VOLUME;
28 static uint16 softvol_right = MAX_VOLUME;
29
30 void
31 rdpsnd_dsp_softvol_set(uint16 left, uint16 right)
32 {
33 softvol_left = left;
34 softvol_right = right;
35 DEBUG(("rdpsnd_dsp_softvol_set: left: %u, right: %u\n", left, right));
36 }
37
38 void
39 rdpsnd_dsp_softvol(unsigned char *buffer, unsigned int size, WAVEFORMATEX * format)
40 {
41 unsigned int factor_left, factor_right;
42 unsigned char *posin = buffer;
43 unsigned char *posout = buffer;
44
45 if ((softvol_left == MAX_VOLUME) && (softvol_right == MAX_VOLUME))
46 return;
47
48 factor_left = (softvol_left * 256) / 65535;
49 factor_right = (softvol_right * 256) / 65535;
50
51 if (format->nChannels == 1)
52 {
53 factor_left = factor_right = (factor_left + factor_right) / 2;
54 }
55
56 if (format->wBitsPerSample == 8)
57 {
58 sint8 val;
59
60 while (posout < buffer + size)
61 {
62 /* Left */
63 val = *posin++;
64 val = (val * factor_left) >> 8;
65 *posout++ = val;
66
67 /* Right */
68 val = *posin++;
69 val = (val * factor_right) >> 8;
70 *posout++ = val;
71 }
72 }
73 else
74 {
75 sint16 val;
76
77 while (posout < buffer + size)
78 {
79 /* Left */
80 val = *posin++;
81 val |= *posin++ << 8;
82 val = (val * factor_left) >> 8;
83 *posout++ = val & 0xff;
84 *posout++ = val >> 8;
85
86 /* Right */
87 val = *posin++;
88 val |= *posin++ << 8;
89 val = (val * factor_right) >> 8;
90 *posout++ = val & 0xff;
91 *posout++ = val >> 8;
92 }
93 }
94
95 DEBUG(("using softvol with factors left: %d, right: %d (%d/%d)\n", factor_left,
96 factor_right, format->wBitsPerSample, format->nChannels));
97 }
98
99 void
100 rdpsnd_dsp_swapbytes(unsigned char *buffer, unsigned int size, WAVEFORMATEX * format)
101 {
102 int i;
103 uint8 swap;
104
105 if (format->wBitsPerSample == 8)
106 return;
107
108 for (i = 0; i < size; i += 2)
109 {
110 swap = *(buffer + i);
111 *(buffer + i) = *(buffer + i + 1);
112 *(buffer + i + 1) = swap;
113 }
114 }
115
116
117 STREAM
118 rdpsnd_dsp_process(STREAM s, struct audio_driver *current_driver, WAVEFORMATEX * format)
119 {
120 static struct stream out;
121
122 /* softvol and byteswap do not change the amount of data they
123 return, so they can operate on the input-stream */
124 if (current_driver->wave_out_volume == rdpsnd_dsp_softvol_set)
125 rdpsnd_dsp_softvol(s->data, s->size, format);
126
127 #ifdef B_ENDIAN
128 if (current_driver->need_byteswap_on_be)
129 rdpsnd_dsp_swapbytes(s->data, s->size, format);
130 #endif
131
132 out.data = xmalloc(s->size);
133
134 memcpy(out.data, s->data, s->size);
135
136 out.size = s->size;
137 out.p = out.data;
138 out.end = out.p + out.size;
139
140 return &out;
141 }

  ViewVC Help
Powered by ViewVC 1.1.26