76
General Anim8or Forum / Re: WEEHEEEE oh, oh wait its dead, I thought it was dancing (CRE8OR NOTICE)
« on: September 06, 2015, 03:52:21 am »
Been focusing heavily on the sound part of the engine the past week and I finally got a high quality sample rate conversion working on the fly.
I'm having it set up by default to re-sample any sounds loaded into the engine to be the same with what the system is playing back audio on.
Because if you run audio that was recorded at 96000 samples per second and you try playing it back at the more standard 44100 it will sound very deep and low tone; and when you do the opposite, playing audio from a low sample rate (like 22050) to a higher sample rate it would sound high pitched and be played back very fast (like the chipmunks).
So this is where re-sampling comes in handy. If you are running your audio device at a higher or lower sample-rate the engine would re-sample the audio to match the correct sample-rate to make sure things sound correct. This pretty much involves going through every single audio sample there is and finding where the new sample would lie (time wise) one the original and interpolating between the original samples to get the new one. Right now I just have a linear interpolation implemented for this job but I will hopefully add support for other forms of interpolation (for even more high quality).
I posted a screenshot with some debug info on it to help illustrate how efficient this is for on the fly conversion.
Heldon's song, Perspective II is about a 3 min song but has 48000 samples per-second with a total of 9387520 samples.
Converting all that to 44100 to about 0.639272 seconds. Considering this really only needs to happen once per audio file and there wouldn't be that many long audio files being loaded up at once I am extremely happy with the result; and if you look at the result for chime3, a much smaller audio file (about 10 seconds long at 96000 samples a second), you can see how feasible this would be for many small files.
Right now I have it setup like this, Sound = LoadSound (filename); PlaySound (Sound); And the engine takes care of the rest.
In the end I'm going to aim for having the user just load a sound and play it and it would work by default and then giving them the option to do all this manually for more advanced uses.
I'm having it set up by default to re-sample any sounds loaded into the engine to be the same with what the system is playing back audio on.
Because if you run audio that was recorded at 96000 samples per second and you try playing it back at the more standard 44100 it will sound very deep and low tone; and when you do the opposite, playing audio from a low sample rate (like 22050) to a higher sample rate it would sound high pitched and be played back very fast (like the chipmunks).
So this is where re-sampling comes in handy. If you are running your audio device at a higher or lower sample-rate the engine would re-sample the audio to match the correct sample-rate to make sure things sound correct. This pretty much involves going through every single audio sample there is and finding where the new sample would lie (time wise) one the original and interpolating between the original samples to get the new one. Right now I just have a linear interpolation implemented for this job but I will hopefully add support for other forms of interpolation (for even more high quality).
I posted a screenshot with some debug info on it to help illustrate how efficient this is for on the fly conversion.
Heldon's song, Perspective II is about a 3 min song but has 48000 samples per-second with a total of 9387520 samples.
Converting all that to 44100 to about 0.639272 seconds. Considering this really only needs to happen once per audio file and there wouldn't be that many long audio files being loaded up at once I am extremely happy with the result; and if you look at the result for chime3, a much smaller audio file (about 10 seconds long at 96000 samples a second), you can see how feasible this would be for many small files.
Right now I have it setup like this, Sound = LoadSound (filename); PlaySound (Sound); And the engine takes care of the rest.
In the end I'm going to aim for having the user just load a sound and play it and it would work by default and then giving them the option to do all this manually for more advanced uses.