Browse Source

Comment change & RIX volume optimize & resampler optimize with bug fix in BLEP filter

louyihua 8 years ago
parent
commit
0e93ecac0a
3 changed files with 505 additions and 527 deletions
  1. 481 500
      resampler.c
  2. 18 21
      rixplay.cpp
  3. 6 6
      sound.c

File diff suppressed because it is too large
+ 481 - 500
resampler.c


+ 18 - 21
rixplay.cpp

@@ -79,7 +79,6 @@ RIX_FillBuffer(
 --*/
 {
 	LPRIXPLAYER pRixPlayer = (LPRIXPLAYER)object;
-	static const int max_volume = SDL_MIX_MAXVOLUME;
 
 	if (pRixPlayer == NULL || !pRixPlayer->fReady)
 	{
@@ -102,12 +101,12 @@ RIX_FillBuffer(
 			if (pRixPlayer->iRemainingFadeSamples <= 0)
 			{
 				pRixPlayer->FadeType = RIXPLAYER::NONE;
-				volume = max_volume;
+				volume = SDL_MIX_MAXVOLUME;
 			}
 			else
 			{
-				volume = (INT)(max_volume * (1.0 - (double)pRixPlayer->iRemainingFadeSamples / pRixPlayer->iTotalFadeInSamples));
-				delta_samples = pRixPlayer->iTotalFadeInSamples / max_volume; vol_delta = 1;
+				volume = (INT)(SDL_MIX_MAXVOLUME * (1.0 - (double)pRixPlayer->iRemainingFadeSamples / pRixPlayer->iTotalFadeInSamples));
+				delta_samples = pRixPlayer->iTotalFadeInSamples / SDL_MIX_MAXVOLUME; vol_delta = 1;
 			}
 			break;
 		case RIXPLAYER::FADE_OUT:
@@ -149,8 +148,8 @@ RIX_FillBuffer(
 			}
 			else
 			{
-				volume = (INT)(max_volume * ((double)pRixPlayer->iRemainingFadeSamples / pRixPlayer->iTotalFadeOutSamples));
-				delta_samples = pRixPlayer->iTotalFadeOutSamples / max_volume; vol_delta = -1;
+				volume = (INT)(SDL_MIX_MAXVOLUME * ((double)pRixPlayer->iRemainingFadeSamples / pRixPlayer->iTotalFadeOutSamples));
+				delta_samples = pRixPlayer->iTotalFadeOutSamples / SDL_MIX_MAXVOLUME; vol_delta = -1;
 			}
 			break;
 		default:
@@ -163,7 +162,7 @@ RIX_FillBuffer(
 			}
 			else
 			{
-				volume = max_volume;
+				volume = SDL_MIX_MAXVOLUME;
 			}
 		}
 
@@ -239,31 +238,29 @@ RIX_FillBuffer(
 			//
 			// Put audio data into buffer and adjust volume
 			//
-			SHORT* ptr = (SHORT*)stream;
-			if (pRixPlayer->FadeType == RIXPLAYER::NONE)
-			{
-				for (int i = 0; i < l; i++)
-				{
-					*ptr++ = *(SHORT *)pRixPlayer->pos * volume / max_volume;
-					pRixPlayer->pos += sizeof(SHORT);
-				}
-			}
-			else
+			if (pRixPlayer->FadeType != RIXPLAYER::NONE)
 			{
+				short* ptr = (short*)stream;
 				for (int i = 0; i < l && pRixPlayer->iRemainingFadeSamples > 0; volume += vol_delta)
 				{
 					int j = 0;
 					for (j = 0; i < l && j < delta_samples; i++, j++)
 					{
-						*ptr++ = *(SHORT *)pRixPlayer->pos * volume / max_volume;
-						pRixPlayer->pos += sizeof(SHORT);
+						*ptr++ = *(short*)pRixPlayer->pos * volume / SDL_MIX_MAXVOLUME;
+						pRixPlayer->pos += sizeof(short);
 					}
 					pRixPlayer->iRemainingFadeSamples -= j;
 				}
 				fContinue = (pRixPlayer->iRemainingFadeSamples > 0);
+				len -= (LPBYTE)ptr - stream; stream = (LPBYTE)ptr;
+			}
+			else
+			{
+				memcpy(stream, pRixPlayer->pos, l * sizeof(short));
+				pRixPlayer->pos += l * sizeof(short);
+				stream += l * sizeof(short);
+				len -= l * sizeof(short);
 			}
-			len -= (LPBYTE)ptr - stream;
-			stream = (LPBYTE)ptr;
 		}
 	}
 }

+ 6 - 6
sound.c

@@ -314,7 +314,7 @@ SOUND_ResampleU8(
 /*++
 	Purpose:
 
-	Resample 8-bit unsigned PCM data into 16-bit signed (little-endian) PCM data.
+	Resample 8-bit unsigned PCM data into 16-bit signed (native-endian) PCM data.
 
 	Parameters:
 
@@ -358,7 +358,7 @@ SOUND_ResampleU8(
 			while (total_bytes < channel_len && resampler_get_sample_count(resampler) > 0)
 			{
 				*dst = resampler_get_and_remove_sample(resampler);
-				dst += lpSpec->channels; total_bytes += (SDL_AUDIO_BITSIZE(AUDIO_S16) >> 3);
+				dst += lpSpec->channels; total_bytes += (SDL_AUDIO_BITSIZE(AUDIO_S16SYS) >> 3);
 			}
 		}
 		/* Flush resampler's output buffer */
@@ -370,7 +370,7 @@ SOUND_ResampleU8(
 			while (total_bytes < channel_len && resampler_get_sample_count(resampler) > 0)
 			{
 				*dst = resampler_get_and_remove_sample(resampler);
-				dst += lpSpec->channels; total_bytes += (SDL_AUDIO_BITSIZE(AUDIO_S16) >> 3);
+				dst += lpSpec->channels; total_bytes += (SDL_AUDIO_BITSIZE(AUDIO_S16SYS) >> 3);
 			}
 		}
 	}
@@ -387,7 +387,7 @@ SOUND_ResampleS16(
 /*++
 	Purpose:
 
-	Resample 16-bit signed (little-endian) PCM data into 16-bit signed (little-endian) PCM data.
+	Resample 16-bit signed (little-endian) PCM data into 16-bit signed (native-endian) PCM data.
 
 	Parameters:
 
@@ -431,7 +431,7 @@ SOUND_ResampleS16(
 			while (total_bytes < channel_len && resampler_get_sample_count(resampler) > 0)
 			{
 				*dst = resampler_get_and_remove_sample(resampler);
-				dst += lpSpec->channels; total_bytes += (SDL_AUDIO_BITSIZE(AUDIO_S16) >> 3);
+				dst += lpSpec->channels; total_bytes += (SDL_AUDIO_BITSIZE(AUDIO_S16SYS) >> 3);
 			}
 		}
 		/* Flush resampler's output buffer */
@@ -444,7 +444,7 @@ SOUND_ResampleS16(
 			while (total_bytes < channel_len && resampler_get_sample_count(resampler) > 0)
 			{
 				*dst = resampler_get_and_remove_sample(resampler);
-				dst += lpSpec->channels; total_bytes += (SDL_AUDIO_BITSIZE(AUDIO_S16) >> 3);
+				dst += lpSpec->channels; total_bytes += (SDL_AUDIO_BITSIZE(AUDIO_S16SYS) >> 3);
 			}
 		}
 	}