Diff of /trunk/arm7/source/arm7main.c [r114] .. [r115] Maximize Restore

  Switch to side-by-side view

--- a/trunk/arm7/source/arm7main.c
+++ b/trunk/arm7/source/arm7main.c
@@ -17,6 +17,17 @@
 
 static int chan = 0;
 
+const short logtable[1024];
+static inline short soundconvert(short output, int sft)
+{
+	if(output >= 0) {
+		output = logtable[output << sft];
+	} else {
+		output = -logtable[(-output) << sft];
+	}
+	return output << 5;
+}
+	
 void restartsound(int ch) {
 	chan = ch;
 
@@ -29,7 +40,6 @@
 	SCHANNEL_CR(6)=SCHANNEL_ENABLE|SOUND_REPEAT |SOUND_VOL(0x7F)|SOUND_PAN(0x40)|SOUND_FORMAT_16BIT;
 	SCHANNEL_CR(7)=SCHANNEL_ENABLE|SOUND_REPEAT |SOUND_VOL(0x7F)|SOUND_PAN(0x40)|SOUND_FORMAT_16BIT;
 	SCHANNEL_CR(8)=SCHANNEL_ENABLE|SOUND_REPEAT |SOUND_VOL(0x7F)|SOUND_PAN(0x40)|SOUND_FORMAT_16BIT;
-
 
 	SCHANNEL_CR(10)=SCHANNEL_ENABLE|SOUND_REPEAT |SOUND_VOL(0x7F)|SOUND_PAN(0x40)|SOUND_FORMAT_8BIT;
 
@@ -75,37 +85,37 @@
 		s16 *dst = &buffer[chan*MIXBUFSIZE];
 		for(i = 0; i < MIXBUFSIZE; i++) {
 			static Int32 preval = 0;
-			Int32 output = NESAPUSoundSquareRender1() << 11;
-			*dst++ = (preval + output) / 2;
-			preval = output;
-		}
-		dst+=MIXBUFSIZE;
-		for(i = 0; i < MIXBUFSIZE; i++) {
-			static Int32 preval = 0;
-			Int32 output = NESAPUSoundSquareRender2() << 11;
-			*dst++ = (preval + output) / 2;
-			preval = output;
-		}
-		dst+=MIXBUFSIZE;
-		for(i = 0; i < MIXBUFSIZE; i++) {
-			static Int32 preval = 0;
-			Int32 output = NESAPUSoundTriangleRender1() << 12;
-			*dst++ = (preval + output) / 2;
-			preval = output;
-		}
-		dst+=MIXBUFSIZE;
-		for(i = 0; i < MIXBUFSIZE; i++) {
-			static Int32 preval = 0;
-			Int32 output = NESAPUSoundNoiseRender1() << 11;
-			output = (preval + output) / 2;
+			Int32 output = soundconvert(NESAPUSoundSquareRender1(), 6);
+			*dst++ = ((preval + output) / 2);
+			preval = output;
+		}
+		dst+=MIXBUFSIZE;
+		for(i = 0; i < MIXBUFSIZE; i++) {
+			static Int32 preval = 0;
+			Int32 output = soundconvert(NESAPUSoundSquareRender2(), 6);
+			*dst++ = ((preval + output) / 2);
+			preval = output;
+		}
+		dst+=MIXBUFSIZE;
+		for(i = 0; i < MIXBUFSIZE; i++) {
+			static Int32 preval = 0;
+			Int32 output = soundconvert(NESAPUSoundTriangleRender1(), 7);
+			*dst++ = ((preval + output) / 2);
+			preval = output;
+		}
+		dst+=MIXBUFSIZE;
+		for(i = 0; i < MIXBUFSIZE; i++) {
+			static Int32 preval = 0;
+			Int32 output = soundconvert(NESAPUSoundNoiseRender1(), 6);
+			output = ((preval + output) / 2);
 			*dst++ = output;
 			preval = output;
 		}
 		dst+=MIXBUFSIZE;
 		for(i = 0; i < MIXBUFSIZE; i++) {
 			static Int32 preval = 0;
-			Int32 output = NESAPUSoundDpcmRender1() << 9;
-			output = (preval + output) / 2;
+			Int32 output = soundconvert(NESAPUSoundDpcmRender1(), 4);
+			output = ((preval + output) / 2);
 			*dst++ = output;
 			preval = output;
 		}
@@ -113,8 +123,8 @@
 		if(mapper == 20) {
 			for(i = 0; i < MIXBUFSIZE; i++) {
 				static Int32 preval = 0;
-				Int32 output = FDSSoundRender3() << 5;
-				output = (preval + output) / 2;
+				Int32 output = soundconvert(FDSSoundRender3(), 0);
+				output = ((preval + output) / 2);
 				*dst++ = output;
 				preval = output;
 			}
@@ -126,7 +136,7 @@
 			for(i = 0; i < MIXBUFSIZE; i++) {
 				static Int32 preval = 0;
 				Int32 output = VRC6SoundRender1() << 11;
-				output = (preval + output) / 2;
+				output = ((preval + output) / 2);
 				*dst++ = output;
 				preval = output;
 			}
@@ -134,7 +144,7 @@
 			for(i = 0; i < MIXBUFSIZE; i++) {
 				static Int32 preval = 0;
 				Int32 output = VRC6SoundRender2() << 11;
-				output = (preval + output) / 2;
+				output = ((preval + output) / 2);
 				*dst++ = output;
 				preval = output;
 			}
@@ -142,7 +152,7 @@
 			for(i = 0; i < MIXBUFSIZE; i++) {
 				static Int32 preval = 0;
 				Int32 output = VRC6SoundRender3() << 10;
-				output = (preval + output) / 2;
+				output = ((preval + output) / 2);
 				*dst++ = output;
 				preval = output;
 			}