Page 1 of 1

[SOLVED] Lua computation time question

Posted: Sun Jul 08, 2012 4:55 pm
by AaronV
Hello! My name is Aaron V. and I'm hoping to work on a procedural audio project.
If it turns out well, I'd like to make an audio based game or something fun like that with Love.
Otherwise, I'll probably just make a different game lol.

I'm using ProteaAudio - it's pretty great.
And it's going well, too.

But sound needs a ton of Sine waves - the more the better.
I'm worried because of calculation time.

I can make a table that would store enough sine results to make a clunky approximation of Sine.
For example 1000 data points is said to give perfect audio for up to 500 Hz - not sure if they're counting the fact that you can use the first half for the second half...
Human ear goes up to 40000 Hz of course, requiring at least 40000 data points for perfect audio.

The cool part is that I'm not worried about perfectly recreating a sine wave.
So I'd only need like 1600 data points - 1600 numbers in RAM - 6400 bits I'm guessing.
Not sure if that's a lot but I have 4 gb of RAM so I'm not worried about it lol.


Blah blah blah
MY QUESTION IS would it not be faster to call up data from a table than to calculate sine?
How many times more efficient do you suppose one is over the other?

I only need an educated guess, I'd rather not mess around with benchmarking lol.
I'm still pretty slow at programming so that's no trivial task for me.

Re: Lua computation time question

Posted: Sun Jul 08, 2012 5:47 pm
by Xgoff
AaronV wrote:Hello! My name is Aaron V. and I'm hoping to work on a procedural audio project.
If it turns out well, I'd like to make an audio based game or something fun like that with Love.
Otherwise, I'll probably just make a different game lol.

I'm using ProteaAudio - it's pretty great.
And it's going well, too.

But sound needs a ton of Sine waves - the more the better.
I'm worried because of calculation time.

I can make a table that would store enough sine results to make a clunky approximation of Sine.
For example 1000 data points is said to give perfect audio for up to 500 Hz - not sure if they're counting the fact that you can use the first half for the second half...
Human ear goes up to 40000 Hz of course, requiring at least 40000 data points for perfect audio.

The cool part is that I'm not worried about perfectly recreating a sine wave.
So I'd only need like 1600 data points - 1600 numbers in RAM - 6400 bits I'm guessing.
Not sure if that's a lot but I have 4 gb of RAM so I'm not worried about it lol.


Blah blah blah
MY QUESTION IS would it not be faster to call up data from a table than to calculate sine?
How many times more efficient do you suppose one is over the other?

I only need an educated guess, I'd rather not mess around with benchmarking lol.
I'm still pretty slow at programming so that's no trivial task for me.
the table will likely be faster, since function calls are fairly expensive. in a simple benchmark i did they were around 4x faster.
For example 1000 data points is said to give perfect audio for up to 500 Hz - not sure if they're counting the fact that you can use the first half for the second half...
Human ear goes up to 40000 Hz of course, requiring at least 40000 data points for perfect audio.
well no, that's just a thing you have to do when sampling audio; you need to sample at least twice your target frequency in order to get a good approximation of the sound. the human ear actually only goes up to around 20khz

Re: Lua computation time question

Posted: Sun Jul 08, 2012 9:02 pm
by AaronV
Oh, right. Hence the 40000 number - double 20000. My bad.

Well thank you, I'll be using a table then. :awesome:

It's gonna sample at waaaay the wrong rate and be exceptionally fast. :crazy:

Re: [SOLVED] Lua computation time question

Posted: Mon Sep 10, 2012 2:43 pm
by kevintani1506
thanks a lot.... thanks for your information... very much useful for me.... keep on posting...:-)