Skip to content

Instantly share code, notes, and snippets.

@ShigekiKarita
Last active September 25, 2018 12:36
Show Gist options
  • Select an option

  • Save ShigekiKarita/5bc9086fabe15c5dad6b6f35a8421725 to your computer and use it in GitHub Desktop.

Select an option

Save ShigekiKarita/5bc9086fabe15c5dad6b6f35a8421725 to your computer and use it in GitHub Desktop.
D言語でVST/AUプラグイン開発4 (インストルメント自作編) ref: https://qiita.com/ShigekiKarita/items/ef47d792b4aae047b42c
override void processAudio(const(float*)[] inputs, float*[]outputs, int frames, TimeInfo info)
{
// 処理するmidiイベント(msg)を受け取る
foreach(msg; getNextMidiMessages(frames))
{
if (msg.isNoteOn())
{
_voiceStatus.markNoteOn(msg.noteNumber());
_sampleIndex[msg.noteNumber()] = 0;
}
else if (msg.isNoteOff())
_voiceStatus.markNoteOff(msg.noteNumber());
}
// 音符が鳴っていれば、対応する周波数にリサンプルした波形を書き出す
if (_voiceStatus.isAVoicePlaying)
{
auto note = _voiceStatus.lastNotePlayed;
auto rs = _resampled[note];
foreach(smp; 0..frames)
{
foreach (ch; 0.. outputs.length)
{
auto i = _sampleIndex[note];
outputs[ch][smp] = rs[ch][i % $];
}
++_sampleIndex[note];
}
}
else
{
outputs[0][0..frames] = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment