How to capture real time audio from MPD (Music Player Daemon)

edited August 2014 in How To...

Yesss It is Yet Another Music Visualizer project. I'm a lamer, a beginner Processing user. These are the facts:

1) MPD can output sound to a fifo queue.... example:

audio_output {
type            "fifo"
name            "visual"
path            "/tmp/mpd.fifo"
format          "44100:16:1"
}

2) I'm trying to use Minim... my setup():

 public void setup() {
        size(640, 480);
         beat = new BeatDetect();
          bbuf = new byte[4*timeSize];
          fbuf = new float[timeSize];
          AudioSystem.getMixerInfo();
          fft = new FFT(timeSize, sr);

        try {
             in=new FileInputStream("/tmp/mpd.fifo");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
 }

and my draw():

public void draw() {
          try {
                if (in.available() >= 4*timeSize) { // only update if there is enough data
                  background(0);  
                  stroke(255);

                  // read one timeSize
                  int nb = in.read(bbuf);
                  int nf = nb / 4;

                  // get floats from byte buffer
                  ByteBuffer bb = ByteBuffer.wrap(bbuf, 0, nb);
                  FloatBuffer fb = bb.asFloatBuffer();
                  fb.get(fbuf, 0, nf);      

                  fft.forward(fbuf);
                  AudioFormat format = new AudioFormat( 44100, // sample rate
                          16,    // sample size in bits
                          1,     // channels
                          true,  // signed
                          true   // bigEndian
                        );


                  System.out.println("Hello users: "+fbuf[2]);
                  for(int i = 0; i < fft.specSize(); i++)
                  {

                    // draw the line for frequency band i, scaling it by 4 so we can see it a bit better
                    line(i, height, i, height - fft.getBand(i)*10);
                  }      
                }
                // drop other samples from buffer
                in.skip(in.available());
              } catch (IOException ioe) {}  
    }

3) I'm using Debian (Testing)

Now the problem:

I'm unable to catch "fft.getBand(i)": for every "i" it is Not a Number "NaN" but... fbuf[j], for every "j", changes while mpd is playing and stops when mpd stops so I'm optimist!!

What's going wrong? Where is my fault?

Thx all

Tagged:
Sign In or Register to comment.