User Tools

Site Tools


sid_library

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
sid_library [2011/09/27 11:20] wadminsid_library [2018/08/26 09:36] (current) – external edit 127.0.0.1
Line 1: Line 1:
-This library allows the operation of the SIDaster Shield (V2.3+) by specifying setup / communication functions. See the comments inside the library file files for in depth description+===== SID Library ===== 
 +The library provides the setup and communications functions to interface an Arduino board with a [[MOS6581]] Sound Interface Device (SID). 
 +Connecting the Arduino board to the SID is made through the Arduino hadware SPI interface, using 74hc595 deserializers. 
 +Schematic, Layout and Source Code of the associated Midi Synth project SIDaster can be found here : http://bit.ly/SIDaster 
 + 
 +==== Download ==== 
 + 
 +Download Link : {{:sid_lib_v4.zip|}} 
  
 ==== Installation ==== ==== Installation ====
 +
 +As simple as an Arduino library installation:
  
   * Go to your ''Arduino\Library'' subfolder.   * Go to your ''Arduino\Library'' subfolder.
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 ''Midi'' library and the ''SID' library. 
 + 
 +<sub>noteit's a reduced version of a engineering version of the SIDaster, lots of things have been deleted to ease comprehension, however brute force copy paste of this code shall not compile properly under Arduino IDE.</sub>
  
 <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,char(freq1)); 
-  sid.send(SID_FREQ1HI,char(freq1>>8)); 
-  sid.send(SID_FREQ2LO,char(freq2)); 
-  sid.send(SID_FREQ2HI,char(freq2>>8)); 
-  sid.send(SID_FREQ3LO,char(freq3)); 
-  sid.send(SID_FREQ3HI,char(freq3>>8)); 
- 
-  // PWM Init 
-  sid.send(SID_PW1LO,char(pw1)); 
-  sid.send(SID_PW1HI,char(pw1>>8)); 
-  sid.send(SID_PW2LO,char(pw2)); 
-  sid.send(SID_PW2HI,char(pw2>>8)); 
-  sid.send(SID_PW3LO,char(pw3)); 
-  sid.send(SID_PW3HI,char(pw3>>8)); 
- 
-  // CTRL 
-  sid.send(SID_CTRL1,ctrl1); 
-  sid.send(SID_CTRL2,ctrl2); 
-  sid.send(SID_CTRL3,ctrl3); 
- 
-  // ADSR 
-  sid.send(SID_AD1,ad1); 
-  sid.send(SID_SR1,sr1); 
-  sid.send(SID_AD2,ad2); 
-  sid.send(SID_SR2,sr2); 
-  sid.send(SID_AD3,ad3); 
-  sid.send(SID_SR3,sr3); 
- 
-  // Filter + Main 
-  sid.send(SID_FCLO,char(freq)); 
-  sid.send(SID_FCHI,char(freq>>8)); 
-  sid.send(SID_RES,res); 
-  sid.send(SID_MODE,mode); 
-} 
  
 // Play sound at frequency specified on voice specified // Play sound at frequency specified on voice specified
Line 226: Line 125:
 } }
 </code> </code>
 +
 +==== Changelog ====
 +See the SID.h file comments for library changelog.
sid_library.1317122457.txt.gz · Last modified: 2018/08/26 09:36 (external edit)