當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing AudioSample.rate()用法及代碼示例

Processing, 類AudioSample中的rate()用法介紹。

用法

  • .rate(rate)

參數

  • rate (float) 要使用的相對播放速率。 1是原始速度。 0.5 是一半速度和一個八度音程。 2 是速度的兩倍和一個八度。

返回

  • void

說明

設置音頻樣本的相對播放速率。 1是原始速度。 0.5 是一半速度和一個八度音程。 2 是速度的兩倍和一個八度。

例子

import processing.sound.*;
AudioSample sample;

void setup() {
  size(640, 360);
  background(255);

  // Create an array and manually write a single sine wave oscillation into it.
  int resolution = 1000;
  float[] sinewave = new float[resolution];
  for (int i = 0; i < resolution; i++) {
    sinewave[i] = sin(TWO_PI*i/resolution);
  }

  // Create the audiosample based on the data, set framerate to play 200 oscillations/second
  sample = new AudioSample(this, sinewave, 200 * resolution);

  // Playing the sample at twice its normal playback speed, you will actually
  // hear a 400 Hz sound
  sample.rate(2);
  sample.loop();
}      

void draw() {
}

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 AudioSample.rate()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。