小刘 发表于 2014-10-27 19:38:54

有没有知道这个processing程序要怎么写

             http://ansifa.blog.163.com/blog/static/52803100201171423347643/这个代码要怎么写

linkong 发表于 2014-10-27 21:17:35

import ddf.minim.*;

Minim minim;
AudioInput in;
AudioRecorder recorder;

void setup()
{
size(512, 200, P3D);

minim = new Minim(this);

in = minim.getLineIn();
// create a recorder that will record from the input to the filename specified
// the file will be located in the sketch's root folder.
recorder = minim.createRecorder(in, "myrecording.wav");

textFont(createFont("Arial", 12));
}

void draw()
{
background(0);
stroke(255);
// draw the waveforms
// the values returned by left.get() and right.get() will be between -1 and 1,
// so we need to scale them up to see the waveform
for(int i = 0; i < in.bufferSize() - 1; i++)
{
    line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
    line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
}

if ( recorder.isRecording() )
{
    text("Currently recording...", 5, 15);
}
else
{
    text("Not recording.", 5, 15);
}
}

void keyReleased()
{
if ( key == 'r' )
{
    // to indicate that you want to start or stop capturing audio data, you must call
    // beginRecord() and endRecord() on the AudioRecorder object. You can start and stop
    // as many times as you like, the audio data will be appended to the end of the buffer
    // (in the case of buffered recording) or to the end of the file (in the case of streamed recording).
    if ( recorder.isRecording() )
    {
      recorder.endRecord();
    }
    else
    {
      recorder.beginRecord();
    }
}
if ( key == 's' )
{
    // we've filled the file out buffer,
    // now write it to the file we specified in createRecorder
    // in the case of buffered recording, if the buffer is large,
    // this will appear to freeze the sketch for sometime
    // in the case of streamed recording,
    // it will not freeze as the data is already in the file and all that is being done
    // is closing the file.
    // the method returns the recorded audio as an AudioRecording,
    // see the exampleAudioRecorder >> RecordAndPlayback for more about that
    recorder.save();
    println("Done saving.");
}
}
这个minni库实例,可以通过按键“r”,实现有麦克风输入的音频录制,并获得相应文件。至于其他,实在是没有看到这个博客的具体内容(无法打开)。不过通过将按改进这个实例应该可以实现采集,分析音频就很简单了(因为已经录制下了文件)。
不过,如果没猜错的话兄弟是想做一个类似千千静听的播放音乐会产生相应频谱柱状图的小东西吧,如果觉得麻烦有很多相关软件可以下载。。。
但愿可以帮助到你~
页: [1]
查看完整版本: 有没有知道这个processing程序要怎么写