sid_library
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| sid_library [2011/09/27 10:06] – created 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 7: | Line 17: | ||
| * Extract files from the library archive to your '' | * Extract files from the library archive to your '' | ||
| + | ==== Usage ==== | ||
| + | |||
| + | You shall first include the library inside its Arduino design by addin a call to the library: | ||
| + | |||
| + | ''# | ||
| + | |||
| + | Then you need to create an instance of the SID type, and initilalise it: | ||
| + | |||
| + | * Create a SID synth by declaring it : '' | ||
| + | * In the Arduino '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * Send bytes to the SID by using '' | ||
| + | |||
| + | Address is the SID address ranging 0-24 as mentionned in the SID datasheet, and the Data is the byte you want to write. See the [[mos6581]] datasheet for more details on how to program the Chip. | ||
| + | |||
| + | ==== Code example ==== | ||
| + | |||
| + | Here is an example of how to use the library, showing how to combine the '' | ||
| + | |||
| + | < | ||
| + | |||
| + | <code C> | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // Pulse width must be less than 0x0FFF (4095) | ||
| + | // note - must also be higher than nothing if using a square wave | ||
| + | // | ||
| + | #define PULSE_WIDTH 0x0 | ||
| + | |||
| + | // These all must be below 0x0F (15) | ||
| + | |||
| + | // | ||
| + | // GLOBAL SYNTH VARIABLES INIT | ||
| + | // | ||
| + | |||
| + | SID sid; | ||
| + | |||
| + | // Play sound at frequency specified on voice specified | ||
| + | // | ||
| + | void synth_on(int note) | ||
| + | { | ||
| + | freq1=NOTES[note]; | ||
| + | sid.send(SID_FREQ1LO, | ||
| + | sid.send(SID_FREQ1HI, | ||
| + | freq2=NOTES[note+3]; | ||
| + | sid.send(SID_FREQ2LO, | ||
| + | sid.send(SID_FREQ2HI, | ||
| + | freq3=NOTES[note+7]; | ||
| + | sid.send(SID_FREQ3LO, | ||
| + | sid.send(SID_FREQ3HI, | ||
| + | ctrl1|=1; | ||
| + | sid.send(SID_CTRL1, | ||
| + | ctrl2|=1; | ||
| + | sid.send(SID_CTRL2, | ||
| + | ctrl3|=1; | ||
| + | sid.send(SID_CTRL3, | ||
| + | } | ||
| + | |||
| + | void synth_off(int note) | ||
| + | { | ||
| + | ctrl1& | ||
| + | sid.send(SID_CTRL1, | ||
| + | ctrl2& | ||
| + | sid.send(SID_CTRL2, | ||
| + | ctrl3& | ||
| + | sid.send(SID_CTRL3, | ||
| + | } | ||
| + | |||
| + | // Debug 2 bytes of data via the address + data shifters | ||
| + | // | ||
| + | |||
| + | // Initially executed code | ||
| + | // | ||
| + | void setup() | ||
| + | { | ||
| + | // Set up the SID chip | ||
| + | sid.clk_setup(); | ||
| + | sid.SPI_setup(); | ||
| + | |||
| + | // Give the voices some initial values | ||
| + | // Set up the MIDI input | ||
| + | MIDI.begin(); | ||
| + | MIDI.setHandleNoteOn(DoHandleNoteOn); | ||
| + | MIDI.setHandleNoteOff(DoHandleNoteOff); | ||
| + | |||
| + | synth_init(); | ||
| - | One shall first include the library inside its design: #include « SID.h » | + | } |
| - | Then create a SID synth by declaring it : SID sid; | + | // Main program loop |
| + | // | ||
| + | void loop() { | ||
| + | MIDI.read(); | ||
| + | } | ||
| - | In the Arduino setup() function, one shall setup successively the clock and the SPI to operate the SID: | + | // Note On Handler |
| - | sid.clk_setup(); | + | // PS : The if / else is implemented because some Midi equipements do not use Note Off, but use instead note On with velocity = 0 |
| - | sid.SPI_setup(); | + | void DoHandleNoteOn |
| + | synth_on(note); | ||
| + | } | ||
| - | You eventually can send bytes to the SID by using sid.send(Address, | ||
| - | Address is the SID address ranging 0-24 as mentionned in the SID datasheet, and the Data is the byte you want to write. | ||
| + | void DoHandleNoteOff (byte channel, byte note, byte velocity) { | ||
| + | synth_off(note); | ||
| + | } | ||
| + | </ | ||
| + | ==== Changelog ==== | ||
| + | See the SID.h file comments for library changelog. | ||
sid_library.1317118003.txt.gz · Last modified: (external edit)
