MIDIbox Forum: linux asid player - MIDIbox Forum

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

linux asid player sidplay2 hack to output midi Rate Topic: -----

#1 User is offline   aTc 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 17-December 09

Posted 11 September 2010 - 04:13

After getting annoyed with asidxp, and having to boot into windows to actually use it, I decided to have a go at getting the linux sidplay2 to output to midi.
And so after a few days of messing about (most of which was listening to sids on my sammich), I came up with this:

http://wreck.k-n-p.o...y2-asid.tar.bz2

It's a sidplay2 with the hardsid part modified to output to midi.
It works for most sids, there are a few problems with some that write to the registers more than 3 times every frame, since the protocol doesn't support that.
Sample playback obviously also doesn't work.

It's pretty much a hack, the code needs some serious cleaning up, and needs to be moved into its own builder, instead of hijacking the hardsid one.
It also uses a very basic, slightly inaccurate timing method at the moment, which also needs work.
I'll get to that once i've tried all 38,714 sids in the hvsc with it, which is slightly more fun :)

It's pretty much hardcoded to work with linux+alsa at the moment, but since it uses RtMidi to take care of the midi end of things, it should have no problems running on other platforms after some cleaning up.

No binaries, you'll have to compile this yourself. See readme.txt included in the archive for compiling details.
Tested on ubuntu 10.04, both 32 and 64 bit versions, and crosscompiled to arm.

It's pretty much in the "it works for me" stage now, any suggestions, bugfixes and code cleanups are welcome :)

#2 User is offline   TK. 

  • MIDIbox Guru
  • View gallery
  • Group: Administrators
  • Posts: 11,141
  • Joined: 01-January 01
  • LocationGermany

Posted 11 September 2010 - 10:41

Nice work, your implementation looks less dirty than my own one :)
(some years ago I hacked the code directly into resid-builder, and MIDI data was output to /dev/midi)

For writing into the waveform registers I'm using a different strategy, here an excerpt:
	// TK: this probably doesn't match with the way how the original ASID software handles the second 
	// waveform register set - but I find it useful this way
	// strategy: whenever the two sets are allocated, shift the 2nd one to the first entry...
	// this ensures, that the two last waveform changes take place
	
	// write to waveform register? check if first set is already allocated
	if( mapped_addr >= 0x16 && mapped_addr <= 0x18 && asid_reg[mapped_addr] & 0x100 ) {
		// switch to second waveform register set
		mapped_addr += 3;
		
		// if this one is allocated as well, copy the old one to the first set
		if( asid_reg[mapped_addr] & 0x100 )
			asid_reg[mapped_addr-3] = asid_reg[mapped_addr];
	}


Here the code of an overworked version if you would like to compare the methods (but it's for the MacOS based SidPlay)
http://www.ucapps.de...sid/ASID_MIDI.m

Best Regards, Thorsten.
Posted Image Buy TK a Beer Disclaimer: buying TK a beer gets you absolutely nothing in return likesuchas firmware enhancements, technical advices and MIDIbox troubleshooting assistance.

#3 User is offline   aTc 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 17-December 09

Posted 11 September 2010 - 16:54

Ah, yes, I seem to have forgotten to move the old writes to the secondary registers back to the first ones.
Fixed now.

Do you happen to have a list of sids that are especially problematic to play back ?

#4 User is offline   TK. 

  • MIDIbox Guru
  • View gallery
  • Group: Administrators
  • Posts: 11,141
  • Joined: 01-January 01
  • LocationGermany

Posted 11 September 2010 - 23:17

I took all Rob Hubbard songs as reference, since I know these tunes since centuries. ;)

Best Regards, Thorsten.
Posted Image Buy TK a Beer Disclaimer: buying TK a beer gets you absolutely nothing in return likesuchas firmware enhancements, technical advices and MIDIbox troubleshooting assistance.

#5 User is offline   toadstool 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 45
  • Joined: 26-October 08
  • LocationScotland

Posted 19 September 2010 - 14:39

Hi guys,

My first post :-) I'd just like to say thanks for providing what proves to be the best and most stable way of playing back SID audio files for me. I'm using 32 bit Ubuntu 10.04 and an Edirol UA-101 audio interface, along with TK/Wilba's super-duper, amazing, formidable, (insert your favourite superlative here) MB-6582.

Much respect to all you hard working fellows!

JC

Currently rocking out to Jazzcat by DRAX - Awesome!

#6 User is offline   aTc 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 17-December 09

Posted 22 September 2010 - 22:31

Making it more stable than asidxp isn't much of a challenge :)

And as a bonus, here's a video of the player running on an arm device.
Apart from the obvious timing problems, it's quite easy to get it running on almost any device that runs linux.
(and has a midi port).
Fixing the timing properly is a bit of a challenge though, and I first have to dig about in the sidplay2 source a bit more to find out exactly how it does things.

#7 User is offline   TK. 

  • MIDIbox Guru
  • View gallery
  • Group: Administrators
  • Posts: 11,141
  • Joined: 01-January 01
  • LocationGermany

Posted 22 September 2010 - 23:18

An extravagant demo! ;)
Do you notice the same timing accuracy issues on a fast computer as well?

My approach was to add a hook into the resid emulation, so that the emulated SID + the real SID can be played in parallel. This was the easiest way to compare the timings, but also the differences between original and emulation.

Best Regards, Thorsten.
Posted Image Buy TK a Beer Disclaimer: buying TK a beer gets you absolutely nothing in return likesuchas firmware enhancements, technical advices and MIDIbox troubleshooting assistance.

#8 User is offline   aTc 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 17-December 09

Posted 23 September 2010 - 02:44

Problem with my version is that it just puts the task to sleep based on the c64 clock cycles between the writes, without taking into consideration how long the emulation, or the midi writing takes.
So on a fast computer it's more accurate, since it spends less time calculating stuff.
It's mostly to do with the timer used by the kernel for task switching. I think the main reason for the slowdown is because my desktop is using a 1ms timer, and the arm device as 10ms one.
(sid playing in that video is C64Music/MUSICIANS/W/Whittaker_David/Tube.sid , should have probably used a more well known tune)


A more accurate method would be one where you just have a function that's called 50 times/second, and sends the changes. But i think you run into problems with sids that were meant to run at 60hz, or use timing other than vblank. At the moment I have no idea if it's possible to get that sort of info from sidplay2 inside a builder.
All you seem to get in a builder is which register is written to, and at which clockcycle, and for that method to work properly you really need to be able to call the emulation for new data, instead of the emulation calling you when something's written to a sid register.

As I said before, really need to dig a lot deeper into this whole thing.

#9 User is offline   nILS 

  • MIDIbox Hero
  • View gallery
  • Group: Administrators
  • Posts: 3,986
  • Joined: 22-July 03
  • LocationStuttgart, Doucheland

Posted 23 September 2010 - 10:20

To sorta get around that issue I added a calibration function into my sid player. Basically it measures the time sending the data and preparing it takes ~10k times (using RDTSC) and hopes that the conditions don't change :)
Check out the unofficial MIDIbox Quote database

Posted Image Buy nILS a Beer Disclaimer: buying nILS a beer gets you absolutely nothing in return likesuchas real-time chat support, gm5x5x5 pcbs, MIDIbox troubleshooting assistance or a less grumpy german.

#10 User is offline   toadstool 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 45
  • Joined: 26-October 08
  • LocationScotland

Posted 23 September 2010 - 12:47

Oweeeeeee, you have a Pandora! My GP2x gave up on me about 6 months ago :hmm: Does this mean you might be hacking the VICE code to allow playing SID music through the Midibox SID? (Hint, Hint :wink:)

#11 User is offline   toadstool 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 45
  • Joined: 26-October 08
  • LocationScotland

Posted 23 September 2010 - 12:59

I've been listening to some of my favourite classics (Tel, Hubbard, Dunn, DRAX, Linus, Jeff etc) and have only just discovered and been blown away by 'Hot Mommas' by Jammer (C64Music/MUSICIANS/J/Jammer/Hot_Mommas.sid) - it's amazing what the SID is capable of! I also never realised TK had been composing tunes that are in the HVSC. Kudos TK!

#12 User is offline   aTc 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 17-December 09

Posted 26 September 2010 - 23:41

Turned out there was an easier solution, which is clock_nanosleep(), which will wake your task up at a requested time with pretty good accuracy.

Videos of it playing various sids on the pandora here.
Video 2 uses nanosleep instead of usleep, which already improved accuracy quite a lot, but it still wobbled about a bit.
Video 3 uses clock_nanosleep, waking it up at a requested time, and is far more stable. Has only minor problems when there's other programs generating a heavy cpu load, but that's more a task switching priority thing.

Accuracy can be improved even more by giving the task a higher priority.

sidplay2-asid_0.2 can be downloaded here.

I'll have a look at the VICE code, but i'm not promising anything :)

#13 User is offline   TK. 

  • MIDIbox Guru
  • View gallery
  • Group: Administrators
  • Posts: 11,141
  • Joined: 01-January 01
  • LocationGermany

Posted 27 September 2010 - 00:13

Great progress - it seems that your version is becoming the best ASID player! :)

Best Regards, Thorsten.
Posted Image Buy TK a Beer Disclaimer: buying TK a beer gets you absolutely nothing in return likesuchas firmware enhancements, technical advices and MIDIbox troubleshooting assistance.

#14 User is offline   aTc 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 17-December 09

Posted 28 September 2010 - 02:12

Well, best player.. I only show the sids that work properly in the videos :)
And it's basically as good as sidplay2 is.
Of course the biggest problem is the asid protocol itself.


Anyway, I did mess about with VICE, and to my own surprise managed to get it to output to asid.
It's in very early stages, but it works reasonably well.
And as before, the biggest limitation is the asid protocol, you have to wait untill there haven't been any writes to the sid registers for a while, then group all the writes together and send the data.
Would be a lot easier if you could just send the register and data in two midi bytes and have it update immediately.
No idea if midi can handle that sort of stuff fast enough, they must have had a reason to make asid the way it is.

Here's a video of that hacked VICE, playing Great Giana Sisters.

#15 User is offline   TK. 

  • MIDIbox Guru
  • View gallery
  • Group: Administrators
  • Posts: 11,141
  • Joined: 01-January 01
  • LocationGermany

Posted 28 September 2010 - 07:57

View PostaTc, on 28 September 2010 - 02:12, said:

Would be a lot easier if you could just send the register and data in two midi bytes and have it update immediately.
No idea if midi can handle that sort of stuff fast enough, they must have had a reason to make asid the way it is.


The transfer of 2 bytes takes 0.64 mS, you would hear a difference if for example the gate flags of the 3 waveform registers would be set one after another with such a delay.

Try the "oscillator phase" parameter of the MBSID lead engine, then you known what I mean ;)

Best Regards, Thorsten.
Posted Image Buy TK a Beer Disclaimer: buying TK a beer gets you absolutely nothing in return likesuchas firmware enhancements, technical advices and MIDIbox troubleshooting assistance.

#16 User is offline   aTc 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 17-December 09

Posted 29 September 2010 - 10:28

View Posttoadstool, on 23 September 2010 - 12:47, said:

Oweeeeeee, you have a Pandora! My GP2x gave up on me about 6 months ago :hmm: Does this mean you might be hacking the VICE code to allow playing SID music through the Midibox SID? (Hint, Hint :wink:)


Done. :)

Well, not quite, needs a lot of cleaning up first, and better integration with the rest of vice, but it's usably on my machine.

#17 User is offline   toadstool 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 45
  • Joined: 26-October 08
  • LocationScotland

Posted 29 September 2010 - 12:02

That is a whole lot of Cool! Will you be releasing your modifications to the VICE code and/or submitting the changes to the VICE team? I sure hope so..... It is a shame there is no way to pump SID samples via MIDI.... Turbo Outrun anyone? Some may see playing SID files as belittling the capabilities of the MB-SID but I for one would love the ability to use the MB-SID as the sound hardware for C64 demos, trackers, games etc as well as using it as a mighty professional synthesiser. I have only just finished building the base board of my MB6582 and have still to source parts for the control surface - I feel like I am on the cusp of attaining true chiptune nirvana (with lots of help of course!) :D

This post has been edited by toadstool: 12 October 2010 - 13:00


#18 User is offline   Smithy 

  • PipPipPipPip
  • Group: Members
  • Posts: 941
  • Joined: 20-September 07

Posted 02 October 2010 - 11:31

View PostaTc, on 11 September 2010 - 16:54, said:

Ah, yes, I seem to have forgotten to move the old writes to the secondary registers back to the first ones.
Fixed now.

Do you happen to have a list of sids that are especially problematic to play back ?


I could contribute to the that list i'm pretty sure! :thumbsup:
*cough* subtune 2 *cough*

Well done on getting Commando to play properly, asidxp and nils hacked .dll couldn't play it properly.
Edit: Asid XP plays it fine actually.

Dude what the hell is the name of the sid at the start of video 3 with the speech?

Does this mean you were able to support PCM playback for that sid?

Or is using some other tricks like Ring Mod to generate the speech.

This post has been edited by Smithy: 02 October 2010 - 12:17


#19 User is offline   nILS 

  • MIDIbox Hero
  • View gallery
  • Group: Administrators
  • Posts: 3,986
  • Joined: 22-July 03
  • LocationStuttgart, Doucheland

Posted 02 October 2010 - 12:38

Quote

Well done on getting Commando to play properly, asidxp and nils hacked .dll couldn't play it properly.
Edit: Asid XP plays it fine actually.

If ASID XP plays it properly then my version will play it properly as well, if you set the flush mode to ASID XP ;)
Check out the unofficial MIDIbox Quote database

Posted Image Buy nILS a Beer Disclaimer: buying nILS a beer gets you absolutely nothing in return likesuchas real-time chat support, gm5x5x5 pcbs, MIDIbox troubleshooting assistance or a less grumpy german.

#20 User is offline   toadstool 

  • MIDIbox Newbie
  • Pip
  • Group: Members
  • Posts: 45
  • Joined: 26-October 08
  • LocationScotland

Posted 02 October 2010 - 14:02

Quote

Dude what the hell is the name of the sid at the start of video 3 with the speech?

Does this mean you were able to support PCM playback for that sid?

Or is using some other tricks like Ring Mod to generate the speech



I think you are referring to 'Hot_Mommas' by 'Jammer' (see my reply #11 above) and I believe it uses some clever ring modulation and possibly changing filters. No PCM samples at all at all. It is totally awesome though eh!? I love it. I tried playing that particular tune back through ASID XP and then muted each channel in turn and it seems one of the channels controls the shape of an oscillator on another channel. Or something.

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users