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
Generating LUTs for Cosine and Exponential Volume Fades
Moderator: Moderators
- neilbaldwin
- Posts: 481
- Joined: Tue Apr 28, 2009 4:12 am
- Contact:
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:
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 *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 :
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.
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
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.
- neilbaldwin
- Posts: 481
- Joined: Tue Apr 28, 2009 4:12 am
- Contact:
Blargg, thank you so much. That is superb!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:
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.