AudioPlayer instead of AudioOUtput with Minim-Library and multiple mixer?

edited September 2014 in Library Questions

Hi All,

I'm trying to use multiple mixer with the Minim library. Basically, I'm using several USB-Sound Cards in order to get multiple Audio Outputs - I have several mp3's played at the same time, and each mp3 is supposed to go to another speaker.

That's what I have so far (based on the setOutputMixer-Example) and that works fine:

import ddf.minim.*;
import ddf.minim.signals.*;
import controlP5.*;
import javax.sound.sampled.*;
AudioPlayer player;
Minim minim;
Minim minim2;
AudioOutput out;
AudioOutput out2;

Mixer.Info[] mixerInfo;
SineWave sine;
SineWave sine2;

void setup()
{
  size(512, 275);

  minim = new Minim(this);
  minim2 = new Minim(this);

  mixerInfo = AudioSystem.getMixerInfo();

  for(int i = 0; i < mixerInfo.length; i++)
  {println(i + " = " + mixerInfo[i].getName());} 

  sine = new SineWave(220, 0.3, 44100);
  sine2 = new SineWave(20, 1.5, 40100);
 }

void draw()
{
  Mixer mixer = AudioSystem.getMixer(mixerInfo[2]);
  minim.setOutputMixer(mixer);
  out = minim.getLineOut(Minim.STEREO);  
  out.addSignal(sine);

  Mixer mixer2 = AudioSystem.getMixer(mixerInfo[1]);
  minim2.setOutputMixer(mixer2);
  out2 = minim2.getLineOut(Minim.STEREO);  
  out2.addSignal(sine2);
 }

Now the question: Instead of the sine, I want to play mp3's, but I can't manage to add the mp3's to the different mixers (Sorry, I'm kind of a beginner...)

Anyone knows how to do that?

Thanks! Rebecca

Tagged:

Answers

  • edited March 2014 Answer ✓

    Hi there,

    Nice project you are working on. I am trying to do something similar on Minim as well.

    Have you tried this example yet?

    import ddf.minim.*;
    import ddf.minim.analysis.*;
    
    Minim minim;
    AudioPlayer song;
    FFT fft;
    
    void setup()
    {
      size(512, 200);
    
      // always start Minim first!
      minim = new Minim(this);
    
      // specify 512 for the length of the sample buffers
      // the default buffer size is 1024
      song = minim.loadFile("songfile.mp3", 512);
      song.play();
    
      // an FFT needs to know how 
      // long the audio buffers it will be analyzing are
      // and also needs to know 
      // the sample rate of the audio it is analyzing
      fft = new FFT(song.bufferSize(), song.sampleRate());
    }
    
    void draw()
    {}
    

    Of course you must have a .WAV or .MP3 file in the data directory of your sketch!

    Best regards, Weiliang

  • edited September 2014

    Hi Weiliang!

    Thank you!

    This is how I solved the problem in the end:

    import processing.serial.*;
    import cc.arduino.*;
    import ddf.minim.*;
    Arduino arduino;
    
    PFont f;
    
    import ddf.minim.signals.*;
    import javax.sound.sampled.*;
    import ddf.minim.ugens.*;
    
    
    ////////////////////Audio////////
    MultiChannelBuffer sampleBuffer;
    MultiChannelBuffer sampleBuffer2;
    
    AudioOutput        output;
    AudioOutput        output2;
    
    Sampler            sampler;
    Sampler            sampler2;
    
    Balance balance;
    Balance balance2;
    Mixer.Info[] mixerInfo;
    
    
    void setup() {
      size(1200, 765);
      frameRate(fps);
      background(120);
      /////////MUSIC PLAYER//////////////////
      minimONE = new Minim(this);
      minimTWO = new Minim(this);
    
    
    
     mixerInfo = AudioSystem.getMixerInfo();
    
      for(int i = 0; i < mixerInfo.length; i++)
      {println(i + " = " + mixerInfo[i].getName());} 
    
      Mixer mixer = AudioSystem.getMixer(mixerInfo[2]);
      minimONE.setOutputMixer(mixer);
      output = minimONE.getLineOut(Minim.STEREO);
    
      Mixer mixer2 = AudioSystem.getMixer(mixerInfo[4]);
      minimTWO.setOutputMixer(mixer2);
      output2 = minimTWO.getLineOut(Minim.STEREO);
    
    
    
    
    
      sampleBuffer     = new MultiChannelBuffer( 1, 1024 );
      songONE = minimONE.loadFile(song1); songONE.setPan(-1); songONE.loop();
    
      sampleBuffer     = new MultiChannelBuffer( 1, 1024 );
      songTWO = minimTWO.loadFile(song2); songTWO.setPan(-1); songTWO.loop();
    }
    

    Kind regards, Rebecca

Sign In or Register to comment.