CVS: rdesktop rdpsnd_dsp.c,1.11,1.12
Michael Gernoth <[email protected]> Sun, 01 Oct 2006 07:31:11 -0700
| Newsgroups | gmane.network.rdesktop.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv23986
Modified Files:
rdpsnd_dsp.c
Log Message:
make it possible to resample 8bit<->16bit soundstreams
Index: rdpsnd_dsp.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdpsnd_dsp.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** rdpsnd_dsp.c 1 Oct 2006 14:03:43 -0000 1.11
--- rdpsnd_dsp.c 1 Oct 2006 14:31:09 -0000 1.12
***************
*** 133,146 ****
#endif
! #ifdef HAVE_LIBSAMPLERATE
! if (device_bitspersample != 16)
! return False;
! #else
if (device_srate != 44100 && device_srate != 22050)
return False;
if (device_bitspersample != 16 && device_bitspersample != 8)
return False;
- #endif
if (device_channels != 1 && device_channels != 2)
--- 133,143 ----
#endif
! #ifndef HAVE_LIBSAMPLERATE
if (device_srate != 44100 && device_srate != 22050)
return False;
+ #endif
if (device_bitspersample != 16 && device_bitspersample != 8)
return False;
if (device_channels != 1 && device_channels != 2)
***************
*** 172,181 ****
if ((format->nChannels != 1) && (format->nChannels != 2))
return False;
- #ifdef HAVE_LIBSAMPLERATE
- if (format->wBitsPerSample != 16)
- return False;
- #else
if ((format->wBitsPerSample != 8) && (format->wBitsPerSample != 16))
return False;
if ((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050))
return False;
--- 169,175 ----
if ((format->nChannels != 1) && (format->nChannels != 2))
return False;
if ((format->wBitsPerSample != 8) && (format->wBitsPerSample != 16))
return False;
+ #ifndef HAVE_LIBSAMPLERATE
if ((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050))
return False;
***************
*** 195,203 ****
#else
int offset;
- int i;
#endif
static BOOL warned = False;
int samplewidth = format->wBitsPerSample / 8;
int outsize = 0;
if ((resample_to_bitspersample == format->wBitsPerSample) &&
--- 189,198 ----
#else
int offset;
#endif
static BOOL warned = False;
+ unsigned char *tmpdata = NULL;
int samplewidth = format->wBitsPerSample / 8;
int outsize = 0;
+ int i;
if ((resample_to_bitspersample == format->wBitsPerSample) &&
***************
*** 208,220 ****
#ifdef B_ENDIAN
if (!stream_be)
! rdpsnd_dsp_swapbytes(in, size, format)
#endif
! if ((resample_to_channels != format->nChannels) ||
! (resample_to_bitspersample != format->wBitsPerSample))
{
! warning("unsupported resample-settings (%u -> %u/%u -> %u/%u -> %u), not resampling!\n", format->nSamplesPerSec, resample_to_srate, format->wBitsPerSample, resample_to_bitspersample, format->nChannels, resample_to_channels);
! warned = True;
}
#ifdef HAVE_LIBSAMPLERATE
if (src_converter == NULL)
--- 203,236 ----
#ifdef B_ENDIAN
if (!stream_be)
! rdpsnd_dsp_swapbytes(in, size, format);
#endif
!
! /* Expand 8bit input-samples to 16bit */
! #ifndef HAVE_LIBSAMPLERATE /* libsamplerate needs 16bit samples */
! if (format->wBitsPerSample != resample_to_bitspersample)
! #endif
! {
! /* source: 8 bit, dest: 16bit */
! if (format->wBitsPerSample == 8)
{
! tmpdata = xmalloc(size * 2);
! for (i = 0; i < size; i++)
! {
! tmpdata[i * 2] = in[i];
! tmpdata[(i * 2) + 1] = 0x00;
! }
! in = tmpdata;
! samplewidth = 16 / 2;
! size *= 2;
}
+ }
+ if (resample_to_channels != format->nChannels)
+ {
+ warning("unsupported resample-settings (%u -> %u/%u -> %u/%u -> %u), not resampling!\n", format->nSamplesPerSec, resample_to_srate, format->wBitsPerSample, resample_to_bitspersample, format->nChannels, resample_to_channels);
+ warned = True;
+ }
+
+ /* Do the resampling */
#ifdef HAVE_LIBSAMPLERATE
if (src_converter == NULL)
***************
*** 283,291 ****
#endif
#ifdef B_ENDIAN
if (!stream_be)
! rdpsnd_dsp_swapbytes(*out, outsize, format)
#endif
! return outsize;
}
--- 299,326 ----
#endif
+ if (tmpdata != NULL)
+ xfree(tmpdata);
+
+ /* Shrink 16bit output-samples to 8bit */
+ #ifndef HAVE_LIBSAMPLERATE /* libsamplerate produces 16bit samples */
+ if (format->wBitsPerSample != resample_to_bitspersample)
+ #endif
+ {
+ /* source: 16 bit, dest: 8 bit */
+ if (resample_to_bitspersample == 8)
+ {
+ for (i = 0; i < outsize; i++)
+ {
+ *out[i] = *out[i * 2];
+ }
+ outsize /= 2;
+ }
+ }
+
#ifdef B_ENDIAN
if (!stream_be)
! rdpsnd_dsp_swapbytes(*out, outsize, format);
#endif
! return outsize;
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV