Getting multiple audio inputs
in
Contributed Library Questions
•
7 months ago
I had a look a few older threads on the forum and the consensus seemed to be that it's better to use OSC to route audio data from something else (like PD,Max,etc.).
I wish there was a way to use two different audio inputs all in Processing.
Had a quick look at Beads and modified a sample:
- // Audio_Input_01.pde
- import beads.*; // import the beads library
- AudioContext ac1,ac2; // declare the parent AudioContext
- void setup() {
- size(800,800);
- ac1 = new AudioContext(); // initialize the AudioContext
- //((JavaSoundAudioIO)ac.getAudioIO()).chooseMixerCommandLine();
- //((JavaSoundAudioIO)ac1.getAudioIO()).printMixerInfo();
- // get an AudioInput UGen from the AudioContext
- // this will setup an input from whatever input is your default audio input (usually the microphone in)
- // changing audio inputs in beads is a little bit janky (as of this writing)
- // so it's best to change your default input temporarily, if you want to use a different input
- UGen microphoneIn = ac1.getAudioInput();
- // set up our usual master gain object
- Gain g = new Gain(ac1, 1, 0.5);
- g.addInput(microphoneIn);
- ac1.out.addInput(g);
- //ac1.start(); // begin working with audio
- JavaSoundAudioIO aio = new JavaSoundAudioIO();
- aio.selectMixer(3);
- ac2 = new AudioContext(aio);
- UGen sysIn = ac2.getAudioInput();
- Gain g2 = new Gain(ac2, 1, 0.5);
- g2.addInput(sysIn);
- ac2.out.addInput(g2);
- ac2.start();
- }
- // draw the input waveform on screen
- // this code is based on code from the Beads tutorials
- void draw()
- {
- loadPixels();
- //set the background
- java.util.Arrays.fill(pixels, color(0));
- AudioContext ac = ac1;
- //scan across the pixels
- for(int i = 0; i < width; i++)
- {
- //for each pixel work out where in the current audio buffer we are
- int buffIndex = i * ac.getBufferSize() / width;
- //then work out the pixel height of the audio data at that point
- int vOffset = (int)((1 + ac.out.getValue(0, buffIndex)) * height / 2);
- //draw into Processing's convenient 1-D array of pixels
- pixels[vOffset * height + i] = color(255);
- }
- updatePixels(); // paint the new pixel array to the screen
- }
but I get this error when calling ac2.start() (initializing the second context):
- JavaSoundAudioIO: Chosen mixer is Soundflower (64ch).
- java.lang.NullPointerException
- at processing.mode.java.runner.Runner.findException(Runner.java:707)
- at processing.mode.java.runner.Runner.reportException(Runner.java:652)
- at processing.mode.java.runner.Runner.exception(Runner.java:595)
- at processing.mode.java.runner.EventThread.exceptionEvent(EventThread.java:367)
- at processing.mode.java.runner.EventThread.handleEvent(EventThread.java:255)
- at processing.mode.java.runner.EventThread.run(EventThread.java:89)
- Exception in thread "Thread-4" java.lang.IllegalArgumentException: Line unsupported: interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian
- at com.sun.media.sound.SimpleInputDevice.getLine(SimpleInputDevice.java:142)
- at beads.JavaSoundAudioIO.setupOutputJavaSound(Unknown Source)
- at beads.JavaSoundAudioIO.access$100(Unknown Source)
- at beads.JavaSoundAudioIO$1.run(Unknown Source)
- at java.lang.Thread.run(Thread.java:680)
I googled a bit then had a look at this
Java article but ran into the same error using:
- import javax.sound.sampled.*;
- AudioFormat format = new AudioFormat(44100,32,2,false,true);
- TargetDataLine line;
- DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); // format is an AudioFormat object
- if (!AudioSystem.isLineSupported(info)) {
- // Handle the error.
- }
- // Obtain and open the line.
- try {
- line = (TargetDataLine) AudioSystem.getLine(info);
- line.open(format);
- } catch (LineUnavailableException ex) {
- // Handle the error.
- //...
- }
I tried different variations for the AudioFormat constructor (16 bit, rather than 32, signed/unsigned/, little/big endian), but to be honest I don't fully understand how the javax.sound.* classes work.
Has anyone managed to read multiple audio inputs in Processing only ? If so, how ?
Thanks,
George
1