(oscillatorobj).setType

def setup
  @osc = Oscillator.new('sine')
  @osc.start
  @osc.amp(0)
  @playing = false

  sel = createSelect
  sel.position(0, height + 5)
  sel.option(SINE)      # 正弦波
  sel.option(TRIANGLE)  # 三角波
  sel.option(SAWTOOTH)  # のこぎり波
  sel.option(SQUARE)    # 矩形波
  sel.selected(SINE)
  sel.changed do
    @osc.setType(sel.value)
  end
end

def draw
  background(220)
  @freq = constrain(map(mouseX, 0, width, 100, 500), 100, 500);
  @amp = constrain(map(mouseY, height, 0, 0, 1), 0, 1);

  text('Tap to play', 20, 20)
  text("freq: #{@freq}", 20, 50)
  text("amp:  #{@amp}", 20, 70)

  if @playing
    @osc.freq(@freq, 0.1)
    @osc.amp(@amp, 0.1)
  end
end

def mousePressed
  @playing = true
end

def mouseReleased
  @playing = false
  @osc.amp(0, 0.5)
end

p5.jsリファレンス(参考情報)

[p5.js] (p5.Oscillator).setType

概要

信号の波形を設定します。

書式

setType(type)

引数

引数名内容備考オプションデフォルト値
type波形SINE
TRIANGLE
SAWTOOTH
SQUARE
正弦波
三角波
のこぎり波
矩形波

戻値

Oscillatorオブジェクト

備考

関連

(oscillator).new
(oscillatorobj).start
(oscillatorobj).stop
(oscillatorobj).freq
(oscillatorobj).amp
(oscillatorobj).getFreq
(oscillatorobj).getAmp
(oscillatorobj).getType