0

I'm trying to load a wav file into a FilePlayer using Processing and Minim Library (later I want to patch a Delay on it). However, the wav file I was given plays too fast, at least at double the speed it is supposed to and it is very high pitched. The file sounds like it is supposed to if I play it in VLC Media Player or in WMP. It is 5 seconds long at a Bit Rate of 20kbps, but the code prints out it is 2299ms long.

Code:

import ddf.minim.*;
import ddf.minim.ugens.*;
import ddf.minim.spi.*; 

Minim minim;
AudioOutput out;
FilePlayer filePlayer; 

Delay myDelay;

void setup() {
  size(100, 100);

  minim = new Minim(this);

  AudioRecordingStream myFile = minim.loadFileStream( "audio1.wav", 1024, true);

  filePlayer = new FilePlayer( myFile );

  filePlayer.play();
  filePlayer.loop();
  out = minim.getLineOut();


  // patch the file player to the output
  filePlayer.patch(out);

  println(filePlayer.length()); //This prints out 2299
}

void draw()
{
  background( 0 );


}
MethDamon
  • 55
  • 11
  • is your wav file 16-bit unsigned 44100 sampled ? – George Profenza Sep 23 '14 at 17:57
  • @George println(filePlayer.sampleRate()); This prints out 44100.0, so im pretty sure about the sample rate. Not sure about the 16-bit unsigned part. – MethDamon Sep 23 '14 at 18:17
  • Can you open your wav file in [Audacity](http://audacity.sourceforge.net/), ?export another wav from there and try the exported wav instead ? Also, what version of Processing and of the Minim library are you using ? – George Profenza Sep 23 '14 at 20:02
  • @GeorgeProfenza I'm using Processing 2.2.1 and the Minim Library I installed directly through Processing 2.2.1. I don't think I'm supposed to do anything to the wav since we were given the file for a homework assignment. – MethDamon Sep 24 '14 at 12:12
  • I see. Do you get different results if you use `minim.loadFile("audio.wav",1024);` instead of `loadFileStream` ? Can you post the audio file somewhere ? – George Profenza Sep 24 '14 at 12:49
  • @GeorgeProfenza According to minim loadFileStream returns an AudioPlayer, which I cannot patch to a delay if I understood correctly – MethDamon Sep 24 '14 at 14:43
  • @GeorgeProfenza The AudioPlayer however plays the file correctly, is there a way to create a delay effect on the AudioPlayer? – MethDamon Sep 24 '14 at 15:55
  • I see what you mean, you're right, can't plug a Delay since AudioPlayer isn't using the UGens framework, so `FilePlayer` is what you need indeed. I've posted an example bellow using a sample sound from Minim and it seems to work (hold the mouse down to disable the huge delay (set it's amp. to 0)). Regarding the given wav file, just a sanity check try a re-export, maybe something went wrong with the file. What course is this for btw ? – George Profenza Sep 26 '14 at 23:24
  • Hi, thanks for your efforts. There is no problem with mp3 files and FilePlayer, it just appears with wav files and not only this one. – MethDamon Oct 01 '14 at 15:58
  • @GeorgeProfenza But I solved the problem with TickRate and a value of 0.25. Thanks alot, though! – MethDamon Oct 01 '14 at 16:08

1 Answers1

0

Try this with your audio file:

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;


Minim minim;
FilePlayer filePlayer;
AudioOutput out;
Delay delay;

void setup(){
 size(640, 240);
 minim = new Minim(this);

 AudioRecordingStream file = minim.loadFileStream( "marcus_kellis_theme.mp3",1024,true); 
 filePlayer = new FilePlayer( file );
 filePlayer.loop(1);//play forever

 delay = new Delay( 0.4, .9, true, true );
 out = minim.getLineOut();
 filePlayer.patch(delay).patch(out);
}
void mousePressed(){
  delay.setDelAmp(0);
}
void mouseReleased(){
  delay.setDelAmp(.9);
}
void draw(){
  background( 0 );
  stroke( 255 );
  beginShape(LINES);
  for( int i = 0; i < out.bufferSize() - 1; i++ ){
    // find the x position of each buffer value
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
    // draw a line from one buffer position to the next for both channels
    vertex( x1, 50 + out.left.get(i)*50);vertex(x2, 50 + out.left.get(i+1)*50);
    vertex( x1, 150 + out.right.get(i)*50);vertex( x2, 150 + out.right.get(i+1)*50);
  } 
  endShape();
}

If it doesn't playback correctly try to open it in Audacity and export it as a 16-bit signed wav.

George Profenza
  • 50,687
  • 19
  • 144
  • 218