/[rdesktop]/sourceforge.net/trunk/rdesktop/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 /sourceforge.net/trunk/rdesktop/rdpsnd_dsp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1262 - (show annotations)
Sun Sep 17 15:49:14 2006 UTC (17 years, 9 months ago) by stargo
File MIME type: text/plain
File size: 3229 byte(s)
use correct types in rdpsnd_dsp_softvol

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, factor_right,
96 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 unsigned char *
117 rdpsnd_dsp_process(unsigned char *inbuffer, unsigned int size, struct audio_driver *current_driver,
118 WAVEFORMATEX * format)
119 {
120 unsigned char *outbuffer;
121
122 outbuffer = xmalloc(size);
123
124 memcpy(outbuffer, inbuffer, size);
125
126 /* Software volume control */
127 if (current_driver->wave_out_volume == rdpsnd_dsp_softvol_set)
128 rdpsnd_dsp_softvol(outbuffer, size, format);
129
130 #ifdef B_ENDIAN
131 if (current_driver->need_byteswap_on_be)
132 rdpsnd_dsp_swapbytes(outbuffer, size, format);
133 #endif
134
135 return outbuffer;
136 }

  ViewVC Help
Powered by ViewVC 1.1.26