Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double fa=220, fb=0;
- SourceDataLine speaker;
- AudioFormat af = new AudioFormat(44100f, 16, 1, true, false);
- DataLine.Info info = new DataLine.Info(SourceDataLine.class, af);
- speaker = (SourceDataLine) AudioSystem.getLine(info);
- speaker.open(af, 4096);
- speaker.start();
- double t = 0;
- short[] buff = new short[256];
- byte[] toSoundCard = new byte[buff.length*2];
- for (;;) {
- if(t>=1) break;
- System.out.println(t+" "+e.getValueAt(t));
- for (int i = 0; i < buff.length; i++) {
- double f=lerp(fa,fb,t);
- //System.out.println(f);
- buff[i] = (short) (Short.MAX_VALUE * 0.5 * Math.sin(t * Math.PI * 2 * f));
- toSoundCard[2 * i] = (byte) buff[i];
- toSoundCard[2 * i + 1] = (byte) (buff[i] >> 8); //(i know i could avoid doing this)
- t += 1.0 / 44100.0;
- }
- speaker.write(toSoundCard, 0, toSoundCard.length);
- }`
- where lerp is this function:
- public static final double lerp(double a, double b, double f) {
- double fn = f > 1 ? 1 : f < 0 ? 0 : f;
- return a * (1 - fn) + b * fn;
- }
Advertisement
Add Comment
Please, Sign In to add comment