Friday, April 18, 2014

Generating Audio from Arbitrary Pressure Groups

Today, I wrote the last leg of this project: generating audio from arbitrary pressure data. The purpose of this is not only to take some random data and make audio from it--that's easy to do. By simply throwing numbers at WebAudio I can make random, meaningless noise. Now I'm searching for some means of making the sound meaningful in some way, for instance making the tone sharper or flatter as the pressure group moves up or down the x-axis. If changes in the tone are made meaningful, then this project has applications in both human and machine learning, assuming that the agent learning from the device knows how to interpret the changes in tone.

I'll post information on the process of actually making the tone meaningful as that happens, but for now I have something basic that accomplishes this imperfectly:

freq = 110 * (Math.pow(2, max_data / (1000 * area)) + (center_y) + (center_x / 10))

This takes the frequency of an A2 (110), scales it up by 2 to the power of the local pressure maximum divided by the area adjusted to be more even with the max_data point, then offsets the resulting value by the center coordinates. The multiplication by a power of 2 was chosen because the same note in different octaves represents the frequency of that note in octave 1 * 2^the current octave number (e.g. A1 = 55Hz, A2=110Hz, A3=220Hz, etc.).

This method, as mentioned above, needs tweaking. Many different groups sound similar by virtue of the
 
max_data / (1000 * area) 

calculation, and THEA is actually so sensitive to pressure input that even a small change in pressure can cause the max_data variable to skyrocket, resulting in high-frequency spikes.

On the Javascript end of today's code, and if anyone from W3C sees this, WebAudio's AudioBufferSourceNode object could benefit from a function to check whether or not the node is in start() or stop() state. Javascript throws up an error when a node is started or stopped twice while in the each respective state, and while it isn't hard to implement a check using boolean flags, I was surprised to see that an internal state is not set when start or stop is called. Perhaps it is and that state is simply kept private. In any case, that's a minor issue at best.

No comments:

Post a Comment