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.

This entry was posted in Cool Sites, Examples, Flash, Flex, News, Random Thoughts, Uncategorized and tagged , , , , , , , . Bookmark the permalink.

44 Responses to Playing with Alchemy : C64 Music Playback on Flash 10.

  1. Proti says:

    this TinySidFlash link is wicked

  2. wonderwhy-er says:

    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. UnitZeroOne says:

    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. Pingback: Anotherfaceinthecrowd – Kanye West… Eat Your Heart Out

  5. grapefrukt says:

    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?

  6. 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).

  7. UnitZeroOne says:

    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.

  8. UnitZeroOne says:

    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.

  9. 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 :)

  10. UnitZeroOne says:

    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.

  11. Pingback: Weekly Shared Items - 13. February, 2009 | toxin 2.0 - weblog of a german design student from wuerzburg

  12. Og2t says:

    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).

  13. 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.

  14. Gabriel Laet says:

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

  15. g.wygonik says:

    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.

  16. Pingback: Hebiflux » Les musiques d’antan à présent sous Flash

  17. glafouk says:

    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 ;)

  18. Keith says:

    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.

  19. Pingback: localToGlobal » Blog Archive » news review -> 7th week of 2009

  20. Cedric says:

    Excellent !! BRAVO !

  21. Pingback: Textmode experiments using Alchemy and C++

  22. reinier says:

    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!

  23. Pingback: Photon Storm » Blog Archive » Flashtros & C64 SID music from AS3/Alchemy

  24. Zell says:

    Brilliant work!

  25. baldrikk says:

    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!

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

  27. Og2t says:

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

  28. GenreX says:

    Good work sir!!!

  29. Alan says:

    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.

  30. Pingback: Flash 10, Massive amounts of 3D particles with Alchemy (source included). - unitzeroone.jp

  31. frank says:

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

  32. Ole Jak says:

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

  33. 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!

  34. tricker says:

    music waves looks great. nice one.

  35. Alama says:

    Hello UnitZeroOne, Verry good job! ;-)

    The final data sound (bytesArray) is played by AS3 (sampleData) or by C code?

    I have a big question!? It possible replace the original sampleData class from AS3 by a new system writed in C? Because, the Sampledata use a buffer from 2048 up to 8192 samples and i’snt possible to change the data on the fly in this buffer. It’s introduce a latency up to +/- 600 ms :-/

    Once the buffer is playing, we must wait for the next Event to a change of sound (DSP) is listenable.

    I like Blue Monday.. :-) )

  36. Shane says:

    I just came across this site. I LOVE the sid player, and the tracks you’ve selected. So old-skool :D

  37. krusher says:

    Are you releasing the source? or at least a version that loads any sid file from url…

  38. Great work,
    Are you still not releasing the source? I’m not good enough with C++ to find out what to change etc :( but i want to use some SID files for a game, converting makes it sounds ugly.

  39. Pingback: The Dude's really fucked up world!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.