/[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 1270 - (hide annotations)
Mon Sep 18 10:20:02 2006 UTC (17 years, 8 months ago) by stargo
File MIME type: text/plain
File size: 3349 byte(s)
replace constants with their define

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 stargo 1260 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 1270 factor_left = (softvol_left * 256) / MAX_VOLUME;
49     factor_right = (softvol_right * 256) / MAX_VOLUME;
50 stargo 1258
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 stargo 1262 sint8 val;
59 stargo 1258
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 stargo 1262 sint16 val;
76 stargo 1258
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 stargo 1263 DEBUG(("using softvol with factors left: %d, right: %d (%d/%d)\n", factor_left,
96     factor_right, format->wBitsPerSample, format->nChannels));
97 stargo 1258 }
98    
99 stargo 1260 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 stargo 1263
117     STREAM
118     rdpsnd_dsp_process(STREAM s, struct audio_driver *current_driver, WAVEFORMATEX * format)
119 stargo 1258 {
120 stargo 1263 static struct stream out;
121 stargo 1258
122 stargo 1263 /* softvol and byteswap do not change the amount of data they
123     return, so they can operate on the input-stream */
124 stargo 1258 if (current_driver->wave_out_volume == rdpsnd_dsp_softvol_set)
125 stargo 1263 rdpsnd_dsp_softvol(s->data, s->size, format);
126 stargo 1258
127 stargo 1260 #ifdef B_ENDIAN
128     if (current_driver->need_byteswap_on_be)
129 stargo 1263 rdpsnd_dsp_swapbytes(s->data, s->size, format);
130 stargo 1260 #endif
131    
132 stargo 1265 out.data = xmalloc(s->size);
133 stargo 1263
134 stargo 1265 memcpy(out.data, s->data, s->size);
135 stargo 1263
136 stargo 1265 out.size = s->size;
137 stargo 1263 out.p = out.data;
138     out.end = out.p + out.size;
139    
140     return &out;
141 stargo 1258 }

  ViewVC Help
Powered by ViewVC 1.1.26