CVS: rdesktop rdpsnd_dsp.c,1.13,1.14

Michael Gernoth <[email protected]> Sun, 01 Oct 2006 10:23:32 -0700
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv26839

Modified Files:
	rdpsnd_dsp.c 
Log Message:
add simple linear resampling implementation to be used when libsamplerate
is not available


Index: rdpsnd_dsp.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdpsnd_dsp.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** rdpsnd_dsp.c	1 Oct 2006 15:07:55 -0000	1.13
--- rdpsnd_dsp.c	1 Oct 2006 17:23:30 -0000	1.14
***************
*** 133,141 ****
  #endif
  
- #ifndef HAVE_LIBSAMPLERATE
- 	if (device_srate != 44100 && device_srate != 22050)
- 		return False;
- #endif
- 
  	if (device_bitspersample != 16 && device_bitspersample != 8)
  		return False;
--- 133,136 ----
***************
*** 171,178 ****
  	if ((format->wBitsPerSample != 8) && (format->wBitsPerSample != 16))
  		return False;
- #ifndef HAVE_LIBSAMPLERATE
- 	if ((format->nSamplesPerSec != 44100) && (format->nSamplesPerSec != 22050))
- 		return False;
- #endif
  
  	return True;
--- 166,169 ----
***************
*** 186,194 ****
  	SRC_DATA resample_data;
  	float *infloat, *outfloat;
- 	int innum, outnum;
  	int err;
  #else
! 	int offset;
  #endif
  	static BOOL warned = False;
  	unsigned char *tmpdata = NULL;
--- 177,185 ----
  	SRC_DATA resample_data;
  	float *infloat, *outfloat;
  	int err;
  #else
! 	int ratio1k = (resample_to_srate * 1000) / format->nSamplesPerSec;
  #endif
+ 	int innum, outnum;
  	static BOOL warned = False;
  	unsigned char *tmpdata = NULL;
***************
*** 233,236 ****
--- 224,229 ----
  	}
  
+ 	innum = size / samplewidth;
+ 
  	/* Do the resampling */
  #ifdef HAVE_LIBSAMPLERATE
***************
*** 241,246 ****
  	}
  
! 	innum = size / samplewidth;
! 	outnum = ((float)innum * ((float)resample_to_srate / (float)format->nSamplesPerSec)) + 1;
  
  	infloat = xmalloc(sizeof(float) * innum);
--- 234,238 ----
  	}
  
! 	outnum = ((float) innum * ((float) resample_to_srate / (float) format->nSamplesPerSec)) + 1;
  
  	infloat = xmalloc(sizeof(float) * innum);
***************
*** 264,303 ****
  	outsize = resample_data.output_frames_gen * resample_to_channels * samplewidth;
  	*out = xmalloc(outsize);
! 	src_float_to_short_array(outfloat, (short *) *out, resample_data.output_frames_gen * resample_to_channels);
  	xfree(outfloat);
  
  #else
! 	if (format->nSamplesPerSec != 22050)
  	{
! 		if (!warned)
! 		{
! 			warning("unsupported source samplerate (%u), not resampling!\n",
! 				format->nSamplesPerSec);
! 			warned = True;
! 		}
  		return 0;
  	}
  
! 	outsize = size * 2;
  	*out = xmalloc(outsize);
  
! 	/* Resample from 22050 to 44100 */
! 	for (i = 0; i < (size / samplewidth); i++)
  	{
! 		/* On a stereo-channel we must make sure that left and right
! 		   does not get mixed up, so we need to expand the sample-
! 		   data with channels in mind: 1234 -> 12123434
! 		   If we have a mono-channel, we can expand the data by simply
! 		   doubling the sample-data: 1234 -> 11223344 */
! 		if (resample_to_channels == 2)
! 			offset = ((i * 2) - (i & 1)) * samplewidth;
! 		else
! 			offset = (i * 2) * samplewidth;
  
! 		memcpy(*out + offset, in + (i * samplewidth), samplewidth);
! 		memcpy(*out + (resample_to_channels * samplewidth + offset),
! 		       in + (i * samplewidth), samplewidth);
  
  	}
  #endif
  
--- 256,298 ----
  	outsize = resample_data.output_frames_gen * resample_to_channels * samplewidth;
  	*out = xmalloc(outsize);
! 	src_float_to_short_array(outfloat, (short *) *out,
! 				 resample_data.output_frames_gen * resample_to_channels);
  	xfree(outfloat);
  
  #else
! 	/* Michaels simple linear resampler */
! 	if (resample_to_srate < format->nSamplesPerSec)
  	{
! 		warning("downsampling currently not supported!\n");
  		return 0;
  	}
  
! 	outnum = (innum * ratio1k) / 1000;
! 
! 	outsize = outnum * samplewidth;
  	*out = xmalloc(outsize);
+ 	bzero(*out, outsize);
  
! 	for (i = 0; i < outsize / (resample_to_channels * samplewidth); i++)
  	{
! 		int source = ((i + ratio1k / 1000 - 1) * 1000) / ratio1k;
  
! 		if (source * resample_to_channels + samplewidth > size)
! 			break;
  
+ 		if (resample_to_channels == 2)
+ 		{
+ 			memcpy(*out + (i * resample_to_channels * samplewidth),
+ 			       in + (source * resample_to_channels * samplewidth), samplewidth);
+ 			memcpy(*out + (i * resample_to_channels * samplewidth) + samplewidth,
+ 			       in + (source * resample_to_channels * samplewidth) + samplewidth,
+ 			       samplewidth);
+ 		}
+ 		else
+ 		{
+ 			memcpy(*out + (i * samplewidth), in + (source * samplewidth), samplewidth);
+ 		}
  	}
+ 	outsize = i * resample_to_channels * samplewidth;
  #endif
  


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