allow slightly deviated sound rates (for Wiz)
[picodrive.git] / pico / sound / sound.c
index 2b61fc9..a73ebd9 100644 (file)
@@ -17,7 +17,7 @@
 void (*PsndMix_32_to_16l)(short *dest, int *src, int count) = mix_32_to_16l_stereo;\r
 \r
 // master int buffer to mix to\r
-static int PsndBuffer[2*44100/50];\r
+static int PsndBuffer[2*(44100+100)/50];\r
 \r
 // dac\r
 static unsigned short dac_info[312+4]; // pppppppp ppppllll, p - pos in buff, l - length to write for this sample\r
@@ -126,7 +126,10 @@ void PsndRerate(int preserve_state)
 \r
   // not all rates are supported in MCD mode due to mp3 decoder limitations\r
   if (PicoAHW & PAHW_MCD) {\r
-    if (PsndRate != 11025 && PsndRate != 22050 && PsndRate != 44100) PsndRate = 22050;\r
+    if (!(11025-100 <= PsndRate && PsndRate <= 11025+100) &&\r
+        !(22050-100 <= PsndRate && PsndRate <= 22050+100) &&\r
+        !(44100-100 <= PsndRate && PsndRate <= 44100+100))\r
+      PsndRate = 22050;\r
     PicoOpt |= POPT_EN_STEREO; // force stereo\r
   }\r
 \r
@@ -212,12 +215,14 @@ static pm_file *cdda_stream = NULL;
 \r
 static void cdda_raw_update(int *buffer, int length)\r
 {\r
-  int ret, cdda_bytes;\r
-  if (cdda_stream == NULL) return;\r
+  int ret, cdda_bytes, mult = 1;\r
+  if (cdda_stream == NULL)\r
+    return;\r
 \r
   cdda_bytes = length*4;\r
-  if (PsndRate <= 22050) cdda_bytes *= 2;\r
-  if (PsndRate <  22050) cdda_bytes *= 2;\r
+  if (PsndRate <= 22050 + 100) mult = 2;\r
+  if (PsndRate <  22050 - 100) mult = 4;\r
+  cdda_bytes *= mult;\r
 \r
   ret = pm_read(cdda_out_buffer, cdda_bytes, cdda_stream);\r
   if (ret < cdda_bytes) {\r
@@ -227,10 +232,10 @@ static void cdda_raw_update(int *buffer, int length)
   }\r
 \r
   // now mix\r
-  switch (PsndRate) {\r
-    case 44100: mix_16h_to_32(buffer, cdda_out_buffer, length*2); break;\r
-    case 22050: mix_16h_to_32_s1(buffer, cdda_out_buffer, length*2); break;\r
-    case 11025: mix_16h_to_32_s2(buffer, cdda_out_buffer, length*2); break;\r
+  switch (mult) {\r
+    case 1: mix_16h_to_32(buffer, cdda_out_buffer, length*2); break;\r
+    case 2: mix_16h_to_32_s1(buffer, cdda_out_buffer, length*2); break;\r
+    case 4: mix_16h_to_32_s2(buffer, cdda_out_buffer, length*2); break;\r
   }\r
 }\r
 \r