gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > Global volume, unsigned samples and bias... agh!

#163748 - Ruben - Fri Oct 10, 2008 10:41 am

So.. In my older code I used to use signed samples until I got unsigned working but the problem is the "global volume" thing. In my old code I would just multiply by that and shift by 7 (127 being the max volume) but it stuffs up the bias if I do that with unsigned so does anyone know how to handle this?

(Sorry if I sound odd, kinda dizzy)

#163753 - eKid - Fri Oct 10, 2008 2:24 pm

Can't you apply the global volume to the signed samples during the mixdown?
(ie convert mixed data unsigned->signed, apply global volume, shift to 8bit, write to output)

#163759 - Ruben - Fri Oct 10, 2008 4:05 pm

For some odd reason nope. I get this weird high pitched square wave.

*pout*

#163760 - Ruben - Fri Oct 10, 2008 4:17 pm

Hmm... Checking it again it works fine when the volume is near the max, but otherwise, it stuffs up the bias. :-S

(May be a bit different since I'm using pimpmobile's clipping routine)

#163787 - Ruben - Sat Oct 11, 2008 5:11 pm

OK. Re-wrote the routine and it seems to work fine but if it's not 80h then the sound becomes distorted like... big time.

Code:
Test Example

.Lmixdown_loop:
  ldrh   r8, [r0, #0x02]
  add    r8, r5, r8, asr #((VOLUME_BITS-CHN_SHIFT)+1)
  subs   r9, r6, r8, asr #0x08
  andne  r8, r7, r9, lsr #0x18
  eor    r8, r8, #0x80
  mul    r9, r8, r2
  mov    r8, r9, lsr #VOLUME_BITS
  strb   r8, [r1, #MAXIMMUM_BUFLENGTH]
 
  ldrh   r8, [r0], #0x04
  add    r8, r5, r8, asr #((VOLUME_BITS-CHN_SHIFT)+1)
  subs   r9, r6, r8, asr #0x08
  andne  r8, r7, r9, lsr #0x18
  eor    r8, r8, #0x80
  mul    r9, r8, r2
  mov    r8, r9, lsr #VOLUME_BITS
  strb   r8, [r1], #0x01
 
  subs   r3, r3, #0x01
  bne    .Lmixdown_loop