data structures - Using a SymbolTable in Java to Play Short Song -
i'm using java play short song , have create symbol tables out of input text file, have feeling i'm doing wrong assigning keys , values, i'm not sure i'm doing wrong. when run program make sound audio file going start , stops why think key value pairs incorrect. appreciated, here code:
package program2; import algs31.binarysearchst; import stdlib.stdaudio; import stdlib.stdin; public class playsimplesong{ public static void main(string[] args) { stdin.fromfile("data/notes_frequencies.txt"); binarysearchst<string, double> nf = new binarysearchst<>(); string key = stdin.readline(); string[] lines = key.split("\\s"); string notes = lines[0]; double frequency = double.parsedouble(lines[1]); nf.put(notes, frequency); stdin.fromfile("data/sample_simple_song.txt"); binarysearchst<string, double> ss = new binarysearchst<>(); string song = stdin.readline(); string[] lines2 = song.split("\\s"); string note = lines2[0]; double duration = double.parsedouble(lines2[1]); ss.put(note, duration); playtone(frequency, duration); } public static void playtone(double frequency, double duration) { final int slicecount = (int) (stdaudio.sample_rate * duration); final double[] slices = new double[slicecount+1]; (int = 0; <= slicecount; i++) { slices[i] = math.sin(2 * math.pi * * frequency / stdaudio.sample_rate); } stdaudio.play(slices); } }
Comments
Post a Comment