ATMEGA328を搭載した Arduino Duemilanove 互換機で音をPWM D/A変換出力するシンセサイザーライブラリです。
Revisión | cc32489e4a0059ef890c0432b7a936789851daab (tree) |
---|---|
Tiempo | 2016-04-23 23:45:17 |
Autor | Akiyoshi Kamide <kamide@yk.r...> |
Commiter | Akiyoshi Kamide |
systemReset() による初期化動作が不十分だったのを修正
@@ -1,5 +1,5 @@ | ||
1 | 1 | // |
2 | -// PWM DAC Synthesizer ver.20160419 | |
2 | +// PWM DAC Synthesizer ver.20160423 | |
3 | 3 | // by Akiyoshi Kamide (Twitter: @akiyoshi_kamide) |
4 | 4 | // http://kamide.b.osdn.me/pwmdac_synth_lib/ |
5 | 5 | // https://osdn.jp/users/kamide/pf/PWMDAC_Synth/ |
@@ -97,12 +97,12 @@ class MidiChannel { | ||
97 | 97 | PROGMEM const byte *wavetable; |
98 | 98 | EnvelopeParam envelope; |
99 | 99 | MidiChannel(PROGMEM const Instrument *instrument) { |
100 | - programChange(instrument); | |
101 | - reset(); | |
100 | + reset(instrument); | |
102 | 101 | } |
103 | - void reset() { | |
102 | + void reset(PROGMEM const Instrument *instrument) { | |
104 | 103 | resetAllControllers(); |
105 | 104 | rpns[LSB] = rpns[MSB] = UCHAR_MAX; |
105 | + programChange(instrument); | |
106 | 106 | } |
107 | 107 | double getPitchRate() const { return pitch_rate; } |
108 | 108 | int getPitchBend() const { return pitch_bend; } |
@@ -333,6 +333,7 @@ class PWMDACSynth { | ||
333 | 333 | #endif |
334 | 334 | } |
335 | 335 | #define EACH_VOICE(p) for(VoiceStatus *(p)=voices; (p)<= voices + (PWMDAC_POLYPHONY - 1); (p)++) |
336 | +#define EACH_CHANNEL(c) for(MidiChannel *(c)=channels; (c)<= channels + (NumberOf(channels) - 1); (c)++) | |
336 | 337 | inline static void updatePulseWidth() { |
337 | 338 | unsigned int pw = 0; |
338 | 339 | EACH_VOICE(v) pw += v->nextPulseWidth(); |
@@ -366,7 +367,10 @@ class PWMDACSynth { | ||
366 | 367 | break; |
367 | 368 | } |
368 | 369 | } |
369 | - static void systemReset() { EACH_VOICE(v) v->reset(); } | |
370 | + static void systemReset() { | |
371 | + EACH_VOICE(v) v->reset(); | |
372 | + EACH_CHANNEL(c) c->reset(defaultInstrument); | |
373 | + } | |
370 | 374 | static MidiChannel *getChannel(char channel) { return channels + (channel - 1); } |
371 | 375 | static char getChannel(MidiChannel *cp) { return (cp - channels) + 1; } |
372 | 376 | static byte musicalMod12(char); |
@@ -382,6 +386,7 @@ class PWMDACSynth { | ||
382 | 386 | return note; |
383 | 387 | } |
384 | 388 | protected: |
389 | + static PROGMEM const Instrument * const defaultInstrument; | |
385 | 390 | static MidiChannel channels[16]; |
386 | 391 | static VoiceStatus voices[PWMDAC_POLYPHONY]; |
387 | 392 | static PROGMEM const byte maxVolumeSineWavetable[]; |
@@ -407,5 +412,6 @@ class PWMDACSynth { | ||
407 | 412 | ISR(PWMDAC_OVF_vect) { PWMDACSynth::updatePulseWidth(); } \ |
408 | 413 | VoiceStatus PWMDACSynth::voices[PWMDAC_POLYPHONY]; \ |
409 | 414 | PWMDAC_CREATE_WAVETABLE(PWMDACSynth::maxVolumeSineWavetable, PWMDAC_MAX_VOLUME_SINE_WAVE); \ |
415 | + PROGMEM const Instrument * const PWMDACSynth::defaultInstrument = instrument; \ | |
410 | 416 | MidiChannel PWMDACSynth::channels[16] = MidiChannel(instrument); |
411 | 417 |
@@ -1,7 +1,7 @@ | ||
1 | 1 | |
2 | 2 | [PWMDAC_Synth - PWM DAC synthesizer library for Arduino] |
3 | 3 | |
4 | -ver.20160419 | |
4 | +ver.20160423 | |
5 | 5 | |
6 | 6 | Arduinoで動作する簡易シンセサイザライブラリです。 |
7 | 7 |