Skip to content

Instantly share code, notes, and snippets.

@ShigekiKarita
Last active September 23, 2018 04:04
Show Gist options
  • Select an option

  • Save ShigekiKarita/7f159fd9d40c7868f2d92bbae1681d0d to your computer and use it in GitHub Desktop.

Select an option

Save ShigekiKarita/7f159fd9d40c7868f2d92bbae1681d0d to your computer and use it in GitHub Desktop.
D言語でVST/AUプラグイン開発2 (エフェクト自作) ref: https://qiita.com/ShigekiKarita/items/9b3aa8f716848278ef62
override void reset(double sampleRate, int maxFrames, int numInputs, int numOutputs) nothrow @nogc
{
// DAW側でsampleRateが変更されたときに呼ばれる?
if (this._sampleRate != sampleRate)
{
// 処理用のsampleRateを変更
this._sampleRate = sampleRate;
// RingBufferのサイズも変更
this._buffer[0] = RingBuffer!float(this.maxDelayTimeFrame);
this._buffer[1] = RingBuffer!float(this.maxDelayTimeFrame);
// 新しいsampleRateにおけるUI上のdelayTimeをRingBufferに反映
this.resetInterval();
}
}
module ringbuffer;
struct RingBuffer(T)
{
...
}
unittest
{
auto buf = RingBuffer!float(3);
assert(buf[] == [0.0, 0.0, 0.0]);
buf.setInterval(2);
assert(buf.readIndex == 0);
assert(buf.writeIndex == 2);
assert(buf.front == 0);
buf.pushBack(1.0);
buf.pushBack(2.0);
buf.pushBack(3.0);
assert(buf[] == [2.0, 3.0, 1.0]);
}
module main;
import dplug.core, dplug.client, dplug.vst;
version (unittest)
{}
else
{
// This create the DLL entry point
mixin(DLLEntryPoint!());
// This create the VST entry point
mixin(VSTEntryPoint!SimpleDelay);
}
// 悪い例, 左右がズレて聞こえる
override void processAudio(const(float*)[] inputs, float*[]outputs, int frames, TimeInfo info) nothrow @nogc
{
foreach (ch; 0..2)
foreach (t; 0 .. frames)
...
// 良い例,左右のズレはなさそう
override void processAudio(const(float*)[] inputs, float*[]outputs, int frames, TimeInfo info) nothrow @nogc
{
foreach (t; 0 .. frames)
foreach (ch; 0..2)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment