Omnimaga

General Discussion => Technology and Development => Other => Topic started by: Keoni29 on January 14, 2013, 01:20:26 pm

Title: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 14, 2013, 01:20:26 pm


I finally made this! It's a breadboard arduino running a sid emulator and a link protocol. You can write to registers in the emulated SID chip. It's very user friendly. Now it's possible to have ingame music and soundeffects without terrible framerate drops.

I need to clean up the source, so that's up for download tomorrow.

Spoiler For Spoiler:
Code: [Select]
#include <SID.h>

#define SOUND 1
#define MIDI 0

// MACROs
#define PIN2H (PIND & 0B00000100)
#define PIN3L !(PIND & 0B00001000)

#define CLR(x,y) (x&=(~(1<<y)))
#define SET(x,y) (x|=(1<<y))

SID mySid;

void setup()
{
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  mySid.begin();
}

int n=0;
int timer=0;
int count=0;
int dcount=0;
byte get=B00000000;
int addrval[3] = {0,0,0};


    #define CHANNEL1  0
    #define CHANNEL2  7
    #define CHANNEL3  14


void loop()
{
  do{
    do
    {
      if (PIN3L)
      {
        if (PIN2H)
        {
          CLR(get,count);
        }
        else
        {
          SET(get,count);
        }
        count++;
        
        while(PIN3L)
        {
        timer++;
          if (timer==500){
            n=count=0;
            break;
          }
        }
        timer=0;
      }
    }while(count!=8);
    addrval[n]=get;
    n++;
    count=0;
  }while(n!=2);

  mySid.set_register(addrval[0], addrval[1]);
  n=0;
}


(http://img.removedfromgame.com/imgs/2013-01-15%2015.03.59.jpg)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Lionel Debroux on January 14, 2013, 02:01:58 pm
Nifty ;)

Relayed to the French community: http://tiplanet.org/forum/viewtopic.php?t=11111
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 14, 2013, 02:05:14 pm
Thank you for translating :)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Lionel Debroux on January 14, 2013, 02:12:44 pm
You're welcome ;)
The posts will be updated on the TI-Planet side when you have posted the source code, the binaries, breadboard schematics, and whatever else.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 14, 2013, 02:14:27 pm
The breadboard schematic is just a breadboarded arduino. You can use a stock arduino and hook up pin 9 to a set of speakers or headphones.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on January 14, 2013, 03:54:19 pm
It's a quite nice idea, i like it! I would suggest you find (make) a small-pcb board + perhaps a phone loudspeaker, so that it would be possible to sorta of glue it to the calculator's back, making more portable. Just an idea. :)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 14, 2013, 04:09:50 pm
Ninja'd you. I already made it :D
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: TIfanx1999 on January 14, 2013, 10:55:26 pm
Pretty cool Keoni! ^^
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Sorunome on January 14, 2013, 11:15:51 pm
Nice! Now just build it INSIDE of a calculator :P
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Ranman on January 15, 2013, 02:14:26 am
Awesome work!

There is as special place in my heart for the C64 and its SID chip!
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 15, 2013, 04:56:37 am
Nice! Now just build it INSIDE of a calculator
That's the next step. First I want to make sure it's flawless. I will also add the original midi out code to the chip. This project was based around the code of my midi interface.

Edit: The midi feature is now implemented. I can now send midi messages as long as they are 3 bytes in size. With a jumper setting I can set the soundchip to SID or MIDI mode.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Ranman on January 15, 2013, 08:34:58 am
Could you fit the entire assembly in a box this size: 1.250" L x 1.900" W x 0.500" H (31.75mm x 48.26mm x 12.70mm)?

http://www.digikey.com/product-detail/en/C2,BK/SCR2B-ND/1992143 (http://www.digikey.com/product-detail/en/C2,BK/SCR2B-ND/1992143)


Here is another good size:

http://www.digikey.com/scripts/dksearch/dksus.dll?FV=fff40021%2Cfff803a6&k=boxes%2C+enclosures%2C+racks&vendor=0&mnonly=0&newproducts=0&ptm=0&fid=0&quantity=0&PV329=899 (http://www.digikey.com/scripts/dksearch/dksus.dll?FV=fff40021%2Cfff803a6&k=boxes%2C+enclosures%2C+racks&vendor=0&mnonly=0&newproducts=0&ptm=0&fid=0&quantity=0&PV329=899)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on January 15, 2013, 10:09:40 am
Ninja'd you. I already made it :D
You should show it off then to give it a bit of spice...
Can you do the same trick to ti-nspire?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 15, 2013, 10:49:08 am
I do not own a nspire, but if it has two I/O lines to work with I can easily implement it. I just shift out the data from the calculator with one data line and one clock line.

Without the midi function. Old picture, but shows the size of the board
(http://img.removedfromgame.com/imgs/2013-01-14%2022.31.02.jpg)

With the midi connector and an on/off switch. It runs off the calculators batteries. An atmega MCU runs fine on 4v-5v, but 6v will damage it. I added a diode to lower the voltage a bit.
(http://img.removedfromgame.com/imgs/2013-01-15%2015.03.59.jpg)

There you have it! It's almost what I had in mind for my profile essay: TI-nterface. I can still add code for GPIO (changing the state of the I/O pins).

Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Nick on January 15, 2013, 12:25:39 pm
How long does it take to send such a command to the chip?
it looks great, and sounds even better :)

And sure you have to add gpio support, it's a wast of pins if you don't do so, or use an ATtiny45 or something equivalent. Those are arduino compatible, and are about a third of the size of the atmega328p.

It looks like that midi port is big to get it into a box, how are you gonna solve that? keep it outside?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 15, 2013, 01:12:03 pm
The attiny45 does not have enough program memory and I don't know if it will compile for the attiny since it outputs the sound on pin 9 by default. Maybe you can change this in the library headers, but I doubt it's gonna compile for the attiny that easily. This sketch as it is takes up 5k. So that won't fit in 4K of program space the attiny45 has. (I only have that kind) The attiny85 on the other hand will hold up to 8k of program data.

The midi port fits in a box just fine. It depends on the size and shape of the box. My idea with the TI-nterface was to have a big plastic enclosure that slides over the top of the calculator. A midi connector on top would be no problem.

Also: I have to come up with a cool name:
TIMID (TI+MIDI+SID)
Zound80
*insert more idea's here*


Edit: Mockup for a music editor. Just a concept. Don't get too excited :P
(http://img.removedfromgame.com/imgs/music%20mockup.png)

I posted the source code for the link protocol on cemetech:
http://www.cemetech.net/forum/viewtopic.php?t=8685&sid=e532c97cb52c8e4552e4721f6461870d
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: TIfanx1999 on January 15, 2013, 04:50:55 pm
Mockup looks very nice. ^^
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 16, 2013, 02:22:49 am
At the moment the speed of the byte transfer is about 110B/sec on normal and 250B/sec on full. I had to add a total delay of pause 3 to get this to work, so perhaps with some optimization on the arduino end I can reduce this delay. To do simple notes you only have to write 3 bytes (plus one to stop the note) 2 bytes for pitch and one for gate/control. That's 27ms per note on normal. I might add "glide" effects to the arduino code to compensate for this slow transfer.

Oops. Multiply that by two since you have to write the address as well, so that makes 6 bytes per note and 54ms/note.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Ranman on January 16, 2013, 02:33:16 am
Also: I have to come up with a cool name:
TIMID (TI+MIDI+SID)
Zound80
*insert more idea's here*

How about Zid80?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on January 16, 2013, 10:22:37 am
Also: I have to come up with a cool name:
TIMID (TI+MIDI+SID)
Zound80
*insert more idea's here*
How about Zid80?
KSidM8z
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 16, 2013, 01:16:20 pm
I made a poll.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Lionel Debroux on January 16, 2013, 01:34:00 pm
Isn't "KSidM8z" somewhat of a mouthful, both hard to pronounce and hard to type ?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Nick on January 16, 2013, 01:45:24 pm
How about Tiscid? That sounds nice (sounds like biscuit), and is easy to type.
It's also an acronym: Texas Instruments Sound Chip Interface Device
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 16, 2013, 01:54:09 pm
Hmmm perhaps I should not include texas instruments. They are not in the credits list.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: ben_g on January 16, 2013, 02:59:56 pm
How exactly does it work? You just send a song or effect to it and make it play the song? Can it 'stream' as in starting to play the song while it's still sending? Is it also possible to send a song AND a few effects at the same time so you won't have to transfer notes during gameplay, only instructions?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 16, 2013, 03:09:05 pm
Nope you have to send register addresses and register values.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on January 16, 2013, 03:11:15 pm
So this is a MIDI interface for the TI84?

How to load soundfonts is the question...
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 16, 2013, 03:12:38 pm
You cannot. Not with the code that's on it at the moment. I could add that some day.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on January 16, 2013, 03:15:17 pm
Use a good soundfont to begin with because once the novelty wears off, people are going to want to USE this often IF the soundfont is epic.

My music sounded so much better after I ditched finale's default.

Edit: I mean, I WILL use this if it has a really cool soundfont :)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 16, 2013, 06:01:07 pm
I started working on a music editor. It will export files that can be played back in a game for example. Just include a file with the subroutines to play back the songs.
I can now edit notes while the calc  plays pattern  loops at the same time.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Spenceboy98 on January 16, 2013, 06:09:29 pm
This is a great project. Keep up the good work! :)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: DJ Omnimaga on January 16, 2013, 07:03:21 pm
This is very cool. :D
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 18, 2013, 09:50:14 am
I am tweaking the link protocol. Now I get speeds up to 380B/sec on normal.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on January 18, 2013, 10:25:17 am
That's already good enough, considering most of the music work is done in paralell by the SID slave.
Imho, you should also speed up the "pcb + enclosure" business to 'sell' it faster.
More: http://playground.arduino.cc/Main/SID-emulator
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 18, 2013, 10:27:22 am
Imho, you should also speed up the "pcb + enclosure" business to 'sell' it faster.
More: http://playground.arduino.cc/Main/SID-emulator

What do you mean by that?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on January 18, 2013, 10:29:59 am
Imho, you should also speed up the "pcb + enclosure" business to 'sell' it faster.
What do you mean by that?
i simply mean, the project final stages are always the hardest part to accomplish. that's all. :D
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 18, 2013, 10:37:52 am
I'm not going to rush this.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on January 18, 2013, 10:40:02 am
fair enough. i can understand it. no problem. but please do not not put it aside 'cos it's really good, you should now that.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 18, 2013, 10:42:08 am
Wow that doesn't mean that I will not be working on this an awful lot :P I'm just taking my time to do lots of optimization :D When I say I'm not gonna rush a full release it definitely doesn't mean I will put it aside :P

Edit: Like for smilies instead of dots 8)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 18, 2013, 12:47:38 pm
I tried to optimize the arduino code, but it's not getting an awful lot faster since my first optimization.
Code: [Select]
#include <SID.h>

// MACROs
#define PIN2H (PIND & 0B00000100)
#define PIN3L !(PIND & 0B00001000)
#define CLR(x,y) (x&=(~(1<<y)))
#define SET(x,y) (x|=(1<<y))

SID mySid;

void setup()
{
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  mySid.begin();
}

byte n=0;
int timer=0;
byte count=0;
byte get=B00000000;
int addrval[2] = {0};

void loop()
{
  do{
    do
    {
      if (PIN3L)          // If the clock pin is LOW
      {
        if (PIN2H)        // And the data pin is HIGH
        {
          CLR(get,count); // CLEAR BIT
        }
        else              // otherwise
        {
          SET(get,count); // SET BIT
        }
        count++;          // Increase the bit counter
       
        while(PIN3L)      // Wait until the clock pin goes HIGH again
        {
        timer++;          // Increase the timeout timer
          if (timer==500){// Timeout at 500 loops
            n=count=0;    // Reset counters
            break;        // Break free
          }
        }
        timer=0;          // Reset the timeout timer
      }
    }while(count!=8);     // Loop again when the bit counter has not reached 8 bits yet
    addrval[n]=get;       // Otherwise store the received byte in an array in cell n
    n++;                  // Increase the byte counter
    count=0;              // Reset the bit counter
  }while(n!=2);           // Loop again when the byte counter has not reached two bytes yet
                          // Otherwise write the value to the register.
  mySid.set_register(addrval[0], addrval[1]);
  n=0;                    // Reset the byte counter
}
Can someone tell me what to optimize?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on January 18, 2013, 01:13:17 pm
I tried to optimize the arduino code, but it's not getting an awful lot faster since my first optimization.
....
Well, i do not have the whole program picture, so it is not very easy to comment. However, i do see you are polling some bit (PIN3L), what is bound to be always slow. Can't you use interrupts instead, saving cpu cycles to do other things? http://www.cab.u-szeged.hu/linux/doc/khg/node19.html
My two cents.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 18, 2013, 01:43:42 pm
I already use timer interrupts for the sid emulation library. Can I use these in parallel?

Edit: I watched the signal on the scope. The bits take 270 microseconds each to send with the current code on my calculator. When I decrease the delays in the calculator code the arduino cannot keep up with it anymore and I just hear scrambled sounds every now and then.

To send 3kB at this rate it takes about 7 seconds, so that is around 420B/sec.
I think this is as good as it gets. I will just optimize the send protocol for playing music and I write another one optimized for soundeffects. I do not want any visible slowdowns during games, so that's my goal.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on January 18, 2013, 02:26:32 pm
I already use timer interrupts for the sid emulation library. Can I use these in parallel?
Yes, as long as you take care of the relative synchronization. It can be a bit more awkward to program, though.

Quote from: Keoni29
.. I watched the signal on the scope.
If you have available spare output bits, you can also use the scope to 'debug' the program.

Anyway, as long as you are happy with the sound, i wouldn't put much more effort into it, at this stage.

Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 20, 2013, 09:32:15 am
I want to make a piano roll style music editor or a tracker to make music with. I also need a file format that works. My old TRAXE tracker format does not cut it. Suggestions?
http://ourl.ca/18194
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: MGOS on January 20, 2013, 09:52:20 am
That's my piano roll music editor and player I made a while ago. It uses the Freq() function of axe, so the quality is pretty bad but it works quite well though.

http://ourl.ca/14703
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 20, 2013, 10:39:18 am
Cool stuff. That's exactely what I had in mind. Can I have the source so I can modify it to work with my soundchip and perhaps have multiple channels?

Edit:
I want to add "hardware" pitch bending with different modes such as LFO, portamento and sweep. The sound processor will also have a lookuptable with musical notes' pitch values. If you write to one of the three dedicated "musical note" registers it will relay it to the freq-hi and lo registers and it will turn on the gate of the channel. This saves a lot of memory and time on the calculator side!

Example:
Calculator sends a NOTE ON normally:
Code: [Select]
00 ff - write ff (0-255) to register 00 (Freq Lo)
01 ff - write ff (0-255) to register 01 (Freq Hi)
04 17 - write TRIANGLE|GATE_ON to register 04 (Conrol reg)
That's 6 bytes!

Calculator sends a NOTE ON with this new feature:
Code: [Select]
1D nn - write nn(0-255) to register 29That's only two bytes!
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 21, 2013, 05:06:35 pm
More footage!

Title: Re: TI84+ soundchip - arduino SID emulator
Post by: TIfanx1999 on January 21, 2013, 09:15:31 pm
Very nice! ^^ How many channels are you planning on supporting?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 22, 2013, 02:44:40 am
It's a SID, so that's 3. All channels are fully customizable as opposed to the soundchip found in the nes which has channels dedicated to a certain waveform.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Nick on January 22, 2013, 08:32:59 am
Wooo, great song :) Maybe you could write a convertor yourself? Would it be that hard to make one?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 22, 2013, 09:17:15 am
I am not that good at programming for the pc and I don't know what the file format of the famitracker modules looks like.
I could write some calculator software instead or alter someones existing software to work with this (TRAXE for example)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on January 22, 2013, 09:43:53 am
I am not that good at programming for the pc and....
Hum, I bet that with your Axe knowledge, if you start up with a "c-language cheap tutorial", within a couple of hours you'll have your converter just about ready. But, i'm just guessing, of course.. Fine work, btw.


Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 22, 2013, 09:51:36 am
I can program in C just fine, but I never really did something with handling files.

Edit: I'm probably gonna make another tracker from scratch, but this time playing and timing notes will be much easier. It will probably not use all of the features of the soundchip such as filters, modulation, etc. but it will be quite powerful and easy to use (I hope)

A mockup of the instrument editor:
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 02, 2013, 11:40:10 am
I did some more programming on the pc. I just have to find a chiptune tracker that outputs a somewhat interpretable stream of data so I can easily convert it with my program. (or make my own tracker using C)

Another interesting thing: I have plenty of I/O pins left on the atmega328 (I only use 4 at the moment) and I have a touchscreen I grabbed out of a broken nintendo DS. In my avatar you can see what that will look like and some people might have seen the video on my youtube channel (http://youtube.com/keoni29). I know someone already did this. I might use his code or stick to my own protocol I use to send data to AXE programs (that's way quicker than transferring data packages using the BASIC link protocol)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: utz on March 03, 2013, 11:45:32 am
Just found out about this... Wow, this is amazing. Will be following developement closely from now on ;)

As far as trackers go, this (http://irrlichtproject.de/downloads/cheabop.tar.gz) might be interesting for you. Never mind the PC speaker part (it's total shit anyway), but the XM converter part could be relevant. Sadly I just hacked somebody's code for it, I don't really understand it.

If you need to generate actual SID register writes, you might also want to check out Goattracker (http://sourceforge.net/projects/goattracker2/), if you haven't already.

Btw if you have time you should present your project on chipmusic.org (http://www.chipmusic.org)!
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 03, 2013, 02:22:39 pm
I just did :)

The source of that tracker suggests it's for linux. I think I can build a tracker from the ground up.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: utz on March 04, 2013, 09:19:04 am
The sources are for the eXtended Module format, which is a standard format used across many PCM trackers running on various platforms, the most popular example being Milkytracker (http://milkytracker.org/). Writing an XM to TIMID converter might be a good idea, since many chip musicians already know how to use XM trackers. On the other hand, I'd never say no to a new tracker xD
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 04, 2013, 01:30:11 pm
I'd like to be able to convert PSID to TIMID. That way I can open up a huge library of music.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 04, 2013, 05:32:46 pm
Thought you'd like to see this coming together:
 
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: DJ Omnimaga on March 04, 2013, 05:54:11 pm
The sound is quite good :). In your video descriptions, though, you should include at which time we first can hear sound, because some of us don't understand all that hardware/sound talk and might simply want to hear the sound immediately. :P
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 04, 2013, 06:41:43 pm
Yeah I know, but these are sorta like the technical devvlog videos. When the project is done I put up  a quality video and a tutorial maybe.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: TIfanx1999 on March 04, 2013, 07:41:42 pm
Keoni that is fantastic! You're gonna give Kerm M a run for his money! :D
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: utz on March 05, 2013, 03:30:17 pm
just remembered something else that may be of interest to you: http://sourceforge.net/projects/sid-wizard/ (http://sourceforge.net/projects/sid-wizard/) (.zip includes sources)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 05, 2013, 06:57:18 pm
Does that run on a c64? Might give it a go and put it on a floppy using my xm cable.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: utz on March 05, 2013, 07:27:31 pm
Yup, runs on c64. I see that you are well prepared :p
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 08, 2013, 07:42:05 am
Lol why was this topic locked all of the sudden?

Ontopic: I have optimized the code on the arduino and I get some pretty fast transfers now. I don't need to include delay loops on the calculator side anymore. I even tried it with full mode, but quite a few bad bytes got trough. I can probably solve that by making a better connection with the arduino. I removed the SID emulation from the code just so I could work on the data transfer and optimizing this. I hope the external interrupts do not interfere with the library though. I just wanted to have the best possible transfer speeds, so others could use this code in their projects not having to worry about delays.

This code uses external interrupts on pin 3 (clock pin of the linkport is hooked up to this pin)
Code: [Select]
// MACROs
#define PIN2L !(PIND & 0B00000100)
#define PIN3L !(PIND & 0B00001000)

#define CLR(x,y) (x&=(~(1<<y)))
#define SET(x,y) (x|=(1<<y))

byte get;
byte bitCount = 8;

void bitTransceive()
{
  get >>= 1;
  if (PIN2L)
  {
    get |= 128;
  }
  bitCount--;
}

void setup()
{
  CLR(DDRD,2); //pinMode 2 is input
  CLR(DDRD,3); //pinMode 3 is input
  Serial.begin(115200);
  attachInterrupt(1,bitTransceive,FALLING);
}

void loop()
{
  if (!bitCount){
    // Pull down clock line to make sure the calculator does not send while the atmega
    // is processing the incoming data.
    SET(DDRD,3);
    Serial.println(get);
    get = 0;
    bitCount = 8;
    CLR(DDRD,3);
    // Released the clockline.
  }
}
My goal was to make the code compacter, faster, more readable and understandable. I don't think there is a lot of room for improvement here!

Edit: This is only for receiving bytes from the calculator. I will write the sending code soon.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: SpiroH on March 08, 2013, 09:03:23 am
How does it sound? I could use a sound sample :-\
Very funny GIF. Good sense of humour!
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 08, 2013, 12:06:19 pm
It sounds like a SID. I only have the one song I played in the videos, so that's not too spectacular. When I get into modulation effects and pitchbends you can really hear its full potential.

Edit: I timed the data transfer. I sent 25600 bytes in 12 seconds which means the transfer rate is 2kB/s or 16kbit/s at the moment. Remember that this arduino is doing nothing other than receiving bytes and relaying them to the pc via serial. This is on normal speed. When I set it to full speed it just gives me a lot of errors (wrong numbers received.) It might be because of the way this code is written, but I am not sure. It might just be because of the high speed and capacitance in the wires. I never had to worry about the capacitance of the wires because the speed was relatively low.

16kbit/s translates to 32000 baud :3

Edit: I can now both read and write respectively from and to the atmega. It's not very smooth at the moment, so I'm gonna run some more tests before I release that.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 12, 2013, 11:26:11 am
I made the linkprotocol bi-directional (r/w)
Code: [Select]
#define _N 255

// MACROs
#define PIN2L !(PIND & 0B00000100)
#define PIN3L !(PIND & 0B00001000)

#define CLR(x,y) (x&=(~(1<<y)))
#define SET(x,y) (x|=(1<<y))

byte data;
byte bitCount = 8;

// State _N (255) : Do nothing and wait for incoming interrupt. Carry out other tasks in the mean time.
// State  0      : Slave receives  (Receive bytes from master)
// State  1      : Slave sends     (Send bytes to master)

void bitReceive()
{
  if(bitCount){
    data >>= 1;
    if (PIN2L)
    {
      data |= 128;
    }
    bitCount--;
  }
}

void bitSend()
{
  if(bitCount)
  {
    //Set portD
    DDRD |= 4;
    if(data & 1)
      PORTD &= 251;
    else
      PORTD |= 4;
      
    data >>= 1;
    bitCount--;
  }
}

void setup()
{
  CLR(DDRD,2); //pinMode 2 is input
  CLR(DDRD,3); //pinMode 3 is input
  attachInterrupt(1,bitReceive,FALLING);
}

void loop()
{
  byte state = _N, address, cell[128];
  
  while(1)
  {
    if (!bitCount){
      // Pull down clock line to make sure the calculator does not send while the atmega
      // is processing the incoming data.
      DDRD |= 8;
      switch (state)
      {
        case 255:
        {
          bitCount = 8;
          address = data >> 1;
          state = data & 1;
          // When the mode is Slave Transmit the function bitSend() is attached to the interrupt.
          if (state){
            data = cell[address];
            attachInterrupt(1,bitSend,FALLING);
          }
          break;
        }
        case 0:
        {        
          cell[address] = data;
          bitCount = 8;
          // Return to mode _N.
          state = _N;
          break;
        }
        case 1:
        {
          bitCount = 8;
          // Re-attach the bitReceive function to the external interrupt on pin 3 and
          // return to mode _N.
          attachInterrupt(1,bitReceive,FALLING);
          state = _N;
          break;
        }
      }
      // Release the clockline and data line.
      DDRD &= 243;
      PORTD &= 251;
    }
  }
}
This code compiles to less than 1k and it uses only 16 bytes of RAM + 128 for the data cells (used in this example so you can read and write from these cells from the calculator. These will get replaced by the SID registers).

Edit: When I put the content of the main loop in a function it compiles to over 2k O.O I have to do this in order to be able to make this into a library and make the code more readable, but it's not optimized at all.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 21, 2013, 12:40:15 pm
I got it all working again after some tinkering with delays. Now I present to you: THE SOURCE AND SCHEMATICS!
http://8times8.host56.com/?p=98

Edit: You can fit a register write in the fastest interrupts. Stuff can get glitchy when you do though. Not sure why, though. At the lowest interrupt frequency you're always safe and there is no noticable framerate drop when you use an optimized music player.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 25, 2013, 11:24:45 am
I am working on a minimalistic music editor that I am going to use for composing music for my Hero Core port.
(http://www.carpetvista.nl/images/buttons/play_button.png) (http://www.omnimaga.org/index.php?action=dlattach;topic=15565.0;attach=14909) 16 step 3 channel loop. All triangle waves.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Dapianokid on March 28, 2013, 06:12:14 pm
Is there a way to emulate this soundchip and somehow link together the emulated soundchip and a Wabbit? :)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Streetwalrus on March 29, 2013, 04:46:08 am
I don't think so.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 29, 2013, 05:03:45 am
I was thinking of this too. It is definitely possible if you have the source of wabbit.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Streetwalrus on March 29, 2013, 08:27:11 am
IDK if there's an arduino emu around. Though with TiLEM + libticables, you can probably do something. What I was saying is that wabbit can't do it w/o source mod and TiLEM would need an external program.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 29, 2013, 08:33:49 am
You do not need an arduino emulator, but you need something that emulates the SID soundchip and the link protocol.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Streetwalrus on March 29, 2013, 08:52:04 am
Also I really gotta get an Arduino like right now. :P Because that sounds awesome. (pun intended)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 29, 2013, 08:57:57 am
Great! You can find the sourcecode and schematics here:
http://8times8.host56.com/?p=98
There is a zipfile with all the resources you need.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Streetwalrus on March 29, 2013, 09:08:53 am
Thanks. I wonder if this can be ported to the RasPi too, 'cause that's what I have right now. :P Not really suited for this, but hey ! quick testing !
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on March 29, 2013, 09:30:37 am
The sid library is timer interrupt driven and the link protocol is external interrupt driven. If you can figure out a way to use interrupts on the RPI you can try to port it.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on December 18, 2013, 07:14:13 am
Working on this again :D
I use hardware SPI for the data transfer now! It is super fast! It is unidirectional though. I2C would be bidirectional, but it is a bit harder to set up. I might change it to I2C some day.

Edit: I got it working and it is much faster, cleaner and more reliable than ever before!
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on December 20, 2013, 07:58:03 am
Allright I had to scrap some things in order to make it work, but now we're golden (hopefully)
I am polling the SPI registers in order to receive bytes with the arduino. This is because the interrupt driven method was not ideal in this situation. Bytes would get lost because the SID emulator's timer interrupt was blocking the SPI interrupt.

As long as there is enough delay in between writes it's fine. I imagine you could use interrupts on the calculator to send one byte at a time and still have plenty of cycles left for your program.

I also wrote a PC program that allows you to convert any data to an appvar. I used it to convert SID dump files to appvars. I successfully played one back. I need some kind of compression though cause those dump files are huge.

Edit: The sawtooth wave of the emulator sounds terrible, so I am probably going to have to rewrite some of the emulator's code. I hope I will be able to pull that off without breaking something in the process :P I am taking out my scope to try to find out what is wrong with it.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on December 22, 2013, 09:44:00 am
Update: Playing back register dumps on my calculator. Finally :D

Song in the video is from r-type.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on December 22, 2013, 10:06:27 am
So, assuming I get an arduino/get the right parts for Christmas, I'm definitely going to build this! :D

Great job, Keoni!
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on December 22, 2013, 10:08:39 am
I will be working on a lightweight chiptune player interrupt routine. You can just slap that on a game and have instant music (given you have a soundchip plugged in). How bout that?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on December 22, 2013, 10:10:49 am
/me thinks it will become useful for VVVVVV :D
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: TIfanx1999 on December 22, 2013, 10:25:18 am
That's pretty awesome Keoni! :D
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on December 22, 2013, 05:30:55 pm


I found out about hardware scrolling on the z80 calcs a while ago. I did some experimentation and this is the result. It is incredibly fast. The main loop has a Pause 200 in it. It just rotates the screen now but in the future new rows will be placed at the edge of the screen. Scrolling and the cursor work now.

Edit: Added poll
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on December 27, 2013, 08:10:38 pm
So I'm in the process of building one of my own. I'll post how it goes later :D
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on December 29, 2013, 04:32:02 am
New version finally released!
http://8times8.host56.com/?p=372
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on December 29, 2013, 11:58:41 am
I appear to be missing "appvRTYPEDMP"

How do I get it, exactly?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on December 29, 2013, 07:13:58 pm
Just change that to TESTVAR. I forgot to change it back
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on December 29, 2013, 09:15:14 pm
Okay, I did that. I get some really garbled "noise" type sound out of it. It cuts in and out. I tested my connections and they seem to be fine. What could the problem be?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on December 30, 2013, 03:50:51 am
Did you reset the soundchip after you plugged it in? Is your cable too long by chance? Did you connect arduino pin 10 to ground?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on December 30, 2013, 11:48:25 am
Pin 10 to ground... Was I supposed to do that?

*facepalm*

lemme make sure this is right:

Input:
Tip to 11
Ring to 13
Sleeve to ground

Output:
Tip to 9 via the resistors/capacitors
Sleeve to ground

Other:
10 to ground
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on December 30, 2013, 01:10:31 pm
This is correct. Try taking the audio directly from pin 9.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on January 06, 2014, 04:53:44 am
I made a test setup for my SID soundchips (real ones) to see which ones still worked. So far I got 2 functional SID chips. I want to try to interface one with my calculator.

Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on February 08, 2014, 12:32:42 pm
Release 1.3:
Added:
+TO8xv.exe: Converts any raw data to an appvar. Useful for converting sid dumps to appvariable so you can play them back from your calculator.
+Link to sid_dumper.exe added in the readme.
Fixed:
-Readme updated. Added some essential information.
-Fixed appvar name in the siddump player source.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on April 09, 2014, 05:29:11 pm
There was something wrong with the previous release.

New version of timid: Version 1.3.2
https://dl.dropboxusercontent.com/u/52769784/TIMID_soundchip_release1.3.2.zip (https://dl.dropboxusercontent.com/u/52769784/TIMID_soundchip_release1.3.2.zip)

Fixed:
- Sid player fixed. Had some timing issues.




Edit: Upcoming features: Soundchip firmware optimized for playing dumps. It allows for writing an entire frame using only 26 bytes as opposed to 25 address+25 value bytes.
I might add some more commands to increase the performance.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on April 12, 2014, 11:33:47 am
Thank you! It works now for me! :w00t:
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on April 12, 2014, 11:35:36 am
Yay. If you can: please make a video :3

Edit: Some songs you can download: http://cookiecraft.eeems.me/public/TIMID/timid_songs.rar (http://cookiecraft.eeems.me/public/TIMID/timid_songs.rar)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: DJ Omnimaga on April 12, 2014, 09:58:44 pm
Do you have MP3s of the songs? Also your link doesn't work :P
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on April 13, 2014, 03:05:57 am
Because I shut off the server. Will reboot it now. These are appvars by the way. Rename TESTVAR.old# to TESTVAR.8xv

I will record some of them this afternoon.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: DJ Omnimaga on April 13, 2014, 03:07:45 pm
Ok but I was wondering about MP3s since I don't have the hardware required to listen to the song examples. :P
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on April 13, 2014, 06:03:20 pm
Will record some tomorrow when I have my line-in on my soundcard sorted out. It was acting up today.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on June 02, 2014, 08:35:44 am
I want to make a PCB for this so everyone can have a TIMID soundchip. I want to know which features should be included on the board.

These features are optional and make the board larger and more expensive.
Onboard voltage regulator. (So you can power it using a 9v battery for example)
I/O pins broken out so it's a fullfledged arduino compatible board.

I can have the bare pcb's manufactured for about $1.20 each. The microcontroller costs about $2-3. The price of the other components varies, but I think I can get the total cost down to $5-8 (depends on the additional features of the board)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Streetwalrus on June 02, 2014, 10:45:37 am
I guess if you keep it 5V it's nice because you can power it off of USB. Even with the 84+'s port. ;)
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: pimathbrainiac on June 02, 2014, 01:30:28 pm
I would actually like the regulator because I don't have an external +5v source, but I do have a +9v for my arduino.

I'll buy if I can get my parents to let me.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Streetwalrus on June 02, 2014, 04:09:29 pm
If you can get it made this cheap, I'd pay $10-15 + shipping. Definitely worth it.
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on June 02, 2014, 04:17:10 pm
Does it have to fit inside of a calculator or is it better to make it an external device with more features?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Streetwalrus on June 02, 2014, 04:49:30 pm
Maybe two versions ?
Title: Re: TI84+ soundchip - arduino SID emulator
Post by: Keoni29 on June 02, 2014, 06:20:17 pm
That depends on the amount of people who actually need one of these. The minimum order per board is 10 pieces.