Getting Multiple Audio Inputs in Processing

后端 未结 1 1207
误落风尘
误落风尘 2021-01-03 09:57

I\'m currently writing a Processing sketch that needs to access multiple audio inputs, but Processing only allows access to the default line in. I have tried getting Lines

相关标签:
1条回答
  • 2021-01-03 10:51

    I had the same issue a few years ago and I used a combination of JACK, JNAJack and Beads. You can follow this Beads Google Group thread for more details.

    At the that time I had to use this version of Beads (2012-04-23), but I hope those changes probably made it into the main project by now.

    For reference, here is the basic class I used:

    import java.util.Arrays;
    
    import org.jaudiolibs.beads.AudioServerIO;
    
    import net.beadsproject.beads.analysis.featureextractors.FFT;
    import net.beadsproject.beads.analysis.featureextractors.PowerSpectrum;
    import net.beadsproject.beads.analysis.segmenters.ShortFrameSegmenter;
    import net.beadsproject.beads.core.AudioContext;
    import net.beadsproject.beads.core.AudioIO;
    import net.beadsproject.beads.core.UGen;
    import net.beadsproject.beads.ugens.Gain;
    import processing.core.PApplet;
    
    
    public class BeadsJNA extends PApplet {
    
        AudioContext ac;
        ShortFrameSegmenter sfs;
        PowerSpectrum ps;
    
        public void setup(){
            //defining audio context with 6 inputs and 6 outputs - adjust this based on your sound card / JACK setup
            ac = new AudioContext(new AudioServerIO.Jack(),512,AudioContext.defaultAudioFormat(6,6));
    
            //getting 4 audio inputs (channels 1,2,3,4)
            UGen microphoneIn = ac.getAudioInput(new int[]{1,2,3,4});
            Gain g = new Gain(ac, 1, 0.5f);
            g.addInput(microphoneIn);
            ac.out.addInput(g);
    
            println("no. of inputs:  " + ac.getAudioInput().getOuts()); 
    
            //test get some FFT power spectrum data form the 
            sfs = new ShortFrameSegmenter(ac);
            sfs.addInput(ac.out);
            FFT fft = new FFT();
            sfs.addListener(fft);
            ps = new PowerSpectrum();
            fft.addListener(ps);
            ac.out.addDependent(sfs);
    
            ac.start();
        }
        public void draw(){
            background(255);
            float[] features = ps.getFeatures();
            if(features != null){
                for(int x = 0; x < width; x++){
                  int featureIndex = (x * features.length) / width;
                  int barHeight = Math.min((int)(features[featureIndex] *
                                                    height), height - 1);
                  line(x, height, x, height - barHeight);
                } 
            }
        }
    
        public static void main(String[] args) {
            PApplet.main(BeadsJNA.class.getSimpleName());
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题