@@ -43,6 +43,8 @@ mpxplay_audioout_info_s aui = {0};
43
43
static int16_t MAIN_OPLPCM [MAIN_PCM_SAMPLESIZE ];
44
44
static int16_t MAIN_PCM [MAIN_PCM_SAMPLESIZE ];
45
45
static int16_t MAIN_PCMResample [MAIN_PCM_SAMPLESIZE ];
46
+ static int MAIN_LastSBRate = 0 ;
47
+ static int16_t MAIN_LastResample [SBEMU_CHANNELS ];
46
48
47
49
static DPMI_ISR_HANDLE MAIN_IntHandlePM ;
48
50
static DPMI_ISR_HANDLE MAIN_IntHandleRM ;
@@ -1133,6 +1135,11 @@ static void MAIN_Interrupt()
1133
1135
uint32_t SB_Bytes = SBEMU_GetSampleBytes ();
1134
1136
uint32_t SB_Pos = SBEMU_GetPos ();
1135
1137
uint32_t SB_Rate = SBEMU_GetSampleRate ();
1138
+ if (MAIN_LastSBRate != SB_Rate )
1139
+ {
1140
+ for (int i = 0 ; i < SBEMU_CHANNELS ; ++ i ) MAIN_LastResample [i ] = 0 ;
1141
+ MAIN_LastSBRate = SB_Rate ;
1142
+ }
1136
1143
int samplesize = max (1 , SBEMU_GetBits ()/8 ); //sample size in bytes 1 for 8bit. 2 for 16bit
1137
1144
int channels = SBEMU_GetChannels ();
1138
1145
_LOG ("sample rate: %d %d\n" , SB_Rate , aui .freq_card );
@@ -1173,7 +1180,7 @@ static void MAIN_Interrupt()
1173
1180
int bytes = count * samplesize * channels ;
1174
1181
1175
1182
{
1176
- int16_t * pcm = resample ? MAIN_PCMResample : MAIN_PCM + pos * 2 ;
1183
+ int16_t * pcm = resample ? MAIN_PCMResample + channels : MAIN_PCM + pos * 2 ;
1177
1184
if (MAIN_DMA_MappedAddr == 0 ) //map failed?
1178
1185
memset (pcm , 0 , bytes );
1179
1186
else
@@ -1183,7 +1190,14 @@ static void MAIN_Interrupt()
1183
1190
if (samplesize != 2 )
1184
1191
cv_bits_n_to_m (pcm , count * channels , samplesize , 2 );
1185
1192
if (resample /*SB_Rate != aui.freq_card*/ )
1186
- count = mixer_speed_lq (MAIN_PCM + pos * 2 , MAIN_PCM_SAMPLESIZE - pos * 2 , pcm , count * channels , channels , SB_Rate , aui .freq_card )/channels ;
1193
+ {
1194
+ for (int i = 0 ; i < channels ; ++ i )
1195
+ {
1196
+ MAIN_PCMResample [i ] = MAIN_LastResample [i ]; //put last sample at beginning for interpolation
1197
+ MAIN_LastResample [i ] = * (pcm + (count - 1 )* channels + i ); //record last sample
1198
+ }
1199
+ count = mixer_speed_lq (MAIN_PCM + pos * 2 , MAIN_PCM_SAMPLESIZE - pos * 2 , MAIN_PCMResample , count * channels , channels , SB_Rate , aui .freq_card )/channels ;
1200
+ }
1187
1201
}
1188
1202
if (channels == 1 ) //should be the last step
1189
1203
cv_channels_1_to_n (MAIN_PCM + pos * 2 , count , 2 , 2 );
0 commit comments