极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9067|回复: 1

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

[复制链接]
发表于 2014-10-27 19:38:54 | 显示全部楼层 |阅读模式
             http://ansifa.blog.163.com/blog/static/52803100201171423347643/  这个代码要怎么写

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 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 example  AudioRecorder >> RecordAndPlayback for more about that
    recorder.save();
    println("Done saving.");
  }
}
这个minni库实例,可以通过按键“r”,实现有麦克风输入的音频录制,并获得相应文件。至于其他,实在是没有看到这个博客的具体内容(无法打开)。不过通过将按改进这个实例应该可以实现采集,分析音频就很简单了(因为已经录制下了文件)。
不过,如果没猜错的话兄弟是想做一个类似千千静听的播放音乐会产生相应频谱柱状图的小东西吧,如果觉得麻烦有很多相关软件可以下载。。。
但愿可以帮助到你~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-26 00:20 , Processed in 0.049988 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表