読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

minimで色々な波形の音を出す

サウンド

サイン波

f:id:aa_debdeb:20151030140433j:plain
/**
* Sound of Square Wave
*
* @author aa_debdeb
* @date 2015/11/01
*/

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;
AudioOutput out;
SineWave wave;

void setup(){
  size(500, 300);
  minim = new Minim(this);
  out = minim.getLineOut(Minim.MONO);
  wave = new SineWave(440, 1.0, out.sampleRate());
  wave.portamento(200);
  out.addSignal(wave);
}

void draw(){
  background(255);
  stroke(0);
  strokeWeight(1);
  beginShape();
  for(int i = 0; i < out.bufferSize() - 1; i++){
    vertex(i, height/2 + out.right.get(i) * 100);
  }
  endShape();
}

void mouseMoved(){
  float freq = map(mouseX, 0, width, 0, 15000);
  wave.setFreq(freq);
}

void stop(){
  out.close();
  minim.stop();
  super.stop();
}

矩形波

f:id:aa_debdeb:20151030140447j:plain
/**
* Sound of Square Wave
*
* @author aa_debdeb
* @date 2015/11/01
*/

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;
AudioOutput out;
SquareWave wave;

void setup(){
  size(500, 300);
  minim = new Minim(this);
  out = minim.getLineOut(Minim.MONO);
  wave = new SquareWave(440, 1.0, out.sampleRate());
  wave.portamento(200);
  out.addSignal(wave);
}

void draw(){
  background(255);
  stroke(0);
  strokeWeight(1);
  beginShape();
  for(int i = 0; i < out.bufferSize() - 1; i++){
    vertex(i, height/2 + out.right.get(i) * 100);
  }
  endShape();
}

void mouseMoved(){
  float freq = map(mouseX, 0, width, 0, 15000);
  wave.setFreq(freq);
}

void stop(){
  out.close();
  minim.stop();
  super.stop();
}

三角波

f:id:aa_debdeb:20151030140507j:plain
/**
* Sound of Triangle Wave
*
* @author aa_debdeb
* @date 2015/11/01
*/

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;
AudioOutput out;
TriangleWave wave;

void setup(){
  size(500, 300);
  minim = new Minim(this);
  out = minim.getLineOut(Minim.MONO);
  wave = new TriangleWave(440, 1.0, out.sampleRate());
  wave.portamento(200);
  out.addSignal(wave);
}

void draw(){
  background(255);
  stroke(0);
  strokeWeight(1);
  beginShape();
  for(int i = 0; i < out.bufferSize() - 1; i++){
    vertex(i, height/2 + out.right.get(i) * 100);
  }
  endShape();
      if(frameCount == 10){
    saveFrame("images/image.jpg");
  }
}

void mouseMoved(){
  float freq = map(mouseX, 0, width, 0, 15000);
  wave.setFreq(freq);
}

void stop(){
  out.close();
  minim.stop();
  super.stop();
}

のこぎり波

f:id:aa_debdeb:20151030140519j:plain
/**
* Sound of Saw Wave
*
* @author aa_debdeb
* @date 2015/11/01
*/

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;
AudioOutput out;
SawWave wave;

void setup(){
  size(500, 300);
  minim = new Minim(this);
  out = minim.getLineOut(Minim.MONO);
  wave = new SawWave(440, 1.0, out.sampleRate());
  wave.portamento(200);
  out.addSignal(wave);
}

void draw(){
  background(255);
  stroke(0);
  strokeWeight(1);
  beginShape();
  for(int i = 0; i < out.bufferSize() - 1; i++){
    vertex(i, height/2 + out.right.get(i) * 100);
  }
  endShape();
}

void mouseMoved(){
  float freq = map(mouseX, 0, width, 0, 15000);
  wave.setFreq(freq);
}

void stop(){
  out.close();
  minim.stop();
  super.stop();
}

パルス波

f:id:aa_debdeb:20151030140532j:plain
/**
* Sound of Pulse Wave
*
* @author aa_debdeb
* @date 2015/11/01
*/

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;
AudioOutput out;
PulseWave wave;

void setup(){
  size(500, 300);
  minim = new Minim(this);
  out = minim.getLineOut(Minim.MONO);
  wave = new PulseWave(440, 1.0, out.sampleRate());
  wave.portamento(200);
  out.addSignal(wave);
}

void draw(){
  background(255);
  stroke(0);
  strokeWeight(1);
  beginShape();
  for(int i = 0; i < out.bufferSize() - 1; i++){
    vertex(i, height/2 + out.right.get(i) * 100);
  }
  endShape();
}

void mouseMoved(){
  float freq = map(mouseX, 0, width, 0, 15000);
  wave.setFreq(freq);
}

void stop(){
  out.close();
  minim.stop();
  super.stop();
}