Reputation: 23
I created a small program to record sound (I use JavaSound with TargetDataLine to reach my sound card). I did some testing with the class " DualOscilloscope.java " of JSYN for a visual of the sound . The problem is that their class opens a line with " Synthesizer " so I have two line tapping on my soundcard and me that triggers an exception (as you can not open two line on a sound card). Is it possible to use my instantiating my TargetDataLine to initialize the synthesizer of JSYN ?
Source code class DualOscilloscope (author Phil Burk )
protected void startAudio(int itemIndex) {
// Both stereo.
int numInputChannels = deviceMaxInputs.get(itemIndex);
if (numInputChannels > 2)
numInputChannels = 2;
int inputDeviceIndex = deviceIds.get(itemIndex);
synth.start(16000, inputDeviceIndex, numInputChannels, AudioDeviceManager.USE_DEFAULT_DEVICE, 0);
channel1.output.connect(pass1.input);
// Only connect second channel if more than one input channel.
if (numInputChannels > 1) {
channel2.output.connect(pass2.input);
}
// We only need to start the LineOut. It will pull data from the
// channels.
scope.start();
Upvotes: 0
Views: 207
Reputation: 711
JSyn does not currently support being passed a TargetDataLine. You could, however, implement your own AudioDeviceManager based on the source code on GitHub. Replace JavaSoundAudioDevice.java with one that used your TargetDataLine instead of creating a new one.
An easier way would be to let JSyn open the audio input and then use that input in your program. Don't open your own TargetDataLine.
You can use JSyn to process audio or to save it as a WAVE file. If you need to do custom processing then you could write a custom unit generator. Or you could use an AudioStreamReader to stream the audio data to your own thread.
AudioStreamReader reader = new AudioStreamReader(synth, 2); // stereo
lineIn.connect(0, read.getInput(), 0);
lineIn.connect(1, read.getInput(), 1);
Then you can read the data from that reader instead of from your own TargetDataLine.
reader.read(buffer, start, count);
Upvotes: 0