Last active
September 25, 2018 12:36
-
-
Save ShigekiKarita/5bc9086fabe15c5dad6b6f35a8421725 to your computer and use it in GitHub Desktop.
D言語でVST/AUプラグイン開発4 (インストルメント自作編) ref: https://qiita.com/ShigekiKarita/items/ef47d792b4aae047b42c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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