mihaip / infinite-mac

A classic Mac loaded with everything you'd want
https://infinitemac.org
Apache License 2.0
1.2k stars 73 forks source link

Audio does not work in Mac OS 8 or Mac OS 9 #67

Closed mihaip closed 1 year ago

mihaip commented 2 years ago

Originally reported at https://github.com/mihaip/infinite-mac/issues/21#issuecomment-1094439387.

Sound control panel fails to open with "An unexpected error has occurred: 864"

mihaip commented 2 years ago

It looks like a lower level problem, almost none of the audio subsystem is initializes when running under Mac OS 8. The patches added by https://github.com/mihaip/macemu/blob/bas-emscripten-release/BasiliskII/src/rsrc_patches.cpp (specifically the thng and sift ones) are not being installed (those resources are never loaded), thus we're not hooking the Sound Manager.

This does not appear to be an issue in the native (Mac) build of Basilisk II with the same Mac OS 8 boot disk, will need to investigate where the differences are.

that-ben commented 1 year ago

Audio works for me now in macos9.app using the same ROM but slightly different System Folder files than what Infinite Mac is using. Although, the sound comes out as extremely choppy. It cuts very briefly twice every second, so it's unusable to listen to music or play games just yet. If you want to experiment and/or analyze which System Folder files I'm using, you can see it here: https://www.macintoshrepository.org/emulate_in_browser.php?macmodel=5&disk1=MacOS904.dsk

mihaip commented 1 year ago

@that-ben Interesting, thanks for the tip.

I downloaded your image and integrated it into my build process, and sound still did not work. I then changed it to not do the disk image rewriting (via the machfs library) and it began to work. In fact, without the rewriting my regular disk image works too.

It appears that it's not a lossless process, and some data is getting lost (this is not the first bug that I've fixed in it, see https://github.com/mihaip/machfs/commit/754b595ffd403534aa7af2fd01a30933ffcff3e5 and https://github.com/mihaip/machfs/commit/85eeb0b7ea129674913c3bd51659acc534b25a11). Will look into it more.

BTW, your instance of the emulator using the "fallback" mode when SharedArrayBuffer is not available. If you start setting the Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers docs (which may also change how you iframe the site) then it should run faster. The Cloudflare Worker that I use sets them at https://github.com/mihaip/infinite-mac/blob/2b462dcea988e4d4eff2df8f32f08d0116044b4f/workers-site/index.ts#L72-L73

You can tell that it's using fallback mode because there are a lot of requests to /worker-commands (which is the fallback mechanism that it uses to communicate when SharedArrayBuffer is not available)

that-ben commented 1 year ago

Merry Christmas to you Mihai!

Wow, thanks! I appreciate all this information. I did not realize it was running in fallback mode, but I did notice there's a TON of requests to worker-commands (approx. 20/sec).

MR is using the same CO policy as what you describe for another emulator (BasiliskII.js), but I did not realize SheepShaver.js also needed this, so I've added the CO policy to the .htaccess, but the 20 worker requests per second continue.

Header Set Cross-Origin-Embedder-Policy "require-corp"
Header Set Cross-Origin-Opener-Policy "same-origin"

Not sure if anything else needs to be done to opt out of the fallback mode?

mihaip commented 1 year ago

I believe the reason why Basilisk II is fine is because its iframe is in the same www.macintoshrepository.org origin (it uses https://www.macintoshrepository.org/emulate-in-browser/BasiliskII.js/).

SheepShaver on the other hand uses https://emulate-sheepshaverjs.macintoshrepository.org/ (subdomains are different origins).

that-ben commented 1 year ago

Oh yeah, that's true! DOH! :P Thx, will try to allow root to embed subdomain with CORS, see if it fixes it.

EDIT: Got it working correctly with adequate Cross-Origin Policy. Thx.

mihaip commented 1 year ago

Sound should be working now (under both Mac OS 8 and Mac OS 9), I've switched to an alternate implementation for injecting data into the system disk images that does not rely on machfs. I've filed #84 to track that corruption, in case I do end up wanting to use the library more in the future.