sid_library
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
sid_library [2011/09/27 11:20] – wadmin | sid_library [2018/08/26 09:36] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | This library | + | ===== SID Library ===== |
+ | The library | ||
+ | Connecting | ||
+ | Schematic, Layout and Source Code of the associated Midi Synth project SIDaster can be found here : http:// | ||
+ | |||
+ | ==== Download ==== | ||
+ | |||
+ | Download Link : {{: | ||
==== Installation ==== | ==== Installation ==== | ||
+ | |||
+ | As simple as an Arduino library installation: | ||
* Go to your '' | * Go to your '' | ||
Line 25: | Line 35: | ||
==== Code example ==== | ==== Code example ==== | ||
- | Here is an example of how to use the library: | + | Here is an example of how to use the library, showing how to combine the '' |
+ | |||
+ | < | ||
<code C> | <code C> | ||
Line 37: | Line 49: | ||
// These all must be below 0x0F (15) | // These all must be below 0x0F (15) | ||
- | |||
- | static const unsigned char BASE_NOTE = 12; | ||
- | static const unsigned int NOTES[] = { | ||
- | 291, 308, 326, 346, 366, 388, 411, 435, 461, 489, 518, 549, | ||
- | 581, 616, 652, 691, 732, 776, 822, 871, 923, 978, 1036, 1097, 1163, 1232, 1305, 1383, 1465, 1552, 1644, | ||
- | 1742, 1845, 1955, 2071, 2195, 2325, 2463, 2610, 2765, 2930, 3104, 3288, 3484, 3691, 3910, 4143, 4650, // 4650 = C4 | ||
- | 4927, 5220, 5530, 5859, 6207, 6577, 6968, 7382, 7821, 8286, 8779, 9301, 9854, 10440, 11060, 11718, 12415, | ||
- | 13153, 13935, 14764, 15642, 16572, 17557, 18601, 19709, 20897, 22121, 23436, 24830, 26306, 27871, 29528, | ||
- | 31234, 33144, 35115, 37203, 39415, 41759, 44242, 46873, 49660, 52613, 55741, 59056, 62567}; | ||
// | // | ||
// GLOBAL SYNTH VARIABLES INIT | // GLOBAL SYNTH VARIABLES INIT | ||
// | // | ||
- | // Coarse Frequency, base 2, value from 0 (-2) to 5 (+2) | ||
- | static byte coarse1 = 0; | ||
- | static byte coarse2 = 0; | ||
- | static byte coarse3 = 0; | ||
- | |||
- | // Default midi channel | ||
- | static byte mchannel = 1; | ||
- | |||
- | // Synth State Managment | ||
- | static boolean trigged = false; // indicating if synth is playing | ||
- | static boolean retrigger = true; // indicating if retriggering ADSR is on | ||
- | |||
- | // Local Osc Frequency | ||
- | // Registers @ B00000 and B00001 | ||
- | // Default 440hz = 0x1CD5 | ||
- | static word freq1 = 0x1CD5; | ||
- | static word freq2 = 0x1CD5; | ||
- | static word freq3 = 0x1CD5; | ||
- | |||
- | // PWM | ||
- | // Default Square Wave = 0x800 | ||
- | // Formula : PWout = (PWn/40.95) % | ||
- | static word pw1 = 0x800; | ||
- | static word pw2 = 0x800; | ||
- | static word pw3 = 0x800; | ||
- | |||
- | // Control Register | ||
- | // Default: Saw | ||
- | // Content NOI|SQR|SAW|TRI|TST|MOD|SYN|GAT | ||
- | static byte ctrl1 = 0X21; | ||
- | static byte ctrl2 = 0X21; | ||
- | static byte ctrl3 = 0X21; | ||
- | |||
- | // Attack and Decay | ||
- | // Default : Shortest | ||
- | static byte ad1 = 0x00; | ||
- | static byte ad2 = 0x00; | ||
- | static byte ad3 = 0x00; | ||
- | |||
- | // Sustain and Release | ||
- | // Default: Max sustain and no release | ||
- | static byte sr1 = 0xF0; | ||
- | static byte sr2 = 0xF0; | ||
- | static byte sr3 = 0xF0; | ||
- | |||
- | // Cutoff Frequency | ||
- | static word freq = 0x7FF; | ||
- | |||
- | // Resonnance and CTRL | ||
- | // Res= 0 no resonnance, Res=F max resonnance | ||
- | // Routing 0 is no filter, 1 is filter | ||
- | // RES(4)|EXT|F3|F2|F1 | ||
- | static byte res = 0x1; | ||
- | |||
- | // Mode | ||
- | // Content EXT|HP|BP|LP|VOL(4) | ||
- | static byte mode = 0x1F; | ||
- | |||
- | // Mono Note Memory | ||
- | static byte last_note = 0; | ||
- | static byte current_note = 0; | ||
- | static byte notes = 0; | ||
- | |||
- | // ######################################################## | ||
SID sid; | SID sid; | ||
- | |||
- | // Give voices some initial params | ||
- | // | ||
- | void synth_init() | ||
- | { | ||
- | // Freq init | ||
- | sid.send(SID_FREQ1LO, | ||
- | sid.send(SID_FREQ1HI, | ||
- | sid.send(SID_FREQ2LO, | ||
- | sid.send(SID_FREQ2HI, | ||
- | sid.send(SID_FREQ3LO, | ||
- | sid.send(SID_FREQ3HI, | ||
- | |||
- | // PWM Init | ||
- | sid.send(SID_PW1LO, | ||
- | sid.send(SID_PW1HI, | ||
- | sid.send(SID_PW2LO, | ||
- | sid.send(SID_PW2HI, | ||
- | sid.send(SID_PW3LO, | ||
- | sid.send(SID_PW3HI, | ||
- | |||
- | // CTRL | ||
- | sid.send(SID_CTRL1, | ||
- | sid.send(SID_CTRL2, | ||
- | sid.send(SID_CTRL3, | ||
- | |||
- | // ADSR | ||
- | sid.send(SID_AD1, | ||
- | sid.send(SID_SR1, | ||
- | sid.send(SID_AD2, | ||
- | sid.send(SID_SR2, | ||
- | sid.send(SID_AD3, | ||
- | sid.send(SID_SR3, | ||
- | |||
- | // Filter + Main | ||
- | sid.send(SID_FCLO, | ||
- | sid.send(SID_FCHI, | ||
- | sid.send(SID_RES, | ||
- | sid.send(SID_MODE, | ||
- | } | ||
// Play sound at frequency specified on voice specified | // Play sound at frequency specified on voice specified | ||
Line 226: | Line 125: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ==== Changelog ==== | ||
+ | See the SID.h file comments for library changelog. |
sid_library.1317122457.txt.gz · Last modified: 2018/08/26 09:36 (external edit)