Wave Table Synthesizer(Occilator only). I will make Envelope Generator and MML for play music.
Project: Synthesizer. It is using embed to Chip Tune Synthesizer for NXP LPC1768.
At First
Prepare an amplifier with volume wheel. The amplifier wire at pin1 to pin18(D/A converter) from IC Clip or Breedboard.
Play
Check out this project and deploy your mbed. And then push the reset key.
You hear a sound from amplifier.
Modify
First step, you can see main.cpp. This source file plays an occilator with "wait()". Modify frequency at
#define ADD 0x2000000
on the top of source.
Occilator select 7 waveforms.
- OCC_NONE,
- OCC_SQUARE,
- OCC_SINE,
- OCC_SAW,
- OCC_WT,
- OCC_NOISE,
- OCC_TRIANGLE,
WT means WaveTable Synthesizer.Use "setWave()" function at first.Wavetable will copy in instance.
Change there for waveform.
gOccilator[0]=Occilator::getInstance(OCC_SAW,INTERRUPT_TIME_US);
INTERRUPT_TIME_US depends sampling rate. Don't change.
Total volume of D/A converter is setting this place.
gOccilator[0]->setVolume(volume);
By the way, this sample output 0 to 1V(not3.3V) for deforming distortion.
ToDo
- Envelope generator and LFO(with delay)
- MML(Music Macro Language)
- Sample Song(I will make a Japanese Anime music,perhaps)
Project Goal Date
I will make for Comic Market 90(2016.Aug. in Tokyo).And these thing will be written in a Doujinshi.
Occilator.h@8:dd2da7c0c4c7, 2016-02-09 (annotated)
- Committer:
- 117Florian
- Date:
- Tue Feb 09 05:39:46 2016 +0000
- Revision:
- 8:dd2da7c0c4c7
- Parent:
- 5:3a753cf68fac
- Child:
- 9:d2a5406650ae
Noise,Saw,Sine????WT????????????Sine????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
117Florian | 3:32094530d55e | 1 | #ifndef _OCCILATOR_H_INCL |
117Florian | 3:32094530d55e | 2 | #define _OCCILATOR_H_INCL |
117Florian | 3:32094530d55e | 3 | |
117Florian | 3:32094530d55e | 4 | #define OCCILATOR_PART_NUM 64 |
117Florian | 3:32094530d55e | 5 | |
117Florian | 4:2febde858269 | 6 | enum Occilator_Type |
117Florian | 4:2febde858269 | 7 | { |
117Florian | 4:2febde858269 | 8 | OCC_NONE, |
117Florian | 4:2febde858269 | 9 | OCC_SQUARE, |
117Florian | 4:2febde858269 | 10 | OCC_SINE, |
117Florian | 8:dd2da7c0c4c7 | 11 | OCC_SAW, |
117Florian | 4:2febde858269 | 12 | OCC_WT, |
117Florian | 4:2febde858269 | 13 | OCC_NOISE, |
117Florian | 4:2febde858269 | 14 | }; |
117Florian | 4:2febde858269 | 15 | |
117Florian | 3:32094530d55e | 16 | class Occilator |
117Florian | 3:32094530d55e | 17 | { |
117Florian | 3:32094530d55e | 18 | public: |
117Florian | 4:2febde858269 | 19 | |
117Florian | 4:2febde858269 | 20 | static Occilator* getInstance(Occilator_Type type,long interrupt_us); |
117Florian | 4:2febde858269 | 21 | |
117Florian | 3:32094530d55e | 22 | |
117Florian | 3:32094530d55e | 23 | /** |
117Florian | 3:32094530d55e | 24 | * Destructor |
117Florian | 3:32094530d55e | 25 | * this destructor anatach the interval timer automatically. |
117Florian | 3:32094530d55e | 26 | */ |
117Florian | 3:32094530d55e | 27 | ~Occilator(); |
117Florian | 3:32094530d55e | 28 | |
117Florian | 3:32094530d55e | 29 | /** |
117Florian | 3:32094530d55e | 30 | * Set angle speed(0x100000000 per 1 round) |
117Florian | 3:32094530d55e | 31 | * frequency is depend on interrupt_us |
117Florian | 3:32094530d55e | 32 | */ |
117Florian | 3:32094530d55e | 33 | void setOmega(long speed); |
117Florian | 3:32094530d55e | 34 | |
117Florian | 3:32094530d55e | 35 | /** |
117Florian | 3:32094530d55e | 36 | * Set volume(0x10000 max volume) |
117Florian | 3:32094530d55e | 37 | * @param volume |
117Florian | 3:32094530d55e | 38 | */ |
117Florian | 3:32094530d55e | 39 | void setVolume(int volume); |
117Florian | 3:32094530d55e | 40 | |
117Florian | 3:32094530d55e | 41 | /** |
117Florian | 3:32094530d55e | 42 | * advance the Angle and caliculate value this span. |
117Florian | 3:32094530d55e | 43 | * it was called by automatically from interval timer. |
117Florian | 3:32094530d55e | 44 | * @return value on this tick(max 0xffff0000) |
117Florian | 3:32094530d55e | 45 | */ |
117Florian | 3:32094530d55e | 46 | virtual unsigned long tick(); |
117Florian | 3:32094530d55e | 47 | |
117Florian | 3:32094530d55e | 48 | long m_Angle; |
117Florian | 3:32094530d55e | 49 | long m_Omega; |
117Florian | 3:32094530d55e | 50 | int m_Volume; |
117Florian | 4:2febde858269 | 51 | |
117Florian | 5:3a753cf68fac | 52 | /** |
117Florian | 5:3a753cf68fac | 53 | * Volume for All Channel. |
117Florian | 5:3a753cf68fac | 54 | * It needs adjust output Voltage(3.3V->1V). |
117Florian | 5:3a753cf68fac | 55 | * Also this volume don't change. |
117Florian | 5:3a753cf68fac | 56 | */ |
117Florian | 5:3a753cf68fac | 57 | static void setMasterVolume(long volume); |
117Florian | 5:3a753cf68fac | 58 | |
117Florian | 4:2febde858269 | 59 | protected: |
117Florian | 4:2febde858269 | 60 | /** |
117Florian | 4:2febde858269 | 61 | * Constructor(only) |
117Florian | 4:2febde858269 | 62 | * to construct after mbed has started. |
117Florian | 4:2febde858269 | 63 | * this constructor handles interval timer automatically. |
117Florian | 4:2febde858269 | 64 | * @value interrupt_us interrupt span (micro second). it work at first time only. |
117Florian | 4:2febde858269 | 65 | */ |
117Florian | 4:2febde858269 | 66 | Occilator(long interrupt_us); |
117Florian | 3:32094530d55e | 67 | }; |
117Florian | 3:32094530d55e | 68 | #endif |