Asteroids on Oscilloscope

The Joy of Tech - Anything and everything about all things shiny..
Post Reply
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

Kamineko wrote:That code was running on an Acer Travelmate C300 laptop running whatever default AC97 stuff Linux (Debian Wheezy) gives me. I don't see much in the way of visible options in the KDE settings and poking around sounds like a good way to fruitlessly waste a fortnight. Having working audio in Linux for me is already a major victory.
I know that feeling!


Kamineko wrote:It would look like a strange smooth curve shooting around between the on-screen objects linking them all together. (Though the interconnecting mesh would flicker madly as the best non-wiggly solution changed from frame to frame.)
Like the filaments in a plasma ball, then?



Anyway... stopped back in because I realised that it's pretty trivial to model the high-pass filter which causes the major drift, but not necessarily so easy to tune the model to match as precisely as you need.

So basically, you've got someone doing this to your data (assuming buffer[0..buffer_size] is all part of the same channel):

Code: Select all

static float capv = 0.0;
for (i = 0; i < buffer_size; i++)
{
    capv = capv + (buffer[i] - capv) * 0.01;
    buffer[i] = buffer[i] - capv;
}
Except that 0.01 is some magic value you'll have to figure out (I'm having a blank, but it's a trivial equation and if you assume maybe a 20Hz cut-off you, like, mulitply things by pi and 2 and divide by 20 and ..uhh.. samplerate ... thing ... bleah).

Anyway... while you're generating your data, you can keep your own model of capv (repeat the first line, above), and whenever you get to a don't-care part of your buffer, you stuff in values that will push capv back towards zero.

Code: Select all

float capv_model = 0.0;
for (i = 0; i < buffer_size; i++)
{
    if (buffer[i] == FILLERVALUE)
    {
        if (capv_model < 0)
            buffer[i] = PLUS_LOTS;
        else
             buffer[i] = MINUS_LOTS;
    }
    capv_model = capv_model + (buffer[i] - capv_model) * 0.01;
}
Then you want to make sure that you visit the FILLERVALUE case as frequently as possible so that you regularly get to steer your capacitor back to zero.

Fortunately, because it's a single-pole filter, tuning the model incorrectly doesn't give you wild results. What will happen is that when the model capv reaches 0, the output will start to oscillate between PLUS_LOTS and MINUS_LOTS to keep the model right on zero (because PLUS_LOTS and MINUS_LOTS will make the model cross to the other side of zero instantly). Even if your tuning is out, the _real_ capacitor will be seeing the oscillation between PLUS_LOTS and MINUS_LOTS and seek to their average, which is still zero.

In theory.


Hm... but if you do this separately on two channels, when they start to oscillate they'll draw a diagonal line across the display.

Maybe stop adding filler values when you see capv_model is close to zero.
User avatar
gravy
Sheepie Whore
Sheepie Whore
Posts: 19572
Joined: Wed May 01, 2002 1:28 pm 0
Location: The Other Place

Re: Asteroids on Oscilloscope

Post by gravy »

Nothing to add except great thread :) Really interesting stuff in here and an awesome project Kamineko :D
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

Oops... timed out on my edit rights. Another thought struck soon after...

If you bucket your objects into quadrants (above, or below zero, on each axis), then instead of adding filler values, you can just select an object from the quadrant that has the opposing sign from your two values of capv. So for each object you add, you accumulate the samples into capv, and at the end you look at the signs and choose the next object from the other side of zero so that capv will move in the other direction back towards zero. Only if you run out of objects in the required quadrant will you have to start drawing PLUS/MINUS_LOTS values instead.

If you go as far as to fully sort your objects and choose objects according to how far wrong capv is, then you're going into control theory and you might want to start reading books on the subject, because it can get kind of involved.


By the way; I kind of meant to start here: The goal of modelling capv from the first equation is to figure out what data you should put in to keep capv close to zero. You want to keep capv close to zero because then the second line 'buffer = buffer - capv' has less effect when capv is nearly zero. So less visible error. capv always walks towards the current buffer output, so it's easy to drive up or down by simply putting out values higher or lower than its current value.


You can also try just adding capv_model onto buffer to directly compensate, but.. umm.. then you have to factor the actual value you emit back into your capv_model... does that work? Not sure. I think it can oscillate.
User avatar
_TinOmen_
Baaaa!
Baaaa!
Posts: 745
Joined: Wed Feb 12, 2003 10:52 pm 0
Location: Stockholm, Sweden
Contact:

Re: Asteroids on Oscilloscope

Post by _TinOmen_ »

This project looks great! Have you made a video yet? I want to see it in motion :)

You know that there are open source Vectrex emulators out there. It should not be too hard to modify one to get the current set of lines to render so you can use it with your oscilloscope code. I could help with that if you are interested.
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

I figured it's probably the case that people have done X-Y scope emulators in software which could work from a .wav file or whatever, and in searching for it I found this:


Note that despite him saying that he was using a better soundcard than his laptop, his set-up shows problems much more than the original youscope demo video:


So anyway... it turns out there are a few oscilloscope emulators out there featuring X-Y mode; some read from your soundcard (so you could use a loop-back cable; or possibly read from an internal monitor line which might not reveal all the problems) and others are are mentioned in conjunction with youscope (so search for "youscope emulator"), which presumably take input directly from a data file.


Also should have mentioned that it's not really a "fault" of the soundcard that it does this. The high-pass filter is necessary because if it was capable of driving DC then it could convince an amplifier to drive DC, where speaker impedance drops off and components transition to the incandescent operating region. The standard solution for this is just to AC-couple with a single capacitor, which is why it's so easy to model. The bigger the cap the lower the cutoff and the less bass you lose (and the more stable your picture), but you can't go right down to DC. The ringing at the high-frequency end is debatable. It has to do _something_, but what it chooses to do is controversial.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

gumboot wrote:
Kamineko wrote:Nope. I won't be able to get to a scope again for a while.
Use the line-in on your soundcard.
Is that likely to work?

I'm not sure if my sound card can support recording and playback simultaneously, and if it can, isn't it likely to just produce near useless data using them both simultaneously? (Electrical or magnetic interference, software crap, Linux being Linux, anything like that.) I have a baseless suspicion that the laptop's input is probably going to be a worse quality device than the output also, so if the output signal is too wild to produce accurately I doubt the input will show anything nice.

The only way to know for sure is to try, of course. But that's boooring.

Given that the output on that Arduino Christmas message was crystal clear, a more productive thing is to take this to a dedicated microcontroller or FPGA project board with a couple of nice DACs.
This project looks great! Have you made a video yet? I want to see it in motion
It looks like glowing muck. :P I've got a video of it running taken from my digital camera, but its huge. I'll try to transcode it to something so I can upload it.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

video It's long and boring and there's no sound. I'm going through various versions of the game. I don't exactly remember the settings I used for each run. I was planning to just cut out the best looking run, but at about 5 minutes in I realised that folks might want to see the different runs so I left them all in.

00:00 to 02:00. At the start, the border is faint and blurry, so I think I was only drawing it once there. The whole screen jumps when the press start caption blinks. No score or highscore captions; I'd already turned them off by this point. The ship's thrusters are so bright, the camera is altering its colour tuning every time I thrust! Watch me fiddle with the scale dials! The screen is bouncing and shifting every time I shoot or thrust.

And I do turn the intensity dial down between trials. It'd be reckless otherwise. Camera isn't showing it.

02:29 to 03:22. More single border stuff. Half of the game objects are outside of the border, which is icky.

03:30 to 04:40. Another run of the above. I think I might have increased the number of nodes per line, the text is looking slightly more well defined perhaps.

05:00 to 05:20. I think I might have increased the buffer size. Increased stability and brightness at the cost of more flicker but the camera isn't showing how bad it is (very obvious on high score table).

06:19 Something weird is happening everything is coming out small.

06:44 to 09:13. Trying to draw the asteroids multiple times makes multiple images appear leading into the screen! Lots of action going on here. The whole screen distorts and warps the less objects there are on the screen. When there's one asteroid left, I fire a bunch of shots off and it becomes pretty painful to play. On Wave 2, I maximum thrust to the right and fire off tons of shots, causing a bundle of rocks to start flying horizontally. Then I die. Then I do the same vertically to clear the wave! Then I turn it off because MY EYES.

09:40 to 10:00. 10:20 to end. Loads and loads of borders are being drawn. The image is roughly stable in the middle of the screen, but you can see objects disappearing a lot and the flickering is terrible! Most text heavy screens come out incomplete. The entry and exit wiggles on the asteroids are pretty obvious. The glowing border absorbs the distortion, making tunnel-like webs appear leading into the screen when objects cluster at the sides. At 11:30 I suddenly turn the border off! For the next wave, the game becomes an unplayable piece of abstract art...
User avatar
_TinOmen_
Baaaa!
Baaaa!
Posts: 745
Joined: Wed Feb 12, 2003 10:52 pm 0
Location: Stockholm, Sweden
Contact:

Re: Asteroids on Oscilloscope

Post by _TinOmen_ »

Looks very cool. About Vectrex on Oscilloscope, I noticed it had already been done.
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

_TinOmen_ wrote:Looks very cool. About Vectrex on Oscilloscope, I noticed it had already been done.
So basically I was doing everything right, except I need to Get A Mac.

Huh.
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

Kamineko wrote:
gumboot wrote:
Kamineko wrote:Nope. I won't be able to get to a scope again for a while.
Use the line-in on your soundcard.
Is that likely to work?

I'm not sure if my sound card can support recording and playback simultaneously, and if it can, isn't it likely to just produce near useless data using them both simultaneously? (Electrical or magnetic interference, software crap, Linux being Linux, anything like that.) I have a baseless suspicion that the laptop's input is probably going to be a worse quality device than the output also, so if the output signal is too wild to produce accurately I doubt the input will show anything nice.
Well, I don't really expect it to make things much worse -- I can see it doing the same things all over again, but that'll only make it a small amount more pronounced -- and I haven't heard of a device (other than maybe USB 1.1 devices) which can't play and record at the same time. You could simply run your current software and then install and run something which purports to visualise whatever's on line-in. apt-cache search brings up 'xoscope', for example.

Oh, by the way, you didn't have the scope set to AC-coupled, did you? My feeling is that with the rate of decay we see here, you'd lose some audible bass if it was the soundcard doing it.
User avatar
gumboot
Baaaaaaa!
Baaaaaaa!
Posts: 7652
Joined: Sun Aug 26, 2007 3:42 am 0
Location: trumpstain!

Re: Asteroids on Oscilloscope

Post by gumboot »

I only answered half the question there, didn't I. The PC _is_ likely to be riddled with interference, but the coupling isn't strong and while it may make the lines a little bit fuzzy, if it did so much as make it hard to see what you were doing then the recordings would be unlistenable.

Usually you can expect some intermittent buzzing or whistle, but to be audible it doesn't have to be very loud at all, so it shouldn't be a significant visual distortion.

I do expect the record path to have some or all of the same filter stages as the playback path. First a gentle analogue filter, then a high-frequency sampler and a sharp digital filter to eliminate aliasing before decimation (this digital filter is what I expect to cause overshoot and wobbly lines), and maybe some more AC coupling as a cheap means of biasing the input signal to the operating region of the ADC.

The output digital filter and the input digital filter won't give you the sum of two wiggly lines (which really would look terrible!); it might just change the frequency of the wiggle a little bit; possibly making it a little bit less wiggly at the cost of making the cursor slightly slower to take long steps -- but this should be negligible.
User avatar
sdetoni
Baaaaa!
Baaaaa!
Posts: 1368
Joined: Tue Jun 18, 2002 4:14 am 0
Location: New Sheepland

Re: Asteroids on Oscilloscope

Post by sdetoni »

That's just mental in a hacker kind of way, using analog audio to drive graphic output :winner:
User avatar
Stephen
Baaaa!
Baaaa!
Posts: 914
Joined: Mon Apr 22, 2002 4:39 pm 0
Location: Akron, Oh USA

Re: Asteroids on Oscilloscope

Post by Stephen »

That's amazing work!
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

Are there are any super simple microcontrollers with 2 real analogue outs that might be fast enough to make one of these in hardware?
User avatar
Kamineko
Baaaaaaa!
Baaaaaaa!
Posts: 7569
Joined: Fri Dec 17, 2004 2:53 pm 0
Contact:

Re: Asteroids on Oscilloscope

Post by Kamineko »

Making a note of the dsPIC33FJ64GP802

http://www.microchip.com/wwwproducts/De ... e=en532310#
Post Reply