Jubatian / cuzebox

CUzeBox emulator
GNU General Public License v3.0
12 stars 2 forks source link

Toggle audio #4

Closed danboid closed 3 years ago

danboid commented 4 years ago

There doesn't seem to be any way to disable the audio currently, not without resorting to an external mixer.

I would like a -nosound switch and maybe the ability to toggle audio with one of the F keys - it looks like F1 and F6 aren't used by cuzebox yet.

Maybe disabling sound could lead to increased performance on low spec machines?

Jubatian commented 4 years ago

For the performance unfortunately audio wouldn't put a dent in it, it is very cheap, what the emulator does is about just sending samples from the PWM to the audio device with a very simple frequency scaling. The heavy hitter is the ATmega's emulation (28.6MHz! It is a magnitude more than any 80's 8-bitter's clock!), then the second heaviest hitter is transferring the canvas to the display (not the processing, the act of transferring the already calculated buffer to display within the libraries / drivers beyond the emulator, on Emscripten even at lowest settings, this takes half the CPU). On such hosts, switching to low resolution (F2) helps the most. Toggling frame merging off (F7) can also have noticeable effect, that's the only really costly filter in the emulator, but even this is typically negligible compared to the ATmega emulation or the transfer of the canvas to display.

It is very difficult to get it going any faster at this point, the ATmega emulation is insanely optimized, likely the fastest emulation of this microcontroller core (though nowhere near complete in peripherals, which of course helps a lot in performance).

The vague plans for F1 was a menu or help, and F6 was I think taking a memory snapshot for state saves.

danboid commented 4 years ago

Thanks for the explanation.

Extra performance was an afterthought - I really just want an easy way to mute the sound

Jubatian commented 4 years ago

It is possible to do, on Linux, you would have to create the following shell script in the directory where the cuzebox executable is:

#!/bin/sh export SDL_AUDIODRIVER='dummy' ./cuzebox $*

Name it something (for example cuzebox_nosound), make it executable (chmod 755 cuzebox_nosound), then you can use it to launch the emulator without sound, it will take parameters as usual.

On Windows something similar is possible with command line scripts, but I don't know how it should be formatted on that OS. The same environment variable needs to be set to the same "dummy" for the execution.

(Just a quick solution as it is doable this way with any version)