26 |
|
|
27 |
static uint16 softvol_left = MAX_VOLUME; |
static uint16 softvol_left = MAX_VOLUME; |
28 |
static uint16 softvol_right = MAX_VOLUME; |
static uint16 softvol_right = MAX_VOLUME; |
29 |
|
static uint32 resample_to_srate = 44100; |
30 |
|
static uint16 resample_to_bitspersample = 16; |
31 |
|
static uint16 resample_to_channels = 2; |
32 |
|
|
33 |
void |
void |
34 |
rdpsnd_dsp_softvol_set(uint16 left, uint16 right) |
rdpsnd_dsp_softvol_set(uint16 left, uint16 right) |
116 |
} |
} |
117 |
} |
} |
118 |
|
|
119 |
|
BOOL |
120 |
|
rdpsnd_dsp_resample_set(uint32 device_srate, uint16 device_bitspersample, uint16 device_channels) |
121 |
|
{ |
122 |
|
if (device_srate != 44100 && device_srate != 22050) |
123 |
|
return False; |
124 |
|
|
125 |
|
if (device_bitspersample != 16 && device_bitspersample != 8) |
126 |
|
return False; |
127 |
|
|
128 |
|
if (device_channels != 1 && device_channels != 2) |
129 |
|
return False; |
130 |
|
|
131 |
|
resample_to_srate = device_srate; |
132 |
|
resample_to_bitspersample = device_bitspersample; |
133 |
|
resample_to_channels = device_channels; |
134 |
|
|
135 |
|
return True; |
136 |
|
} |
137 |
|
|
138 |
|
BOOL |
139 |
|
rdpsnd_dsp_resample_supported(WAVEFORMATEX * format) |
140 |
|
{ |
141 |
|
if (format->wFormatTag != WAVE_FORMAT_PCM) |
142 |
|
return False; |
143 |
|
if ((format->nChannels != 1) && (format->nChannels != 2)) |
144 |
|
return False; |
145 |
|
if ((format->wBitsPerSample != 8) && (format->wBitsPerSample != 16)) |
146 |
|
return False; |
147 |
|
if ((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050)) |
148 |
|
return False; |
149 |
|
|
150 |
|
return True; |
151 |
|
} |
152 |
|
|
153 |
|
uint32 |
154 |
|
rdpsnd_dsp_resample(unsigned char **out, unsigned char *in, unsigned int size, |
155 |
|
WAVEFORMATEX * format) |
156 |
|
{ |
157 |
|
static BOOL warned = False; |
158 |
|
int outsize, offset; |
159 |
|
int samplewidth = format->wBitsPerSample / 8; |
160 |
|
int i; |
161 |
|
|
162 |
|
if ((resample_to_bitspersample != format->wBitsPerSample) || |
163 |
|
(resample_to_channels != format->nChannels) || |
164 |
|
((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050))) |
165 |
|
{ |
166 |
|
if (!warned) |
167 |
|
{ |
168 |
|
warning("unsupported resample-settings (%u/%u/%u), not resampling!\n", |
169 |
|
format->nSamplesPerSec, format->wBitsPerSample, format->nChannels); |
170 |
|
warned = True; |
171 |
|
} |
172 |
|
return 0; |
173 |
|
} |
174 |
|
|
175 |
|
if (format->nSamplesPerSec == 22050) |
176 |
|
{ |
177 |
|
outsize = size * 2; |
178 |
|
*out = xmalloc(outsize); |
179 |
|
|
180 |
|
/* Resample to 44100 */ |
181 |
|
for (i = 0; i < (size / samplewidth); i++) |
182 |
|
{ |
183 |
|
/* On a stereo-channel we must make sure that left and right |
184 |
|
does not get mixed up, so we need to expand the sample- |
185 |
|
data with channels in mind: 1234 -> 12123434 |
186 |
|
If we have a mono-channel, we can expand the data by simply |
187 |
|
doubling the sample-data: 1234 -> 11223344 */ |
188 |
|
if (resample_to_channels == 2) |
189 |
|
offset = ((i * 2) - (i & 1)) * samplewidth; |
190 |
|
else |
191 |
|
offset = (i * 2) * samplewidth; |
192 |
|
|
193 |
|
memcpy(*out + offset, in + (i * samplewidth), samplewidth); |
194 |
|
memcpy(*out + (resample_to_channels * samplewidth + offset), |
195 |
|
in + (i * samplewidth), samplewidth); |
196 |
|
|
197 |
|
} |
198 |
|
} |
199 |
|
else |
200 |
|
{ |
201 |
|
outsize = 0; |
202 |
|
} |
203 |
|
|
204 |
|
return outsize; |
205 |
|
} |
206 |
|
|
207 |
STREAM |
STREAM |
208 |
rdpsnd_dsp_process(STREAM s, struct audio_driver *current_driver, WAVEFORMATEX * format) |
rdpsnd_dsp_process(STREAM s, struct audio_driver * current_driver, WAVEFORMATEX * format) |
209 |
{ |
{ |
210 |
static struct stream out; |
static struct stream out; |
211 |
|
|
219 |
rdpsnd_dsp_swapbytes(s->data, s->size, format); |
rdpsnd_dsp_swapbytes(s->data, s->size, format); |
220 |
#endif |
#endif |
221 |
|
|
222 |
out.data = xmalloc(s->size); |
out.data = NULL; |
223 |
|
|
224 |
|
if (current_driver->wave_out_format_supported == rdpsnd_dsp_resample_supported) |
225 |
|
{ |
226 |
|
out.size = rdpsnd_dsp_resample(&out.data, s->data, s->size, format); |
227 |
|
} |
228 |
|
|
229 |
memcpy(out.data, s->data, s->size); |
if (out.data == NULL) |
230 |
|
{ |
231 |
|
out.data = xmalloc(s->size); |
232 |
|
memcpy(out.data, s->data, s->size); |
233 |
|
out.size = s->size; |
234 |
|
} |
235 |
|
|
|
out.size = s->size; |
|
236 |
out.p = out.data; |
out.p = out.data; |
237 |
out.end = out.p + out.size; |
out.end = out.p + out.size; |
238 |
|
|