0

我正在尝试使用处理和最小库将 wav 文件加载到 FilePlayer 中(稍后我想在其上修补延迟)。但是,我收到的 wav 文件播放速度太快,至少是预期速度的两倍,而且音调非常高。如果我在 VLC 媒体播放器或 WMP 中播放,该文件听起来应该是这样。比特率为 20kbps 时长 5 秒,但代码打印出它长 2299 毫秒。

代码:

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 );


}
4

1 回答 1

0

用你的音频文件试试这个:

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();
}

如果它不能正确播放,请尝试在 Audacity 中打开它并将其导出为 16 位签名 wav。

于 2014-09-26T23:24:35.903 回答