Gambatte 0.5.0-wip2 released

Announce new emulators, discuss which games run best under each emulator, and much much more.

Moderator: General Mods

Post Reply
byuu

Post by byuu »

Perhaps it's time for a dedicated pulseaudio engine after all. Yet another audio API to support.
Lucky number five. Posted this in another thread, thought you might like to give it a try.

http://0pointer.de/lennart/projects/pul ... 6c26206689

Code: Select all

#include <pulse/simple.h> 

pa_simple *pa_server; 

bool init() { 
  pa_sample_spec spec; 
  spec.format = PA_SAMPLE_S16LE; 
  spec.channels = 2; 
  spec.rate = 2000000; // or 8000 ;)
  pa_server = pa_simple_new(0, "gambatte::pulseaudio", PA_STREAM_PLAYBACK, 0, "audio", &spec, 0, 0, 0); 
  return pa_server; 
} 

void write(uint16_t *data, unsigned length_in_bytes) { 
  int error; 
  pa_simple_write(pa_server, (void*)data, length_in_bytes, &error); 
} 

void term() { 
  if(pa_server) { 
    pa_simple_free(pa_server); 
    pa_server = 0; 
  } 
}
Should be a simple, blocking PulseAudio driver. I'll mess with a non-blocking one later.

Enjoy the double latency of a sound server ;)
But the case of resampling from ~2 MHz to ~44 kHz is much harder than the case of resampling from 32 kHz to ~44 kHz.
Very true, my resampling is infinitesimal by comparison. Amazing that the GB can generate a 2 MHz signal. Seems absurdly excessive.
even more if you go from 2 MHz to 8 kHz.
May I ask why you drop to 8KHz, instead of eg 48KHz? Not like it's going to make a world of difference starting from 2MHZ ...
I haven't. It would mean yet another video engine option, but if it often works better it'd be well worth it.
I haven't had much success with it in the past, so it may not be worth the effort to even try. Just an idea.
DOLLS (J) [!]
ZNES Developer
Posts: 215
Joined: Mon Aug 02, 2004 11:22 pm

Post by DOLLS (J) [!] »

sinamas wrote:That's two taps in total and a triangular weighing function. All FIR filters can in fact be seen as being linear, which is why I chose to specify the number of taps in that one. The word linear is often used ambiguously.
I see, so this means you could have named it all the same if it were a two tap windowed sinc filter?
sinamas
Gambatte Developer
Gambatte Developer
Posts: 157
Joined: Fri Oct 21, 2005 4:03 pm
Location: Norway

Post by sinamas »

byuu wrote:Amazing that the GB can generate a 2 MHz signal.
Well, a 4 MHz clock means 8 MHz voltage changes, so it's not all that amazing.
byuu wrote:May I ask why you drop to 8KHz, instead of eg 48KHz? Not like it's going to make a world of difference starting from 2MHZ ...
Because it results in more than 48/8 = 6 times the noise, since all the aliasing wraps over a smaller area which is all audible. Oh, and check my edit on the previous page if you're testing.
DOLLS (J) [!] wrote:I see, so this means you could have named it all the same if it were a two tap windowed sinc filter?
Well it would still be linear in the convolution sense (each output sample is a linear combination of input samples), but the weighing wouldn't be linear.
Last edited by sinamas on Tue Oct 28, 2008 7:52 pm, edited 1 time in total.
byuu

Post by byuu »

Because it results in more than 48/8 = 6 times the noise, since all the aliasing wraps over a smaller area which is all audible.
More space for precision = more noise? So then, why not use 4KHz? x.x
I take it there must be some odd rule where 8KHz is the minimum to preserve all sound, yet 2MHz is the internal rate. Very confusing.
I can stop bugging you and read a book on this if you'd prefer, heh.
sinamas
Gambatte Developer
Gambatte Developer
Posts: 157
Joined: Fri Oct 21, 2005 4:03 pm
Location: Norway

Post by sinamas »

byuu wrote:
Because it results in more than 48/8 = 6 times the noise, since all the aliasing wraps over a smaller area which is all audible.
More space for precision = more noise? So then, why not use 4KHz? x.x
I take it there must be some odd rule where 8KHz is the minimum to preserve all sound, yet 2MHz is the internal rate. Very confusing.
I can stop bugging you and read a book on this if you'd prefer, heh.
What? No, I meant for testing. For playing games you should use something above 40 kHz. Whatever is native to your sound card probably. I meant that the difference between resampling methods will be more obvious if you do listening tests at that rate, or an even lower rate for that matter.
franpa
Gecko snack
Posts: 2374
Joined: Sun Aug 21, 2005 11:06 am
Location: Australia, QLD
Contact:

Post by franpa »

sinamas wrote:
franpa wrote:randomly the video will sync to a different refresh other then 60hz, I don't know why it happens but it happens while playing Zelda OoA and the only way to get it to sync with 60hz again for a while is to restart the emu.
There's probably little I can do. A lot of hardware/drivers have vsync issues all on their own. Sometimes you can get more stable behavior by enabling page flipping (only affects full screen). Vsync depends on the video driver being able to stably wait/block until the start of vblank each frame, and on getting a decent estimate of the current actual sample rate from the sound engine. Oh, and on the actual sample rate and refresh rate actually being reasonably close to the nominal value. For instance the windows video drivers on my laptop give me a 62.3 Hz refresh rate while reporting a nominal rate of 60 Hz, as well as missing vblank a lot unless page flipping is active.
When playing the Thwomp boss in Zelda OoA, the emulation will randomly slow down. loading a savestate resolves the slowness. CPU Usage spikes at 20% during the slow period.

the GQS file is the savestate? (so I can share it)
Core i7 920 @ 2.66GHZ | ASUS P6T Motherboard | 8GB DDR3 1600 RAM | Gigabyte Geforce 760 4GB | Windows 10 Pro x64
sinamas
Gambatte Developer
Gambatte Developer
Posts: 157
Joined: Fri Oct 21, 2005 4:03 pm
Location: Norway

Post by sinamas »

franpa wrote:When playing the Thwomp boss in Zelda OoA, the emulation will randomly slow down. loading a savestate resolves the slowness. CPU Usage spikes at 20% during the slow period.

the GQS file is the savestate? (so I can share it)
Doesn't happen here. Does it still happen if you disable sync to vblank, and use the null audio engine?
Does the slowdown always occur immediately if you load a save state that was saved during slowdown?
Yes, the .gqs-file is the save state file. If this issue is game-specific it could be useful to share it.
You may also want to set thread affinity so that gambatte is tied to one core, in case of tsc drift, but that hopefully shouldn't be an issue.
franpa
Gecko snack
Posts: 2374
Joined: Sun Aug 21, 2005 11:06 am
Location: Australia, QLD
Contact:

Post by franpa »

sinamas wrote:Does the slowdown always occur immediately if you load a save state that was saved during slowdown?
It occurs during normal play. Loading a savestate immediately solves the lag, so if i save then load, the issue vanishes instantly. I will answer the other questions as I test them out.
Core i7 920 @ 2.66GHZ | ASUS P6T Motherboard | 8GB DDR3 1600 RAM | Gigabyte Geforce 760 4GB | Windows 10 Pro x64
kick
Trooper
Posts: 550
Joined: Wed Mar 01, 2006 8:47 pm

Post by kick »

Just 5 minutes of testing and I already found a few nasty issues in the Win32 build :)

- Moving the window while Gambatte is running produces an awful stuttering noise while the emulation is temporarily halted during the process.Even a single click on the title bar is enough to produce a bad hiccup.
Even worse,mousing through the menu bar options while the emulation is running (occasionally) results in sound skips or brief pauses.
I haven't seen such 'features' in any (GB/GBA) emulator so far.
It gets really annoying after a while.

- Enabling VSync in windowed mode results in 100% CPU load. This happens with the OpenGL and DirectDraw renderers,but not with Direct3D. (tested with an ATI card)

- When using the Direct3D renderer there's a graphical glitch known as the 'triangle boundary screen distortion'. It's a well-known glitch that was once present in VBA-M but has been fixed since I reported it not long ago.There's no such problem with the other renderers.Only D3D is affected.

Here's a screenshot of the problem:
Image
Last edited by kick on Wed Oct 29, 2008 10:57 am, edited 7 times in total.
[i]Have a nice kick in da nutz[/i] @~@* c//
franpa
Gecko snack
Posts: 2374
Joined: Sun Aug 21, 2005 11:06 am
Location: Australia, QLD
Contact:

Post by franpa »

I assume your not on windows? I only get the DirectDraw renderer.
Core i7 920 @ 2.66GHZ | ASUS P6T Motherboard | 8GB DDR3 1600 RAM | Gigabyte Geforce 760 4GB | Windows 10 Pro x64
kick
Trooper
Posts: 550
Joined: Wed Mar 01, 2006 8:47 pm

Post by kick »

You should have at least 3 of the 4 possible renderers (DirectDraw,Direct3D[9],OpenGL and QPainter) available on Windows.

Looks like your drivers or DirectX is FUBAR'd.
Last edited by kick on Wed Oct 29, 2008 9:58 am, edited 1 time in total.
[i]Have a nice kick in da nutz[/i] @~@* c//
franpa
Gecko snack
Posts: 2374
Joined: Sun Aug 21, 2005 11:06 am
Location: Australia, QLD
Contact:

Post by franpa »

Probably just the geforce 180.43 drivers being fucked... they also cause display to revert to 4bit colour when playing Black & White 1... aside from B&W1, I have had no issues with OpenGL, Direct Draw and Direct 3D games.

I guess the problem with these drivers is bigger then suspected. Oh and yes, I follow proper driver installation guidelines which I have noted here. http://forums.nvidia.com/index.php?showtopic=80421

EDIT: bah I AM getting 4 display renderers... I either keep overlooking things or something is wacked out on my pc and things change for no reason.
Core i7 920 @ 2.66GHZ | ASUS P6T Motherboard | 8GB DDR3 1600 RAM | Gigabyte Geforce 760 4GB | Windows 10 Pro x64
sinamas
Gambatte Developer
Gambatte Developer
Posts: 157
Joined: Fri Oct 21, 2005 4:03 pm
Location: Norway

Post by sinamas »

kick wrote:- Moving the window while Gambatte is running produces an awful stuttering noise while the emulation is temporarily halted during the process.Even a single click on the title bar is enough to produce a bad hiccup.
That's a Qt bug if anything. Working around it would require a lot of work and added latency and complexity. Well, unless I can find some kind of clever hack.
kick wrote:Even worse,mousing through the menu bar options while the emulation is running results in sound skips or brief pauses.
I haven't seen such 'features' in any (GB/GBA) emulator so far.
Extremely annoying.
Try using a bigger buffer size. Or perhaps I should provide a non-smooth video option that always pushes as much audio as it can, not caring about a smooth frame rate.
kick wrote:- Enabling VSync in windowed mode results in 100% CPU load. This happens with the OpenGL and DirectDraw renderers,but not with Direct3D. (Tested with an ATI card)
Go bug ATI.
kick wrote:- When using the Direct3D renderer there's a graphical glitch known as the 'triangle boundary screen distortion'. It's a well-known glitch that was once present in VBA-M but has been fixed since I reported it not long ago.There's no such problem with the other renderers.Only D3D is affected.
Why does this only happen on ATI cards anyway? I'd say it's an ATI bug, since it deviates from the reference renderer. Chances are we can forget about ATI fixing things, and will have to work around it on the application side.

Microsoft DirectX reference renderer:
Image
kick
Trooper
Posts: 550
Joined: Wed Mar 01, 2006 8:47 pm

Post by kick »

NOTE: That test was done with a 'vintage' ATI card.I don't think you will ever see a new driver update from AMD for R200 cards and below.

Now I'll do some testing on another machine with a modern (Radeon HD4000 series) card with the latest drivers and see if ATI/AMD has (finally?) fixed the problem with its current hardware.
[i]Have a nice kick in da nutz[/i] @~@* c//
franpa
Gecko snack
Posts: 2374
Joined: Sun Aug 21, 2005 11:06 am
Location: Australia, QLD
Contact:

Post by franpa »

btw, I may have simply mixed up the # of audio outputs with the # of video renderers... since there is indeed only 1 audio output mode. (2 if you count Null)

The audio issues when going through menu's does not happen for me at 68ms, 48khz.
Core i7 920 @ 2.66GHZ | ASUS P6T Motherboard | 8GB DDR3 1600 RAM | Gigabyte Geforce 760 4GB | Windows 10 Pro x64
kick
Trooper
Posts: 550
Joined: Wed Mar 01, 2006 8:47 pm

Post by kick »

franpa wrote:The audio issues when going through menu's does not happen for me at 68ms, 48khz.
Looks like I'll have to retest this again on XP w/SP2 (installing SP3 can degrade your audio performance) and Linux/Wine.
[i]Have a nice kick in da nutz[/i] @~@* c//
franpa
Gecko snack
Posts: 2374
Joined: Sun Aug 21, 2005 11:06 am
Location: Australia, QLD
Contact:

Post by franpa »

sp3 does that? o_O

edit: zelda OoA savestate @ the boss. just play around and eventually during the boss fight it will start slowing down,. it will be slight at first, but will randomly become very slow.

Mediafire seems to be struggling lately so don't be surprised if the download fails. try to get it later if it does fail.
http://www.mediafire.com/?nlgz15zznmw
Core i7 920 @ 2.66GHZ | ASUS P6T Motherboard | 8GB DDR3 1600 RAM | Gigabyte Geforce 760 4GB | Windows 10 Pro x64
sinamas
Gambatte Developer
Gambatte Developer
Posts: 157
Joined: Fri Oct 21, 2005 4:03 pm
Location: Norway

Post by sinamas »

I've been playing around for the last half hour without any sign of slowdown. Anyone else able to reproduce this? You can load the save state by using the "Load State From" option, or copying the file to the save directory and renaming it to match your ROM image name if needed.
franpa
Gecko snack
Posts: 2374
Joined: Sun Aug 21, 2005 11:06 am
Location: Australia, QLD
Contact:

Post by franpa »

it "may" be isolated to the core 2 duo range of processors. it seems to be related to when the boss head spins around from being attacked and it may be accumulative.

EDITED.
Core i7 920 @ 2.66GHZ | ASUS P6T Motherboard | 8GB DDR3 1600 RAM | Gigabyte Geforce 760 4GB | Windows 10 Pro x64
sinamas
Gambatte Developer
Gambatte Developer
Posts: 157
Joined: Fri Oct 21, 2005 4:03 pm
Location: Norway

Post by sinamas »

franpa wrote:it "may" be isolated to the core 2 duo range of processors.
What makes you say that? Did you try setting thread affinity? I did my testing on a laptop with a Core 2 Duo T8100. Anyway, it would be weird for a platform-specific issue to be game-dependent, and it would be even weirder for an emulation issue to be platform-specific, so I'm not sure what to make of this. Are you sure this doesn't happen in other games too? I'm still completely unable to reproduce this.
byuu

Post by byuu »

Even worse,mousing through the menu bar options while the emulation is running (occasionally) results in sound skips or brief pauses. I haven't seen such 'features' in any (GB/GBA) emulator so far. It gets really annoying after a while.
'features' in quotes -- you are quite the demanding user, I must say.

Just curious here ... other than the "other programs do it" argument -- why do you even expect that to work well? It requires multi-threading right off the bat as Windows locks the thread that calls Get/PeekMessage() once the menubar is clicked on, and the OS itself tends to eat up a lot of resources drawing the menus and such. It'd require quite a bit more buffering (eg latency) to avoid, which is probably what other programs do. That, or as sinamas said, it could be a Qt-specific issue that raw Win32 programming avoids.

How often do you run through the menu when playing a game, anyway? I've never heard anyone complain about what happens when you're navigating menus. Half of the emulators I use pause the emulation while in them.
- When using the Direct3D renderer there's a graphical glitch known as the 'triangle boundary screen distortion'. It's a well-known glitch that was once present in VBA-M but has been fixed since I reported it not long ago.There's no such problem with the other renderers.Only D3D is affected.
I can confirm that's an ATI driver bug. Though I would be curious if anyone knows what the "workaround" is to compensate, since a lot of people like to blame app developers for driver bugs; that in all honesty, should not be worked around. Deviating from the reference renderer just encourages the driver manufacturers to be lazy.
kick
Trooper
Posts: 550
Joined: Wed Mar 01, 2006 8:47 pm

Post by kick »

---------------------------------------------
ATI drivers and emulation - Part 1
---------------------------------------------

Finally,I've finished testing with the new ATI cards.It took a while,since I used multiple PCs with different ATI cards and drivers.

Unlike the previous report (in which I've used a a legacy card),this time we have the newest HD2k - HD4k cards and the latest Catalyst drivers.
Let's see how modern ATI cards cope with emulation.

Firstly,the Direct3D TBD issue is gone:
Image
Now that's a step in the right direction for ATI/AMD :)

But you should know that the workaround is still needed for pre-R300 cards,since ATI won't *ever* update their drivers for legacy cards (unlike nVidia who cares about legacy support)

Stay tuned for Part 2 :)
Last edited by kick on Sat Nov 01, 2008 3:35 am, edited 2 times in total.
[i]Have a nice kick in da nutz[/i] @~@* c//
kick
Trooper
Posts: 550
Joined: Wed Mar 01, 2006 8:47 pm

Post by kick »

-------------------------------------------
ATI Drivers and Emulation - Part 2
-------------------------------------------

Back with some more ATI driver goodness :)

- When using the D3D renderer and enabling one of the HQxX filters,you get this:
Image
Ugh!

Doesn't happen with the other renderers.

- 100% CPU munch when running in windowed mode using DirectDraw or OpenGL with VSync :( Same as with their 2-year old drivers for legacy cards.Unbelievable! :(

bgb doesn't have this problem.The emulation runs silky smooth with no CPU munch.The smoothness with VSync on is near-perfect.

Coming up - Part 3 ;)
Last edited by kick on Sat Nov 01, 2008 3:39 am, edited 3 times in total.
[i]Have a nice kick in da nutz[/i] @~@* c//
kick
Trooper
Posts: 550
Joined: Wed Mar 01, 2006 8:47 pm

Post by kick »

Before we move on to Part 3,I'd like to report a few DMG core bugs in the latest version of Gambatte:

- The first three lines of the displayed image are flashing when a sprite touches them.A lot of games are affected.

Beetlejuice extracted from bgb or the real hardware:
Image

Gambatte and the bug that needs to be turned into juice :D :
Image

A screenshot of LoZ:Link's Awakening - Gambatte displays the same glitch:
Image

- Kid Icarus: Just after the opening story scrolls to the end and the title screen appears,part of the 'Kid Icarus' fonts appear briefly at the bottom of the screen as tile garbage.

In case anybody wants the bgb settings file I've been using in this test,you can get it from here:
http://stashbox.org/280719/bgb.ini


It's been tweaked for highest emulation accuracy.
There's even a tweaked DMG palette as a bonus :)
Last edited by kick on Sat Nov 01, 2008 3:48 am, edited 14 times in total.
[i]Have a nice kick in da nutz[/i] @~@* c//
franpa
Gecko snack
Posts: 2374
Joined: Sun Aug 21, 2005 11:06 am
Location: Australia, QLD
Contact:

Post by franpa »

Kick, you DO know that the Nvidia 180 driver series drops support for anything below the 8 series of cards? I wouldn't call that backwards support, hell they dropped support for the tnt2 and riva cards ages ago too.
Core i7 920 @ 2.66GHZ | ASUS P6T Motherboard | 8GB DDR3 1600 RAM | Gigabyte Geforce 760 4GB | Windows 10 Pro x64
Post Reply