From af30dfbe847477360a1c86418a6f5a63aabdc8e4 Mon Sep 17 00:00:00 2001
From: Andreas Claesson <andreas.claesson@gmail.com>
Date: Wed, 25 May 2005 15:25:59 +0000
Subject: Fixing faulty check in pcm_volumeChange and fixed some warnings.

git-svn-id: https://svn.musicpd.org/mpd/branches/ancl@3287 09075e82-0dd4-0310-85a5-a0d7c8717e4f
---
 src/pcm_utils.c  | 24 +++++++++++++++---------
 src/replayGain.c | 14 +++++++++-----
 2 files changed, 24 insertions(+), 14 deletions(-)

(limited to 'src')

diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index 9e816e00d..e92089f31 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -236,8 +236,8 @@ void pcm_volumeChange(char * buffer, int bufferSize, AudioFormat * format,
 	int samples;
 	int shift; 
 
-	if(format->bits!=32 || format->channels!=2) {
-		ERROR("Only 32 bit stereo is supported for pcm_volumeChange!\n");
+	if(format->bits!=32 || format->fracBits == 0) {
+		ERROR("Only 32 bit mpd_fixed_t samples are supported in pcm_volumeChange!\n");
 		exit(EXIT_FAILURE);
 	}
 
@@ -261,12 +261,16 @@ void pcm_volumeChange(char * buffer, int bufferSize, AudioFormat * format,
 	}
 	/* change */
 	if(iScale == 1) {
-		while(samples--)
-			*buffer32++ = *buffer32 >> shift;
+		while(samples--) {
+			*buffer32 = *buffer32 >> shift;
+			buffer32++;
+		}
 	}
 	else {
-		while(samples--)
-			*buffer32++ = (*buffer32 >> shift) * iScale;
+		while(samples--) {
+			*buffer32 = (*buffer32 >> shift) * iScale;
+			buffer32++;
+		}
 	}	
 
 }
@@ -283,8 +287,8 @@ void pcm_add(char * buffer1, char * buffer2, size_t bufferSize1,
 	int iScale2;
 	int shift;
 	
-	if(format->bits!=32 || format->channels!=2 ) {
-		ERROR("Only 32 bit stereo is supported for pcm_add!\n");
+	if(format->bits!=32 || format->fracBits==0 ) {
+		ERROR("Only 32 bit mpd_fixed_t samples are supported in pcm_add!\n");
 		exit(EXIT_FAILURE);
 	}
 
@@ -297,8 +301,10 @@ void pcm_add(char * buffer1, char * buffer2, size_t bufferSize1,
 	/* scale and add samples */
 	/* no check for overflow needed - we trust our headroom is enough */ 
 	while(samples1 && samples2) {
-		*buffer32_1++ = (*buffer32_1 >> shift) * iScale1 +
+		temp = (*buffer32_1 >> shift) * iScale1 +
 			(*buffer32_2 >> shift) * iScale2;
+		*buffer32_1++ = temp;
+		buffer32_2++;
 	}
 	/* take care of case where buffer2 > buffer1 */
 	if(samples2) memcpy(buffer32_1,buffer32_2,samples2<<2);
diff --git a/src/replayGain.c b/src/replayGain.c
index d0de774a0..ace70b0e5 100644
--- a/src/replayGain.c
+++ b/src/replayGain.c
@@ -155,12 +155,16 @@ void doReplayGain(ReplayGainInfo * info, char * buffer, int bufferSize,
 	/* no check for overflow needed - replaygain peak info prevent
 	 * clipping and we have 3 headroom bits in our 32 bit samples */ 
 	if(iScale == 1) {
-		while(samples--)
-			*buffer32++ = *buffer32 >> shift;
+		while(samples--) {
+			*buffer32 = *buffer32 >> shift;
+			buffer32++;
+		}
 	}
-	else {
-		while(samples--)
-			*buffer32++ = (*buffer32 >> shift) * iScale;
+	else { 
+		while(samples--) {
+			*buffer32 = (*buffer32 >> shift) * iScale;
+			buffer32++;
+		}
 	}	
 
 }
-- 
cgit v1.2.3