Nucleo F401REでFM音源を実装するやつ 外部DACとオペアンプを利用 現在はMCP4922とNJM2737

Dependencies:   AOTTrigon I2CEEPROM MCP4922 AQM0802A mbed

Fork of NuMidi401 by Yuu Kobayashi

NuFM401

Nucleo F401用の自作ソフトウェアMIDI音源

概要

だいたいそんなもんです。

特徴

  • ブレッドボードの上で組める程度には簡単な回路構成
  • 外部のDACにMCP4922を採用
  • 念のためのボルテージフォロアとしてNJM2737Dを採用
  • バンク用EEPROMに24FC1025を採用
  • シリアル経由でMIDIデータを受信することで操作

補足

シリアル <=> MIDI のドライバにはHairless-MIDISerialをオススメします。 仮想MIDIケーブルはとりあえずMIDI Yokeで。

Committer:
kb10uy
Date:
Mon Dec 29 09:01:10 2014 +0000
Revision:
10:0ffdefe75566
Parent:
9:12a54d2ea8fc
Child:
12:7408b85fba39
MIDI?????USBMIDI????Serial????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kb10uy 7:439c57c20593 1 #include "Operator.h"
kb10uy 7:439c57c20593 2
kb10uy 7:439c57c20593 3 static const float pi2 = 6.283185307179586476925286766559f;
kb10uy 7:439c57c20593 4
kb10uy 10:0ffdefe75566 5 FMOperator::FMOperator()
kb10uy 10:0ffdefe75566 6 {
kb10uy 10:0ffdefe75566 7 attack = 0.0f;
kb10uy 10:0ffdefe75566 8 delay = 0.0f;
kb10uy 10:0ffdefe75566 9 sustain = 0.0f;
kb10uy 10:0ffdefe75566 10 sustainRate = 1.0f;
kb10uy 10:0ffdefe75566 11 release = 0.0f;
kb10uy 10:0ffdefe75566 12
kb10uy 10:0ffdefe75566 13 frequencyMultiple = 1.0f;
kb10uy 10:0ffdefe75566 14 totalLevel = 1.0f;
kb10uy 10:0ffdefe75566 15
kb10uy 10:0ffdefe75566 16 startTime = 0.0;
kb10uy 10:0ffdefe75566 17 releaseTime = 0.0;
kb10uy 10:0ffdefe75566 18 baseFrequency = 1.0f;
kb10uy 10:0ffdefe75566 19 }
kb10uy 10:0ffdefe75566 20
kb10uy 9:12a54d2ea8fc 21 FMOperator::FMOperator(Timer *tm, AOTTrigon *t)
kb10uy 7:439c57c20593 22 {
kb10uy 7:439c57c20593 23 attack = 0.0f;
kb10uy 7:439c57c20593 24 delay = 0.0f;
kb10uy 7:439c57c20593 25 sustain = 0.0f;
kb10uy 7:439c57c20593 26 sustainRate = 1.0f;
kb10uy 7:439c57c20593 27 release = 0.0f;
kb10uy 7:439c57c20593 28
kb10uy 7:439c57c20593 29 frequencyMultiple = 1.0f;
kb10uy 7:439c57c20593 30 totalLevel = 1.0f;
kb10uy 7:439c57c20593 31
kb10uy 9:12a54d2ea8fc 32 tri = t;
kb10uy 7:439c57c20593 33 master = tm;
kb10uy 7:439c57c20593 34 startTime = 0.0;
kb10uy 7:439c57c20593 35 releaseTime = 0.0;
kb10uy 7:439c57c20593 36 baseFrequency = 1.0f;
kb10uy 7:439c57c20593 37 }
kb10uy 7:439c57c20593 38
kb10uy 7:439c57c20593 39 float FMOperator::calculate(float fmIn) {
kb10uy 7:439c57c20593 40 if (startTime == 0.0) return 0.0f;
kb10uy 7:439c57c20593 41 float pos = (pi2 * baseFrequency * frequencyMultiple);
kb10uy 9:12a54d2ea8fc 42 double nt = (master->read_us() / 1000000.0) - startTime;
kb10uy 9:12a54d2ea8fc 43 return tri->sin(fmIn + (float)(pos * nt));
kb10uy 7:439c57c20593 44 }
kb10uy 7:439c57c20593 45
kb10uy 7:439c57c20593 46 void FMOperator::attackNote(float freq) {
kb10uy 7:439c57c20593 47 baseFrequency = freq;
kb10uy 9:12a54d2ea8fc 48 startTime = master->read_us() / 1000000.0;
kb10uy 7:439c57c20593 49 }
kb10uy 7:439c57c20593 50
kb10uy 7:439c57c20593 51 void FMOperator::releaseNote() {
kb10uy 7:439c57c20593 52 startTime = 0.0;
kb10uy 9:12a54d2ea8fc 53 releaseTime = master->read_us() / 1000000.0;
kb10uy 7:439c57c20593 54 }