Direct Sample Manipulation!!! Oh Yeah!

BlitzMax Forums/BlitzMax Programming/Direct Sample Manipulation!!! Oh Yeah!

RexRhino(Posted 2004) [#1]
I was just going through the BlitzMax docs... and I was super excited to see that we are able to directly access sample data! Which means that realtime sound manipulation and sound synthesis is now not only possible, but super easy! Way to go Mark for adding this feature! Super cool!

Has anyone tried using this functionality yet??? I can't wait to try the win32 version to start doing some realtime softsynths.


marksibly(Posted 2004) [#2]
Umm...it may not be what you think.

The TAudioSample type is an 'intermediate' format for audio samples. You can load and create audiosamples, but there is not currently any way to manipulate them in realtime as they are playing.


RexRhino(Posted 2004) [#3]
Couldn't one use double buffering, like for screen graphics?

For example, one can have two 250ms samples as buffers... in your loop, you use ChannelPlaying (does it exist in BlitzMax?) to see if sample A is playing... if so, you continue generating sample B. If sample A is no longer playing, you now play sample B and begin generating a new sample A. You will get a latency of however big your buffer is (for example, if your buffer is 250ms seconds, then changes in your realtime settings only change every 250ms seconds).

This could probably be encapsulated in an object/library, so it would be completly transparent (You would just use methods to change the buffer and call a worker method each loop and the object would handle the rest of the stuff).

The only reason it might not work is if the commands to create a sample, load a sample, and then discard a sample are too slow. But since this is all in memory and there is no disk usage, I don't see why this would be the case?

As a side note, how I am assuming .samples works like an array, and for a stereo sample I can use something like:

sound.samples[ksample, left_channel] = whitenoise()

It wasn't fully explained in the docs.


RexRhino(Posted 2004) [#4]
Another Additional Question:

The command CreateStaticAudioSample gets the data from existing memory as I understand it. Does the TAudioSample object and the subsequent TSound object make an additional copy of the referenced memory, or does it use a pointer to the memory in each object. Because if it is just a pointer to the same peice of memory and not copying a big chunk of memory with each new object, I don't see why there would be any kind of slowdown for creating and deleteing TAudioSamples and TSounds?


Taron(Posted 2008) [#5]
There we have a beautiful question! And it's 3 years old.... holy crap, it should already be speaking! 8)