I am trying to create a program that will read a list of values from a text file and make an audio stream out of it.
I generated a text file of sine wave values (1 cycle, 360 points), and now want to read them into the stream. I would ultimately also like to have the option of saving it to a .wav
EDIT: I have come up with the following code, but there are some errors. The float array has all the right values, but I think the main problem is spitting out the wavetable values gets me way fewer values, looking at the audio output of my speakers, one cycle of a sine wave became 4 cycles of a square wave. Can anyone see any obvious corrections that need to be made?
import ddf.minim.*; import ddf.minim.ugens.*;
Minim minim = new Minim( this ); AudioOutput out = minim.getLineOut( Minim.STEREO, 360 );
for (int i = 0 ; i < strLines.length ; i++) { // use the split array with character to isolate each component String[] linesArray = split(strLines[i], ","); // cast string value to a float values float[] linesArrayFloat = float(linesArray); // create new wave tables from float array values Wavetable table = new Wavetable(linesArrayFloat); table.setWaveform(linesArrayFloat); // create an oscillator with frequency 100 and 0.5 amp using the vales from the table Oscil osc = new Oscil(100, 0.5, table); // output to speakers osc.patch( out ); //test values -> println(table); } }
in.txt is simply a file with 360 values between 0 and 1 that make up one cycle of a sine wave.