Generating LUTs for Cosine and Exponential Volume Fades

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Generating LUTs for Cosine and Exponential Volume Fades

Post by neilbaldwin »

I'm pretty rubbish at maths programming so I was wondering if anyone could write some C code to generate a couple of look-up tables.

I need the values from 00 to 0F plotting on both a cosine (S-Curve) and also exponential curve with a range of angles (is it?).

The LUTs should be 16 bytes each of course.

Like these;

http://transom.org/?p=7543
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

One odd thing about the linked page is that he looks at the fade waveforms in the linear space, even though we perceive it in an exponential space. In other words, his exponential fade is really linear, getting louder uniformly, while his linear fade is really exponential, getting loud quickly, then more slowly reaching full volume.

Here's a quick C program I whipped up: gen_vol_fade_curve.c

It graphs the output, for easy experimentation. Example of exponential curve, generating a 32-entry table:

Code: Select all

.byte   0,  1,  1,  1,  1,  2,  2,  2,  2,  3,  3,  4,  4,  4,  5,  5
.byte   6,  6,  7,  7,  8,  9,  9, 10, 10, 11, 12, 12, 13, 14, 15, 15


;  0 *
;  1    *
;  1    *
;  1    *
;  1    *
;  2        *
;  2        *
;  2        *
;  2        *
;  3             *
;  3             *
;  4                 *
;  4                 *
;  4                 *
;  5                     *
;  5                     *
;  6                          *
;  6                          *
;  7                              *
;  7                              *
;  8                                   *
;  9                                       *
;  9                                       *
; 10                                           *
; 10                                           *
; 11                                                *
; 12                                                    *
; 12                                                    *
; 13                                                        *
; 14                                                             *
; 15                                                                 *
; 15                                                                 *
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

Just my 2 cents :
To decrease/increase a value exponentially on the NES, you don't have to use lockup tables, you can do something like this :

Code: Select all

  lda Value
  lsr A
  lsr A
  sta Temp
  lda Value
  sec
  sbc Temp
  sta Value        ;Value = 3/4 * Value
This will make the Value decrease exponentially, by a ratio of 3/4 every time the code is called. Of course it will not work very well for small values, and you can only use fixed ratios with this method.

Otherwise use a soft such as Open Ofice Calc to do it, and copy the values manually with .db statements.... annoying I know but about the same trouble as writing a program just for that.
I did such a thing once for a 12*32 exponential pitch table, and man it was annoying.
Useless, lumbering half-wits don't scare us.
User avatar
neilbaldwin
Posts: 481
Joined: Tue Apr 28, 2009 4:12 am
Contact:

Post by neilbaldwin »

blargg wrote:One odd thing about the linked page is that he looks at the fade waveforms in the linear space, even though we perceive it in an exponential space. In other words, his exponential fade is really linear, getting louder uniformly, while his linear fade is really exponential, getting loud quickly, then more slowly reaching full volume.

Here's a quick C program I whipped up: gen_vol_fade_curve.c

It graphs the output, for easy experimentation. Example of exponential curve, generating a 32-entry table:
Blargg, thank you so much. That is superb! :D

I've realised now that what I had in my head wasn't a cosine curve but possibly an inverse exponential curve (if that's the correct term). You can generate it by setting the 'adjust' parameter in your exp_curve() function to less than 1.0.
Post Reply