/[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 1258 - (show annotations)
Sun Sep 17 14:41:16 2006 UTC (17 years, 9 months ago) by stargo
File MIME type: text/plain
File size: 2822 byte(s)
add software volume control (currently only for libao but will be
used for alsa, too)

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 inline void
39 rdpsnd_dsp_softvol(unsigned char *inbuffer, unsigned char *outbuffer, unsigned int size,
40 WAVEFORMATEX * format)
41 {
42 unsigned int factor_left, factor_right;
43 unsigned char *posin = inbuffer;
44 unsigned char *posout = outbuffer;
45
46 factor_left = (softvol_left * 256) / 65535;
47 factor_right = (softvol_right * 256) / 65535;
48
49 if (format->nChannels == 1)
50 {
51 factor_left = factor_right = (factor_left + factor_right) / 2;
52 }
53
54 if (format->wBitsPerSample == 8)
55 {
56 char val;
57
58 while (posout < outbuffer + size)
59 {
60 /* Left */
61 val = *posin++;
62 val = (val * factor_left) >> 8;
63 *posout++ = val;
64
65 /* Right */
66 val = *posin++;
67 val = (val * factor_right) >> 8;
68 *posout++ = val;
69 }
70 }
71 else
72 {
73 short val;
74
75 while (posout < outbuffer + size)
76 {
77 /* Left */
78 val = *posin++;
79 val |= *posin++ << 8;
80 val = (val * factor_left) >> 8;
81 *posout++ = val & 0xff;
82 *posout++ = val >> 8;
83
84 /* Right */
85 val = *posin++;
86 val |= *posin++ << 8;
87 val = (val * factor_right) >> 8;
88 *posout++ = val & 0xff;
89 *posout++ = val >> 8;
90 }
91 }
92
93 DEBUG(("using softvol with shifts left: %d, right: %d (%d/%d)\n", factor_left, factor_right,
94 format->wBitsPerSample, format->nChannels));
95 }
96
97 unsigned char *
98 rdpsnd_dsp_process(unsigned char *inbuffer, unsigned int size, struct audio_driver *current_driver,
99 WAVEFORMATEX * format)
100 {
101 unsigned char *outbuffer;
102
103 outbuffer = xmalloc(size);
104
105 /* Software volume control */
106 if (current_driver->wave_out_volume == rdpsnd_dsp_softvol_set)
107 {
108 rdpsnd_dsp_softvol(inbuffer, outbuffer, size, format);
109 }
110 else
111 {
112 memcpy(outbuffer, inbuffer, size);
113 }
114
115 return outbuffer;
116 }

  ViewVC Help
Powered by ViewVC 1.1.26