CVS: rdesktop rdpsnd_dsp.c, NONE, 1.1 rdpsnd_dsp.h, NONE, 1.1 configure.ac, 1.24, 1.25 rdpsnd.c, 1.13, 1.14 rdpsnd.h, 1.3, 1.4 rdpsnd_libao.c, 1.17, 1.18

Michael Gernoth <[email protected]> Sun, 17 Sep 2006 07:41:18 -0700
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22692

Modified Files:
	configure.ac rdpsnd.c rdpsnd.h rdpsnd_libao.c 
Added Files:
	rdpsnd_dsp.c rdpsnd_dsp.h 
Log Message:
add software volume control (currently only for libao but will be
used for alsa, too)


--- NEW FILE: rdpsnd_dsp.c ---
/*
   rdesktop: A Remote Desktop Protocol client.
   Sound DSP routines
   Copyright (C) Michael Gernoth 2006

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "rdesktop.h"
#include "rdpsnd.h"
#include "rdpsnd_dsp.h"

#define MAX_VOLUME 65535

static uint16 softvol_left = MAX_VOLUME;
static uint16 softvol_right = MAX_VOLUME;

void
rdpsnd_dsp_softvol_set(uint16 left, uint16 right)
{
	softvol_left = left;
	softvol_right = right;
	DEBUG(("rdpsnd_dsp_softvol_set: left: %u, right: %u\n", left, right));
}

inline void
rdpsnd_dsp_softvol(unsigned char *inbuffer, unsigned char *outbuffer, unsigned int size,
		   WAVEFORMATEX * format)
{
	unsigned int factor_left, factor_right;
	unsigned char *posin = inbuffer;
	unsigned char *posout = outbuffer;

	factor_left = (softvol_left * 256) / 65535;
	factor_right = (softvol_right * 256) / 65535;

	if (format->nChannels == 1)
	{
		factor_left = factor_right = (factor_left + factor_right) / 2;
	}

	if (format->wBitsPerSample == 8)
	{
		char val;

		while (posout < outbuffer + size)
		{
			/* Left */
			val = *posin++;
			val = (val * factor_left) >> 8;
			*posout++ = val;

			/* Right */
			val = *posin++;
			val = (val * factor_right) >> 8;
			*posout++ = val;
		}
	}
	else
	{
		short val;

		while (posout < outbuffer + size)
		{
			/* Left */
			val = *posin++;
			val |= *posin++ << 8;
			val = (val * factor_left) >> 8;
			*posout++ = val & 0xff;
			*posout++ = val >> 8;

			/* Right */
			val = *posin++;
			val |= *posin++ << 8;
			val = (val * factor_right) >> 8;
			*posout++ = val & 0xff;
			*posout++ = val >> 8;
		}
	}

	DEBUG(("using softvol with shifts left: %d, right: %d (%d/%d)\n", factor_left, factor_right,
	       format->wBitsPerSample, format->nChannels));
}

unsigned char *
rdpsnd_dsp_process(unsigned char *inbuffer, unsigned int size, struct audio_driver *current_driver,
		   WAVEFORMATEX * format)
{
	unsigned char *outbuffer;

	outbuffer = xmalloc(size);

	/* Software volume control */
	if (current_driver->wave_out_volume == rdpsnd_dsp_softvol_set)
	{
		rdpsnd_dsp_softvol(inbuffer, outbuffer, size, format);
	}
	else
	{
		memcpy(outbuffer, inbuffer, size);
	}

	return outbuffer;
}

--- NEW FILE: rdpsnd_dsp.h ---
/*
   rdesktop: A Remote Desktop Protocol client.
   Sound DSP routines
   Copyright (C) Michael Gernoth 2006

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

void rdpsnd_dsp_softvol_set(uint16 left, uint16 right);
unsigned char *rdpsnd_dsp_process(unsigned char *inbuffer, unsigned int size,
				  struct audio_driver *current_driver, WAVEFORMATEX * format);

Index: configure.ac
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/configure.ac,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** configure.ac	17 Sep 2006 11:42:22 -0000	1.24
--- configure.ac	17 Sep 2006 14:41:16 -0000	1.25
***************
*** 195,218 ****
      break
  elif test "$sound" = auto; then
!     SOUNDOBJ="$SOUNDOBJ rdpsnd.o"
      AC_DEFINE(WITH_RDPSND)
  elif test "$sound" = oss; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_oss.o"
      AC_DEFINE(WITH_RDPSND)
  elif test "$sound" = sgi; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_sgi.o"
      LDFLAGS="$LDFLAGS -laudio"
  elif test "$sound" = yes; then
!     SOUNDOBJ="$SOUNDOBJ rdpsnd.o"
      AC_DEFINE(WITH_RDPSND)
  elif test "$sound" = sun; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_sun.o"
      AC_DEFINE(WITH_RDPSND)
  elif test "$sound" = libao; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_libao.o"
      LDFLAGS="$LDFLAGS -lao"
      AC_DEFINE(RDPSND_SUN)
  elif test "$sound" = alsa; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_alsa.o"
      LDFLAGS="$LDFLAGS -lasound"
      AC_DEFINE(WITH_RDPSND)
--- 195,218 ----
      break
  elif test "$sound" = auto; then
!     SOUNDOBJ="$SOUNDOBJ rdpsnd.o rdpsnd_dsp.o"
      AC_DEFINE(WITH_RDPSND)
  elif test "$sound" = oss; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_dsp.o rdpsnd_oss.o"
      AC_DEFINE(WITH_RDPSND)
  elif test "$sound" = sgi; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_dsp.o rdpsnd_sgi.o"
      LDFLAGS="$LDFLAGS -laudio"
  elif test "$sound" = yes; then
!     SOUNDOBJ="$SOUNDOBJ rdpsnd.o rdpsnd_dsp.o"
      AC_DEFINE(WITH_RDPSND)
  elif test "$sound" = sun; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_dsp.o rdpsnd_sun.o"
      AC_DEFINE(WITH_RDPSND)
  elif test "$sound" = libao; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_dsp.o rdpsnd_libao.o"
      LDFLAGS="$LDFLAGS -lao"
      AC_DEFINE(RDPSND_SUN)
  elif test "$sound" = alsa; then
!     SOUNDOBJ="rdpsnd.o rdpsnd_dsp.o rdpsnd_alsa.o"
      LDFLAGS="$LDFLAGS -lasound"
      AC_DEFINE(WITH_RDPSND)

Index: rdpsnd.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdpsnd.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** rdpsnd.c	17 Sep 2006 11:42:22 -0000	1.13
--- rdpsnd.c	17 Sep 2006 14:41:16 -0000	1.14
***************
*** 22,25 ****
--- 22,26 ----
  #include "rdesktop.h"
  #include "rdpsnd.h"
+ #include "rdpsnd_dsp.h"
  
  #define RDPSND_CLOSE		1
***************
*** 394,403 ****
  
  	packet->s = *s;
  	packet->tick = tick;
  	packet->index = index;
- 	packet->s.p += 4;
  
  	/* we steal the data buffer from s, give it a new one */
! 	s->data = malloc(s->size);
  
  	if (!g_dsp_busy)
--- 395,409 ----
  
  	packet->s = *s;
+ 	packet->s.data =
+ 		rdpsnd_dsp_process(s->data, s->size, current_driver, &formats[current_format]);
+ 	packet->s.p = packet->s.data + 4;
+ 	packet->s.end = packet->s.data + s->size;
  	packet->tick = tick;
  	packet->index = index;
  
+ #if 0				/* Handled by DSP */
  	/* we steal the data buffer from s, give it a new one */
! 	s->data = xmalloc(s->size);
! #endif
  
  	if (!g_dsp_busy)
***************
*** 426,430 ****
  rdpsnd_queue_next(void)
  {
! 	free(packet_queue[queue_lo].s.data);
  	queue_lo = (queue_lo + 1) % MAX_QUEUE;
  }
--- 432,436 ----
  rdpsnd_queue_next(void)
  {
! 	xfree(packet_queue[queue_lo].s.data);
  	queue_lo = (queue_lo + 1) % MAX_QUEUE;
  }

Index: rdpsnd.h
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdpsnd.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rdpsnd.h	17 Sep 2006 11:42:22 -0000	1.3
--- rdpsnd.h	17 Sep 2006 14:41:16 -0000	1.4
***************
*** 29,36 ****
  {
  	void (*wave_out_write) (STREAM s, uint16 tick, uint8 index);
! 	  BOOL(*wave_out_open) (void);
  	void (*wave_out_close) (void);
! 	  BOOL(*wave_out_format_supported) (WAVEFORMATEX * pwfx);
! 	  BOOL(*wave_out_set_format) (WAVEFORMATEX * pwfx);
  	void (*wave_out_volume) (uint16 left, uint16 right);
  	void (*wave_out_play) (void);
--- 29,36 ----
  {
  	void (*wave_out_write) (STREAM s, uint16 tick, uint8 index);
! 	BOOL(*wave_out_open) (void);
  	void (*wave_out_close) (void);
! 	BOOL(*wave_out_format_supported) (WAVEFORMATEX * pwfx);
! 	BOOL(*wave_out_set_format) (WAVEFORMATEX * pwfx);
  	void (*wave_out_volume) (uint16 left, uint16 right);
  	void (*wave_out_play) (void);

Index: rdpsnd_libao.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdpsnd_libao.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** rdpsnd_libao.c	17 Sep 2006 11:42:22 -0000	1.17
--- rdpsnd_libao.c	17 Sep 2006 14:41:16 -0000	1.18
***************
*** 23,26 ****
--- 23,27 ----
  #include "rdesktop.h"
  #include "rdpsnd.h"
+ #include "rdpsnd_dsp.h"
  #include <unistd.h>
  #include <fcntl.h>
***************
*** 138,147 ****
  
  void
- libao_volume(uint16 left, uint16 right)
- {
- 	warning("volume changes not supported with libao-output\n");
- }
- 
- void
  libao_play(void)
  {
--- 139,142 ----
***************
*** 245,249 ****
  	libao_driver.wave_out_format_supported = libao_format_supported;
  	libao_driver.wave_out_set_format = libao_set_format;
! 	libao_driver.wave_out_volume = libao_volume;
  	libao_driver.wave_out_play = libao_play;
  	libao_driver.name = xstrdup("libao");
--- 240,244 ----
  	libao_driver.wave_out_format_supported = libao_format_supported;
  	libao_driver.wave_out_set_format = libao_set_format;
! 	libao_driver.wave_out_volume = rdpsnd_dsp_softvol_set;
  	libao_driver.wave_out_play = libao_play;
  	libao_driver.name = xstrdup("libao");


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642