[SOLVED] Lua computation time question

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
AaronV
Prole
Posts: 16
Joined: Sun Jul 08, 2012 4:11 am

[SOLVED] Lua computation time question

Post 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.
Last edited by AaronV on Tue Jul 24, 2012 9:33 pm, edited 1 time in total.
What have I gotten myself into?
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Lua computation time question

Post 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
AaronV
Prole
Posts: 16
Joined: Sun Jul 08, 2012 4:11 am

Re: Lua computation time question

Post 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:
What have I gotten myself into?
kevintani1506
Prole
Posts: 1
Joined: Mon Sep 10, 2012 2:42 pm
Contact:

Re: [SOLVED] Lua computation time question

Post by kevintani1506 »

thanks a lot.... thanks for your information... very much useful for me.... keep on posting...:-)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests