PCM audio streaming error

Get technical support from the community & developers with specific X16 programs if you can't find the solution elsewhere
(for general non-support related chat about programs please comment directly under the program in the software library)
DragWx
Posts: 345
Joined: Tue Mar 07, 2023 9:07 pm

Re: PCM audio streaming error

Post by DragWx »

I think I see what's happening in the emulator. In r42, support for raster effects was added to the video rendering code.

The way it works is, anytime a VERA register is updated which would change what's on the screen, the emulator will partially render the current scanline with the old VERA state based on how many pixels would've made it to the display already, then update the VERA state so when the scanline is rendered the rest of the way, it reflects the changed state.

The way it does a partial render is, it renders a full scanline first, then copies the relevant pixels into the line buffer which eventually gets painted to the window.

The problem is, when you use MACPTR to write 10240 bytes to the VERA's data port, the emulator will end up rendering 10240 full scanlines in a vain attempt to try to support any raster-effects it might cause, but MACPTR in the emulator is instant, so 10240 scanlines get rendered and zero pixels actually get used. :P

I think this is what's causing the emulator to lag so much on this program, but the way you'd improve this would probably require an overhaul of the rendering code so that the VERA's state is only actually looked at when the next pixel of the scanline needs to be output, versus trying to pre-empt it by rendering a full scanline and only sometimes copying pixels from it. I've written a software rendering pipeline like this before, so I can offer some suggestions if needed. :D

EDIT: I'm pretty sure this is what it is, so I posted a thread about it in the bug report forum.
Last edited by DragWx on Sat Apr 08, 2023 7:14 am, edited 1 time in total.
User avatar
desertfish
Posts: 1098
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: PCM audio streaming error

Post by desertfish »

One extra observation:

Streaming stuff from SD card image generally works better in x16emu, than using the hostfs. Hostfs seems to support all operations, but the timings seem off. So you may want to try copying the stuff to sdcard image and run it from there, even though it mostly works on hostfs.

(box16 *requires* SD card image because its hostfs support is not yet on the level of x16emu)
Ed Minchau
Posts: 503
Joined: Sat Jul 11, 2020 3:30 pm

Re: PCM audio streaming error

Post by Ed Minchau »

I tried uploading this to test out the Try It Now feature. Well, it sure didn't like that. I think maybe it's the file folder structure that's the problem. Gonna rewrite some code and try it again with everything in the same folder.
Ed Minchau
Posts: 503
Joined: Sat Jul 11, 2020 3:30 pm

Re: PCM audio streaming error

Post by Ed Minchau »

OK, trying this again in the hopes that the web assembler version of the emulator works better than the windows version. I changed the code so there's no subfolders anymore. Here's the zip file:
INDY.zip
(7.5 MiB) Downloaded 561 times
And to try it now:
Try It Now!

...and whaddya know, it works! The sound isn't perfect, a few very quiet hisses and pops, but it's way better than on the windows emulator. Now I think I want to try again at double the horizontal resolution, and see just what the limits of the X16 really are.
MooingLemur
Posts: 34
Joined: Sat Feb 19, 2022 4:44 pm

Re: PCM audio streaming error

Post by MooingLemur »

I think this is an issue particular to hostfs emulation on x16emu. Running it from an sdcard image is much closer to how it behaves on hardware.

It does run smoothly on hardware btw.

R42 does have an issue with the emu warping after a load which causes audio to bunch up and play fast for the first split second. This has been fixed in current master, but there are still problems that show up in situations like this demo. Lazy load in Calliope also stutters while it's loading the song in the background.
Ed Minchau
Posts: 503
Joined: Sat Jul 11, 2020 3:30 pm

Re: PCM audio streaming error

Post by Ed Minchau »

MooingLemur wrote: Mon Apr 10, 2023 7:44 am I think this is an issue particular to hostfs emulation on x16emu. Running it from an sdcard image is much closer to how it behaves on hardware.

It does run smoothly on hardware btw.

R42 does have an issue with the emu warping after a load which causes audio to bunch up and play fast for the first split second. This has been fixed in current master, but there are still problems that show up in situations like this demo. Lazy load in Calliope also stutters while it's loading the song in the background.
Thanks for verifying that it works on the real hardware. Did you just try the version in this thread, or the one with double the video resolution in the r42 video demo thread?
MooingLemur
Posts: 34
Joined: Sat Feb 19, 2022 4:44 pm

Re: PCM audio streaming error

Post by MooingLemur »

I've found the issue. I mentioned the resolution in the "bug" thread, but I'll duplicate it here.
Screenshot from 2023-04-12 06-15-12.png
Screenshot from 2023-04-12 06-15-12.png (31.25 KiB) Viewed 5530 times
The hostfs intercept will advance the 6502 clock count by a value based on the elapsed wall clock time. MACPTR often exceeds 255 clocks worth of time, and *may* exceed 65535, however unlikely. This change fixes running INDY.PRG from hostfs.

This change has been merged into master.
Last edited by MooingLemur on Wed Apr 12, 2023 6:57 am, edited 1 time in total.
MooingLemur
Posts: 34
Joined: Sat Feb 19, 2022 4:44 pm

Re: PCM audio streaming error

Post by MooingLemur »

Ed Minchau wrote: Wed Apr 12, 2023 5:31 am
Thanks for verifying that it works on the real hardware. Did you just try the version in this thread, or the one with double the video resolution in the r42 video demo thread?
Only the version from this thread so far.
Post Reply