/[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

Annotation of /sourceforge.net/trunk/rdesktop/rdpsnd_dsp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1259 - (hide annotations)
Sun Sep 17 15:08:48 2006 UTC (17 years, 9 months ago) by stargo
File MIME type: text/plain
File size: 2835 byte(s)
softvol only needs one buffer

1 stargo 1258 /*
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 stargo 1259 rdpsnd_dsp_softvol(unsigned char *buffer, unsigned int size, WAVEFORMATEX * format)
40 stargo 1258 {
41     unsigned int factor_left, factor_right;
42 stargo 1259 unsigned char *posin = buffer;
43     unsigned char *posout = buffer;
44 stargo 1258
45 stargo 1259 if ((softvol_left == MAX_VOLUME) && (softvol_right == MAX_VOLUME))
46     return;
47    
48 stargo 1258 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     char val;
59    
60 stargo 1259 while (posout < buffer + size)
61 stargo 1258 {
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     short val;
76    
77 stargo 1259 while (posout < buffer + size)
78 stargo 1258 {
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 shifts left: %d, right: %d (%d/%d)\n", factor_left, factor_right,
96     format->wBitsPerSample, format->nChannels));
97     }
98    
99     unsigned char *
100     rdpsnd_dsp_process(unsigned char *inbuffer, unsigned int size, struct audio_driver *current_driver,
101     WAVEFORMATEX * format)
102     {
103     unsigned char *outbuffer;
104    
105     outbuffer = xmalloc(size);
106    
107 stargo 1259 memcpy(outbuffer, inbuffer, size);
108    
109 stargo 1258 /* Software volume control */
110     if (current_driver->wave_out_volume == rdpsnd_dsp_softvol_set)
111     {
112 stargo 1259 rdpsnd_dsp_softvol(outbuffer, size, format);
113 stargo 1258 }
114    
115     return outbuffer;
116     }

  ViewVC Help
Powered by ViewVC 1.1.26