当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。