@@ -92,23 +92,23 @@ static inline uint32_t add16signed(uint32_t a, uint32_t b) {
9292}
9393
9494__attribute__((always_inline ))
95- static inline uint32_t mult16signed (uint32_t val , int32_t mul [ 2 ] ) {
95+ static inline uint32_t mult16signed (uint32_t val , int32_t lomul , int32_t himul ) {
9696 #if (defined(__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1 ))
97- mul [ 0 ] <<= 16 ;
98- mul [ 1 ] <<= 16 ;
97+ lomul <<= 16 ;
98+ himul <<= 16 ;
9999 int32_t hi , lo ;
100100 enum { bits = 16 }; // saturate to 16 bits
101101 enum { shift = 15 }; // shift is done automatically
102- asm volatile ("smulwb %0, %1, %2" : "=r" (lo ) : "r" (mul [ 0 ] ), "r" (val ));
103- asm volatile ("smulwt %0, %1, %2" : "=r" (hi ) : "r" (mul [ 1 ] ), "r" (val ));
102+ asm volatile ("smulwb %0, %1, %2" : "=r" (lo ) : "r" (lomul ), "r" (val ));
103+ asm volatile ("smulwt %0, %1, %2" : "=r" (hi ) : "r" (himul ), "r" (val ));
104104 asm volatile ("ssat %0, %1, %2, asr %3" : "=r" (lo ) : "I" (bits ), "r" (lo ), "I" (shift ));
105105 asm volatile ("ssat %0, %1, %2, asr %3" : "=r" (hi ) : "I" (bits ), "r" (hi ), "I" (shift ));
106106 asm volatile ("pkhbt %0, %1, %2, lsl #16" : "=r" (val ) : "r" (lo ), "r" (hi )); // pack
107107 return val ;
108108 #else
109109 uint32_t result = 0 ;
110110 for (int8_t i = 0 ; i < 2 ; i ++ ) {
111- float mod_mul = (float )mul [ i ] / (float )((1 << 15 ) - 1 );
111+ float mod_mul = (float )( i ? himul : lomul ) / (float )((1 << 15 ) - 1 );
112112 int16_t ai = (val >> (sizeof (uint16_t ) * 8 * i ));
113113 int32_t intermediate = (int32_t )(ai * mod_mul );
114114 if (intermediate > SHRT_MAX ) {
@@ -232,10 +232,11 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t *self,
232232 }
233233 }
234234
235- int32_t loudness [2 ] = { level , level };
235+ int32_t lo_level = level ;
236+ int32_t hi_level = level ;
236237 if (MP_LIKELY (self -> base .channel_count == 2 )) {
237- loudness [ 0 ] = (left_panning_scaled * loudness [ 0 ] ) >> 15 ;
238- loudness [ 1 ] = (right_panning_scaled * loudness [ 1 ] ) >> 15 ;
238+ lo_level = (left_panning_scaled * lo_level ) >> 15 ;
239+ hi_level = (right_panning_scaled * hi_level ) >> 15 ;
239240 }
240241
241242 // First active voice gets copied over verbatim.
@@ -245,28 +246,28 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t *self,
245246 if (MP_LIKELY (self -> base .channel_count == sample -> channel_count )) {
246247 for (uint32_t i = 0 ; i < n ; i ++ ) {
247248 uint32_t v = src [i ];
248- word_buffer [i ] = mult16signed (v , loudness );
249+ word_buffer [i ] = mult16signed (v , lo_level , hi_level );
249250 }
250251 } else {
251252 for (uint32_t i = 0 ; i < n ; i += 2 ) {
252253 uint32_t v = src [i >> 1 ];
253- word_buffer [i ] = mult16signed (copy16lsb (v ), loudness );
254- word_buffer [i + 1 ] = mult16signed (copy16msb (v ), loudness );
254+ word_buffer [i ] = mult16signed (copy16lsb (v ), lo_level , hi_level );
255+ word_buffer [i + 1 ] = mult16signed (copy16msb (v ), lo_level , hi_level );
255256 }
256257 }
257258 } else {
258259 if (MP_LIKELY (self -> base .channel_count == sample -> channel_count )) {
259260 for (uint32_t i = 0 ; i < n ; i ++ ) {
260261 uint32_t v = src [i ];
261262 v = tosigned16 (v );
262- word_buffer [i ] = mult16signed (v , loudness );
263+ word_buffer [i ] = mult16signed (v , lo_level , hi_level );
263264 }
264265 } else {
265266 for (uint32_t i = 0 ; i + 1 < n ; i += 2 ) {
266267 uint32_t v = src [i >> 1 ];
267268 v = tosigned16 (v );
268- word_buffer [i ] = mult16signed (copy16lsb (v ), loudness );
269- word_buffer [i + 1 ] = mult16signed (copy16msb (v ), loudness );
269+ word_buffer [i ] = mult16signed (copy16lsb (v ), lo_level , hi_level );
270+ word_buffer [i + 1 ] = mult16signed (copy16msb (v ), lo_level , hi_level );
270271 }
271272 }
272273 }
@@ -279,7 +280,7 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t *self,
279280 if (MP_LIKELY (!self -> base .samples_signed )) {
280281 word = tosigned16 (word );
281282 }
282- word = mult16signed (word , loudness );
283+ word = mult16signed (word , lo_level , hi_level );
283284 hword_buffer [i ] = pack8 (word );
284285 }
285286 } else {
@@ -288,8 +289,8 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t *self,
288289 if (MP_LIKELY (!self -> base .samples_signed )) {
289290 word = tosigned16 (word );
290291 }
291- hword_buffer [i ] = pack8 (mult16signed (copy16lsb (word ), loudness ));
292- hword_buffer [i + 1 ] = pack8 (mult16signed (copy16msb (word ), loudness ));
292+ hword_buffer [i ] = pack8 (mult16signed (copy16lsb (word ), lo_level , hi_level ));
293+ hword_buffer [i + 1 ] = pack8 (mult16signed (copy16msb (word ), lo_level , hi_level ));
293294 }
294295 }
295296 }
@@ -299,28 +300,28 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t *self,
299300 if (MP_LIKELY (self -> base .channel_count == sample -> channel_count )) {
300301 for (uint32_t i = 0 ; i < n ; i ++ ) {
301302 uint32_t word = src [i ];
302- word_buffer [i ] = add16signed (mult16signed (word , loudness ), word_buffer [i ]);
303+ word_buffer [i ] = add16signed (mult16signed (word , lo_level , hi_level ), word_buffer [i ]);
303304 }
304305 } else {
305306 for (uint32_t i = 0 ; i + 1 < n ; i += 2 ) {
306307 uint32_t word = src [i >> 1 ];
307- word_buffer [i ] = add16signed (mult16signed (copy16lsb (word ), loudness ), word_buffer [i ]);
308- word_buffer [i + 1 ] = add16signed (mult16signed (copy16msb (word ), loudness ), word_buffer [i + 1 ]);
308+ word_buffer [i ] = add16signed (mult16signed (copy16lsb (word ), lo_level , hi_level ), word_buffer [i ]);
309+ word_buffer [i + 1 ] = add16signed (mult16signed (copy16msb (word ), lo_level , hi_level ), word_buffer [i + 1 ]);
309310 }
310311 }
311312 } else {
312313 if (MP_LIKELY (self -> base .channel_count == sample -> channel_count )) {
313314 for (uint32_t i = 0 ; i < n ; i ++ ) {
314315 uint32_t word = src [i ];
315316 word = tosigned16 (word );
316- word_buffer [i ] = add16signed (mult16signed (word , loudness ), word_buffer [i ]);
317+ word_buffer [i ] = add16signed (mult16signed (word , lo_level , hi_level ), word_buffer [i ]);
317318 }
318319 } else {
319320 for (uint32_t i = 0 ; i + 1 < n ; i += 2 ) {
320321 uint32_t word = src [i >> 1 ];
321322 word = tosigned16 (word );
322- word_buffer [i ] = add16signed (mult16signed (copy16lsb (word ), loudness ), word_buffer [i ]);
323- word_buffer [i + 1 ] = add16signed (mult16signed (copy16msb (word ), loudness ), word_buffer [i + 1 ]);
323+ word_buffer [i ] = add16signed (mult16signed (copy16lsb (word ), lo_level , hi_level ), word_buffer [i ]);
324+ word_buffer [i + 1 ] = add16signed (mult16signed (copy16msb (word ), lo_level , hi_level ), word_buffer [i + 1 ]);
324325 }
325326 }
326327 }
@@ -333,7 +334,7 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t *self,
333334 if (MP_LIKELY (!self -> base .samples_signed )) {
334335 word = tosigned16 (word );
335336 }
336- word = mult16signed (word , loudness );
337+ word = mult16signed (word , lo_level , hi_level );
337338 word = add16signed (word , unpack8 (hword_buffer [i ]));
338339 hword_buffer [i ] = pack8 (word );
339340 }
@@ -343,8 +344,8 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t *self,
343344 if (MP_LIKELY (!self -> base .samples_signed )) {
344345 word = tosigned16 (word );
345346 }
346- hword_buffer [i ] = pack8 (add16signed (mult16signed (copy16lsb (word ), loudness ), unpack8 (hword_buffer [i ])));
347- hword_buffer [i + 1 ] = pack8 (add16signed (mult16signed (copy16msb (word ), loudness ), unpack8 (hword_buffer [i + 1 ])));
347+ hword_buffer [i ] = pack8 (add16signed (mult16signed (copy16lsb (word ), lo_level , hi_level ), unpack8 (hword_buffer [i ])));
348+ hword_buffer [i + 1 ] = pack8 (add16signed (mult16signed (copy16msb (word ), lo_level , hi_level ), unpack8 (hword_buffer [i + 1 ])));
348349 }
349350 }
350351 }
0 commit comments