UnitZeroOne

Avatar

A blog written by Ralph Hauwert, freelance developer, specialized in realtime visualisation, 3D and application development.

Playing with Alchemy : C64 Music Playback on Flash 10.

6581

It's been silent here. Next to tripping to Tokyo to speak at Adobe MAX in Januari and doing some small jobs, I'm doing a very, very cool Flash 10 Project utilizing the upcoming Papervision for Flash 10. For some optimization parts I've been looking into using Alchemy as an easy way to write optimized bytecode. As opposed to what some people took from my previous post on Alchemy, I don't hate Alchemy. My point there was that if Alchemy can perform that well, so should ActionScript be able to, with the standard compiler.

Now, that being said, all work and no play makes jack a dull boy. With no time to spare during the morning, daytime and evening, I took the laptop with me to bed last night, and decided to do something I didn't do before, port something with Adobe Alchemy. I decided upon a long time thing on my wish list; SID Playback in Flash. What is SID ? Well, SID stands for Sound Interface Device, referring to the MOS6581 and it's a programmable audiochip as used in the Commodore 64 and Commodore 128. I grew up with the Commodore 64, and the audio it produces is still something I hold dearly. You are quite likely to have heard a SID chip before, if you listen to the radio, as it is quite a possible you've heard one of these baby's scream. Good recent examples are :

Bastian - You've got my love. (the beat in this song comes from Jeroen Tel's Rubicon).

Nelly Furtado - Do It (controversy all around, Timbaland blatantly stole Glenn Rune Gallefoss's version of Acid Jazzed Evening).

De Jeugd van Tegenwoordig - Hollereer (Produced by Bastian, C64 lover himself).

My interest was more playing back the old C64 tunes from games and demos. Keep in mind, an average SID file is about 2kilobyte to 10kilobyte; a perfect Small Web Format for all your music during preloading needs ;-) . Now, this is something I have been working on before in Flash 9, using the FC64 project, the amazing Flash C64 emulation effort by Claus Wahlers and Darron Schall. Last year, I even made a start with porting FC64 to Flash 10, but that needed to be dropped in favor of actual client work. SID Playback is something different from playing back .mod .xm or .mid files, as the SID chip doesn't do much on it's own. Essentially, a .SID file is an executable meant to be ran on the 6510, the Commodore 64's CPU. So to playback the file, you not only need to emulate the SID chip, but also the 6510 and the needed registers / memory.

Software emulation of the SID chip has been around for a while, and all modern platforms have a way of playback SID files. Winamp plugins, command line utilities for conversion, it's all there. As is there opensource code to do this. There's libraries for most major languages. So, after a bit of research, I decided upon the Linux version of TinySid. This library is small enough and well optimized. It looked simple to port, so I went at it. All in all, 4 hours later, I had this baby up and running! (And an unhappy girlfriend who isn't into the nerd thing, nor is she into listening to chiptunes whilst trying to sleep). Considering my very rusty C and a little hack around I had to do for the audio output, Alchemy shows off it's feathers here. Many kudo's to the Alchemy and Flash Player team for this effort. Just now I spent half an hour building a tiny interface using Keith Peter's Minimal Components, and collected some songs; and here it is.

TinySidFlash (open link, requires Flash 10).

My favorites : Politik and Science (A C64 version of Coldplay's the Scientist), Morphing and Turbo. Yes, I love Dane's tunes!

There's no code yet, as this is still very rough and unfinished work. I'm pretty sure that when I get time again, I'll have a go at LibSidPlay instead, since the overall emulation in that library is a lot better.

Digg, StumbleUpon, Slash and others:
  • Digg
  • del.icio.us
  • DZone
  • StumbleUpon
  • Slashdot
  • Technorati
  • blogmarks
  • BlogMemes
  • Ma.gnolia

Related posts:

  1. Help me test! Flash VSync and Screen Tearing.
  2. Triangle3D : Small Flash 10 3D demo.
  3. Another scream on Flash, Alchemy Memory and compilers.
  4. More play with Alchemy : Lookup table effects.
  5. Flash 10, Massive amounts of 3D particles with Alchemy (source included).

34 Comments, Comment or Ping

  1. Proti

    this TinySidFlash link is wicked

  2. Pretty interesting. Is it raw music data drawn there using Flash built in stuff? Or is it produced by C64? Just never seen raw music wave being visually correlative with it’s own sounding :)

  3. Actually, I quickly hacked the viz in using AS3; SoundMixer. Pretty much overhead really, but it was the quickest way to get a realtime view on the data, rather then going over the Alchemy output, and trying to figure out where in the stream we are. The Flash Frontend was really less then halve and hour of work, just wanted to show off the lib running in Flash.

  4. Very nice work!
    It would be very nice to use this for small games and such. I see this swf is 124k, which isn’t very small, but I guess the components bloat it pretty badly. How small do you figure the player could be?

  5. Hi Ralph,

    just one consideration about “if Alchemy can perform that well, so should ActionScript be able to, with the standard compiler”.

    You must take into account that Alchemy runs (sometimes …) faster because it has a totally different execution approach then the one implemented by the AS VM.
    Thanks to LLVM, we have statically compiled code, highly optimized, that uses a “special” execution model that, for instance, can speed up function calls thanks to the use of virtual stacks for parameter passing and return values.
    There are many other consequences of using a statically compiled language, and all those things bring to an execution engine that – in some situation – can run faster then the dynamic AS bytecode.

    For sure they might (and will) use some internal optimizations in the future to run AS bytecode even faster, but the biggest ASVM problem is not the bytecode instructions execution speed (many other languages like Python or PHP run a lot slower) but the lack of fast data structures that can be accessed an manipulated quickly (for instance a faster way to allow pixel by pixel image manipulation without running into ridiculous bottlenecks).

  6. Grapefrukt : Actually, the original player only version was around 80 kb. This has to do with Alchemy including a lot of code, which is C based. This is compiled as ActionScript / Bytecode, and gets/needs to be included in the final file. One could write a normal player with AS3, and probably have that optimized to the range of a couple of / maybe 15kb. But that wasn’t really my point on this. The fact that I managed to get that up and running in about 4 hours, from research to finish, and it being my first Alchemy port (not my first Alchemy project though), was astounding to me. I’m already looking for a new port for when I have time.

  7. Gabriele, I totally agree. I went kind of short on it in this post, as I already discussed it heavily in my previous post. I’m not that schooled about LLVM as I liked to be though. About the pixel by pixel thing; I have some stuff coming up using Alchemy which I’ll show at FITC Amsterdam.

  8. I did many many tests too with Alchemy and BitmapDatas when Achemy was in private beta, and I’ve been a bit disappointed with it.
    Looking forward for your FITC talk to know more about that :)

  9. Gabriele : You’ve got mail. IMHO, it’s how you approach the problem per case though. IE, the quake they showed ran just fine and was “software” rasterized (even more software then flash drawing api that is), from what I’ve heard. So optimisation to push at least overdraw possible and such is still needed, of course. But in 2D cases, that won’t matter as much (until you start layering). Got some solid effects for FITC and a good side by side comparison of everything.

  10. Amazing work Ralph! I remember our C64 biased discussion @ FITC last year, I’ll be interested to use your tinysidflash on http://intros.c64.org soon (it is going to be totally redesigned).

  11. Another example of original SID tunes that made it into the Billboard charts: Kernkraft 400 by Zombie Nation, “inspired” by David Whittaker’s “Stardust” from the game Lazy Jonas.

  12. This is awesome! Did you try playing NSF (NES Sound Format) files on TinySidFlash? Not sure if NSF/SID are the same or similar.

  13. Awesome. Brings back memories… *does the robot* :-) I so can’t wait to get back to the states and have time to play with Alchemy. Thanks for the inspiration.

  14. glafouk

    Wow man !!!
    I just get down on my kneez…
    The “8bitboy” was already a crazy idea…
    But this one… a SID player… Woaaauw…
    Thanks a lot for this… Micromusic rulez ;)

  15. Very cool. I love demoscene music! I used to listen to Nectarine 24/7 :) Have you ever seen http://flashtro.intro-inferno.com/flashtros.php? That is another cool demoscene to flash project.

  16. Cedric

    Excellent !! BRAVO !

  17. This is unbelievable great! I can remember coding on the C64 with TurboAssembler, swapping floppydiscs by post with reusable stamps and travelling to all kinds of places to meet other group members and spread our demo’s to the world. Who could imagine almost 20 years and several computers later it would be possible to listen to a C64 sid tune through something called a flashplayer in a webbrowser on this new invention they call ‘the internet’. I say exiting times! Respect!

  18. Zell

    Brilliant work!

  19. Hi Ralph!
    Good to se you posting again! and what a post!
    Couldnt find better thing to try as an example:)

    And let me know the next time you are coming to oslo again and feels the need for more beer!

  20. I just stumbled across this page and I have to say that this is really awesome!

  21. Hey Ralph, any change you’d share the source? I’d love to turn it into a embedable SID player.

  22. GenreX

    Good work sir!!!

  23. Awesome job on the SID emulator. It is something to hear modern music using retro computer music sounds- so now when people tell me my music sounds like Super Mario or Zelda (when it is really my C64 influence kicking in) I can take it as a compliment.

  24. @Alan Thanks. Would love to hear your stuff though!

  25. frank

    Maak alsjeblieft die sid player af, helaas doet de preview het bij mij niet maar het zou geweldig zijn sids op het web..!

  26. Ole Jak

    Would you mind sharing your source… at least in private…? Please=)

  27. Amazing! Where can I get the source?? I’m very interested in incorporating this into a flash game or at least a flash visualizer! Good work!

Reply to “Playing with Alchemy : C64 Music Playback on Flash 10.”

Search

Site hosted by :