aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-03-05 00:19:02 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-03-05 00:19:02 +0000
commit124854ff511ebca49a219eb82b882595e1a12384 (patch)
treea1211ba3a318740c2a2449d6e408c587fae4426d
parent92692c0249655b48eba2086eee00eb0ab7c6cbbb (diff)
downloadmpd-124854ff511ebca49a219eb82b882595e1a12384.tar.gz
mpd-124854ff511ebca49a219eb82b882595e1a12384.tar.xz
mpd-124854ff511ebca49a219eb82b882595e1a12384.zip
obotomize mixing a bit
git-svn-id: https://svn.musicpd.org/mpd/trunk@198 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/pcm_utils.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index e7d767972..9cfb9efc3 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -85,7 +85,7 @@ void pcm_volumeChange(char * buffer, int bufferSize, AudioFormat * format,
}
void pcm_add(char * buffer1, char * buffer2, size_t bufferSize1,
- size_t bufferSize2, AudioFormat * format)
+ size_t bufferSize2, int vol1, int vol2, AudioFormat * format)
{
mpd_sint32 temp32;
mpd_sint8 * buffer8_1 = (mpd_sint8 *)buffer1;
@@ -96,7 +96,7 @@ void pcm_add(char * buffer1, char * buffer2, size_t bufferSize1,
switch(format->bits) {
case 16:
while(bufferSize1>0 && bufferSize2>0) {
- temp32 = *buffer16_1+*buffer16_2;
+ temp32 = (vol1*(*buffer16_1)+vol2*(*buffer16_2))/100;
*buffer16_1 = temp32>32767 ? 32767 :
(temp32<-32768 ? -32768 : temp32);
buffer16_1++;
@@ -108,7 +108,7 @@ void pcm_add(char * buffer1, char * buffer2, size_t bufferSize1,
break;
case 8:
while(bufferSize1>0 && bufferSize2>0) {
- temp32 = *buffer8_1+*buffer8_2;
+ temp32 = (vol1*(*buffer8_1)+vol2*(*buffer8_2))/100;
*buffer8_1 = temp32>127 ? 127 :
(temp32<-128 ? -128 : temp32);
buffer8_1++;
@@ -127,10 +127,12 @@ void pcm_add(char * buffer1, char * buffer2, size_t bufferSize1,
void pcm_mix(char * buffer1, char * buffer2, size_t bufferSize1,
size_t bufferSize2, AudioFormat * format, float portion1)
{
+ int vol1;
float s = sin(M_PI_2*portion1);
s*=s;
+
+ vol1 = s*100+0.5;
+ vol1 = vol1>100 ? 100 : ( vol1<0 ? 0 : vol1 );
- pcm_volumeChange(buffer1,bufferSize1,format,(int)(s*100));
- pcm_volumeChange(buffer2,bufferSize2,format,(int)((1-s)*100));
- pcm_add(buffer1,buffer2,bufferSize1,bufferSize2,format);
+ pcm_add(buffer1,buffer2,bufferSize1,bufferSize2,vol1,100-vol1,format);
}