Created
January 21, 2018 13:09
-
-
Save lhns/e65d2a34225acebabbd48ab8576e4493 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################## | |
CODE: | |
########################################################################## | |
import com.xtaudio.xt.*; | |
public class RenderSimple { | |
static double phase = 0.0; | |
static final double FREQUENCY = 660.0; | |
static final XtFormat FORMAT = new XtFormat(new XtMix(48000, XtSample.FLOAT32), 0, 0, 1, 0); | |
static void render(XtStream stream, Object input, Object output, int frames, | |
double time, long position, boolean timeValid, long error, Object user) { | |
System.out.println("render"); | |
for (int f = 0; f < frames; f++) { | |
phase += FREQUENCY / FORMAT.mix.rate; | |
if (phase >= 1.0) | |
phase = -1.0; | |
((float[]) output)[f] = (float) Math.sin(phase * Math.PI); | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
try (XtAudio audio = new XtAudio(null, null, null, null)) { | |
XtService service = XtAudio.getServiceBySetup(XtSetup.PRO_AUDIO); | |
try (XtDevice device = service.openDevice(5)) { | |
System.out.println(device.getName()); | |
if (device != null && device.supportsFormat(FORMAT)) { | |
XtBuffer buffer = device.getBuffer(FORMAT); | |
try (XtStream stream = device.openStream(FORMAT, true, false, | |
buffer.current, RenderSimple::render, null, null)) { | |
System.out.println("starting"); | |
stream.start(); | |
System.out.println("started"); | |
Thread.sleep(10000); | |
System.out.println("stopping"); | |
stream.stop(); | |
} | |
} | |
} | |
} | |
} | |
} | |
########################################################################## | |
OUTPUT: | |
########################################################################## | |
Voicemeeter Virtual ASIO | |
starting | |
started | |
Process finished with exit code -1073741819 (0xC0000005) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment