Didero / ThimbleMonkey

An early version of a Python / PySide6 graphical program to view Return To Monkey Island files (and hopefully Thimbleweed Park files later)
Other
0 stars 0 forks source link

Unable to play sounds #3

Closed legendofmi closed 1 year ago

legendofmi commented 1 year ago

I recently downloaded the latest version to try out the music and sounds but none seem to work. When I selected the file and pressed play nothing seems to happen. The length of the sounds remains the same. Same behaviour when compiling it myself on macOS or running it on Windows 11 with the already compiled executable.

legendofmi commented 1 year ago

Checked the terminal and it seems the vorbis library could not be loaded: qt.pointer.dispatch: skipping QEventPoint(id=1 ts=0 pos=0,0 scn=913.426,771.867 gbl=913.426,771.867 Released ellipse=(1x1 ∡ 0) vel=0,0 press=-913.426,-771.867 last=-913.426,-771.867 Δ 913.426,771.867) : no target window Traceback (most recent call last): File "/Users/user/Downloads/ThimbleMonkey-main/ui/widgets/SoundBankDisplayWidget.py", line 50, in _onSampleSelected parsedSample = bytes(self._soundbank.rebuild_sample(sampleToLoad)) File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/fsb5/__init__.py", line 211, in rebuild_sample from . import vorbis File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/fsb5/vorbis.py", line 12, in <module> vorbis = load_lib('vorbis') File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/fsb5/utils.py", line 76, in load_lib raise LibraryNotFoundException("Could not load the library %r" % (names[0])) fsb5.utils.LibraryNotFoundException: Could not load the library 'vorbis'

Didero commented 1 year ago

I had hoped MacOS had better inate support for Ogg Vorbis... I've added a new point to the end of 'Initial setup' section readme describing how to install that support. Please let me know if it works!

legendofmi commented 1 year ago

Didn't work on either. Same result as before on macOS and Windows.

On macOS I installed ogg and vorbis via homebrew: user@User-Air ~ % brew install libogg ==> Fetching libogg ==> Downloading https://ghcr.io/v2/homebrew/core/libogg/manifests/1.3.5 ######################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebrew/core/libogg/blobs/sha256:f18fefb04d1 ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh ######################################################################## 100.0% ==> Pouring libogg--1.3.5.arm64_ventura.bottle.tar.gz 🍺 /opt/homebrew/Cellar/libogg/1.3.5: 97 files, 513.2KB ==> Running `brew cleanup libogg`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

user@User-Air ~ % brew install libvorbis ==> Fetching libvorbis ==> Downloading https://ghcr.io/v2/homebrew/core/libvorbis/manifests/1.3.7 ######################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebrew/core/libvorbis/blobs/sha256:7c0b3250 ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh ######################################################################## 100.0% ==> Pouring libvorbis--1.3.7.arm64_ventura.bottle.tar.gz 🍺 /opt/homebrew/Cellar/libvorbis/1.3.7: 157 files, 2.4MB ==> Running `brew cleanup libvorbis`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

and the result I got was the same: Decoding to bytes after 17.983438207997096 seconds Traceback (most recent call last): File "/Users/user/Downloads/ThimbleMonkey-main/ui/widgets/SoundBankDisplayWidget.py", line 50, in _onSampleSelected parsedSample = bytes(self._soundbank.rebuild_sample(sampleToLoad)) File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/fsb5/__init__.py", line 211, in rebuild_sample from . import vorbis File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/fsb5/vorbis.py", line 12, in <module> vorbis = load_lib('vorbis') File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/fsb5/utils.py", line 76, in load_lib raise LibraryNotFoundException("Could not load the library %r" % (names[0])) fsb5.utils.LibraryNotFoundException: Could not load the library 'vorbis'

On Windows 11 I can't see the console so I don't know the error. I tried copying both dlls to the same folder as the exe and also to System32 with the same result. Note: I am running Windows 11 on Parallels.

Didero commented 1 year ago

After having spent hours learning more about Python ctypes than I'd hoped, it seems the OggVorbis library loading code of the FSB soundbank library I use for this is a bit wonky :/ If you happen to own Thimbleweed Park, can you open the files from that in ThimbleMonkey (You have to open the 'Resources' subfolder in the gamepath for that)? It has loose .ogg and .wav files, do those play successfully? Because if so, I'll have to rewrite the .bank file loading code to manually decode part of the soundbank.

legendofmi commented 1 year ago

I just downloaded and installed Thimbleweed Park and get an error when I open the OGG files on macOS. The WAV files work well. The OGG files play well on Windows 11.

Note: I have python3 installed and is NOT 32bit. I am running it on a Macbook Air with M1 chip (Apple Silicon). Checking the libraries https://formulae.brew.sh/formula/libvorbis and https://formulae.brew.sh/formula/libogg it seems they are supported by M1.

Screenshot 2022-12-30 at 15 11 51
Didero commented 1 year ago

After some more searching and trying, the problem may be that Homebrew installs the packages outside the virtual environment created in step 4 of the set-up. Please try this:

I really really hope this works, but if it doesn't, I'll keep searching for a solution. Please let me know, and thanks a lot for all your help so far!

legendofmi commented 1 year ago

Didn't work. With Return to Monkey Island I got the following error: Traceback (most recent call last): File "/Users/user/Downloads/ThimbleMonkey-main/ui/widgets/SoundBankDisplayWidget.py", line 50, in _onSampleSelected parsedSample = bytes(self._soundbank.rebuild_sample(sampleToLoad)) File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/fsb5/__init__.py", line 211, in rebuild_sample from . import vorbis File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/fsb5/vorbis.py", line 12, in <module> vorbis = load_lib('vorbis') File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/fsb5/utils.py", line 76, in load_lib raise LibraryNotFoundException("Could not load the library %r" % (names[0])) fsb5.utils.LibraryNotFoundException: Could not load the library 'vorbis' Traceback (most recent call last): File "/Users/user/Downloads/ThimbleMonkey-main/ui/widgets/SimpleSoundPanel.py", line 80, in _playSound raise NotImplementedError(f"Playing sound for the '{self._fileExtension}' sound format is not supported") NotImplementedError: Playing sound for the '' sound format is not supported

With Thimbleweed Park I got the following: Traceback (most recent call last): File "/Users/user/Downloads/ThimbleMonkey-main/ui/MainWindow.py", line 130, in loadFileFromFileBrowser self.showFileData(fileEntryToLoad) File "/Users/user/Downloads/ThimbleMonkey-main/ui/MainWindow.py", line 155, in showFileData widgetToShow = SoundDisplayWidget(fileEntryToShow, dataToShow) File "/Users/user/Downloads/ThimbleMonkey-main/ui/widgets/SoundDisplayWidget.py", line 11, in __init__ self._soundPanel = SimpleSoundPanel(audioData, fileEntry.fileExtension, True) File "/Users/user/Downloads/ThimbleMonkey-main/ui/widgets/SimpleSoundPanel.py", line 36, in __init__ self.setAudioData(audioData, fileExtension, shouldAutoplay, title) File "/Users/user/Downloads/ThimbleMonkey-main/ui/widgets/SimpleSoundPanel.py", line 52, in setAudioData self._soundFile = pyogg.VorbisFile(tempFile.fileName()) File "/Users/user/Downloads/ThimbleMonkey-main/venv/lib/python3.10/site-packages/pyogg/__init__.py", line 24, in __init__ raise PyOggError("The Ogg library wasn't found or couldn't be loaded (maybe you're trying to use 64bit libraries with 32bit Python?)") pyogg.pyogg_error.PyOggError: The Ogg library wasn't found or couldn't be loaded (maybe you're trying to use 64bit libraries with 32bit Python?)

Didero commented 1 year ago

I had to fight with a Linux Mint virtual machine for most of the day, but I changed and added some readme steps. Could you try deleting your 'venv' folder entirely and following them from the start again, please?

And if that doesn't work, maybe the PyOgg library is getting confused by your computer being Apple Silicon. If so, could you navigate to ThimbleMonkey-main/venv/lib/python3.10/site-packages/pyogg, see if there's a subfolder called 'libs' there, and if so, deleting it, and then trying to open a Thimbleweed Park .ogg and Return To Monkey Island soundbank file again? That's more a workaround than a fix, but if it works, it'd at least give an idea of what the cause of this problem even is.

legendofmi commented 1 year ago

I got an error with the first command: user@User-MacBook-Air ~ % sudo apt install python3-pip Password: The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt. Please visit http://www.java.com for information on installing Java. I installed Java and restarted the machine, but still had the same error.

I tried compiling it without those additional steps ("apt"), but got exactly the same error when trying to play OGG files. I quit the app and deleted the folder "libs" you mentioned and no change, the same errors again.

Didero commented 1 year ago

Aw shoot, I didn't realise MacOS doesn't have the 'apt' command, sorry. Skip that step then. I've updated the readme again. Did you try the second part of my message, about deleting the 'libs' subfolder?

legendofmi commented 1 year ago

Thanks for the help. I did try, but no luck (check the previous comment).

Didero commented 1 year ago

Oh sorry, I must've missed your edit. I think the library I use for sound playback might just be incompatible with M1 Macs? That would be weird though. I'll keep digging, see if I can find a reason for this, because this is gonna keep nagging at me. Thanks again for all your testing help! I'll update this issue if I have any new ideas.

legendofmi commented 1 year ago

Do you mean PyOgg? I did find a similar issue of someone trying to use it to play OPUS files: https://github.com/TeamPyOgg/PyOgg/issues/97 In the comments he does mention a solution (commenting a few lines). I'm not expert enough to know what to do.

Didero commented 1 year ago

Oh, that's a good hint, thanks! I was searching for PyOgg problems with Ogg and Vorbis, but the issue you linked could be related. I've made my own copy of PyOgg with a possible fix for that linked issue. Could you download the latest code for ThimbleMonkey, follow the steps in the 'Updating' section of ThimbleMonkey's readme so the new PyOgg version should be downloaded and used, and then try to play an .ogg from Thimbleweed Park, and a sound from an .assets.bank soundbank from Return To Monkey Island? Hopefully at least the .ogg works, and with a bit of luck the soundbank sound too. But if at least the .ogg works, I've got a starting point for a fix.

legendofmi commented 1 year ago

Happy new year, and thanks again for your support. :)

Unfortunately, it didn't work. I even tried compiling it from scratch, but I got the same result as before and the same errors.

Didero commented 1 year ago

Happy new year to you too!

I tried another fix to my PyOgg fork, could you try updating and/or starting from scratch again? EDIT: Make sure you close and reopen your terminal since the last attempt, so there aren't any lingering settings

legendofmi commented 1 year ago

Sorry, didn't work after starting from scratch (including a new terminal window).

BTW, I believe there are two issues:

  1. macOS only: OGG files don't play. On Windows 11 I'm able to play Thimbleweed OGG files (using the already compiled executable)
  2. General: Return to Monkey Island bank files don't play which also happens on Windows 11.
Didero commented 1 year ago

I was so focussed on this MacOS problem that I forgot that to open the soundbanks on Windows, some extra DLLs are needed. I updated the readme.

I also spent most of yesterday and today setting up a MacOS VM to see if I could reproduce the error. And... I can't. For me it all works, playing a .ogg even worked before I installed libogg and libvorbis. So the problem must be with the combination of Homebrew, M1, and Python. When you installed Homebrew, it should have ended with a message saying "Next steps:" and then two commands to run, something like echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> ~/.zprofile and "eval $(/opt/homebrew/bin/brew shellenv)", but it may not have shown that if you've installed Homebrew a while ago. If it didn't show and/or you haven't run them command when installing Homebrew, could you try running those commands? That should hopefully help Python find the libraries, so after this, could you try opening an .ogg and .assets.bank again?

legendofmi commented 1 year ago

For Windows, you mean libvorbis.dll and libogg.dll? I have those next to the executable and it doesn't work either.

on macOs I tried adding that line eval "$(/opt/homebrew/bin/brew shellenv)" to ~/.zprofile but made no difference. I'll try to install homebrew again just in case.

Didero commented 1 year ago

The Windows executable already has those DLLs inside it, so that should already work. Adding the DLLs is only if you're running the Python script directly. It works for me on Windows 10, hopefully Windows 11 doesn't do anything weird... Guess I've got another VM to set up.

And for MacOS, adding a line to .zprofile requires restarting the terminal before it takes effect, did you do that too? Because otherwise I'm really running out of ideas...

legendofmi commented 1 year ago

I reinstalled homebrew and restarted the laptop afterwards, but still no luck. The .zprofile also looks good:

# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
export PATH
# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"

No really sure what I'm missing.

For Windows 11, I should point out that I'm running the Windows 11 ARM version. Not sure if that makes any difference. I never had any issues with other applications.

Didero commented 1 year ago

I've released a new version with the KTX export error fix that you also helped with. It includes a MacOS build from my x86 VM. Could you try running that, possibly through Rosetta 2, and see if that build does open and play sounds properly? It's not a fix for running the Python yourself, but if this works it'd at least be something for you and other M1 users.

As for the ARM version for Windows, I feel bad having to say it but I can't support that version, because I don't know how that works and I don't have a way to run it, sorry :(

legendofmi commented 1 year ago

I'm sorry to say it still doesn't work on either Thimbleweed or Return to Monkey Island.

Screenshot 2023-01-03 at 17 50 36

Also similar error on Windows 11 ARM (only for RtMI, works fine for Thimbleweed).

Screenshot 2023-01-03 at 18 01 23
Didero commented 1 year ago

Ok, I tried something a bit more drastic by re-implementing some code from a library I use. I made new Mac and Windows releases for it. It might not make it run on your M1 Mac (though I'm hoping it does, especially when run through Rosetta 2), but it should at least make it work on your ARM Windows, considering the RtMI bank playback now uses the same decoding as used with the loose .ogg files of Thimbleweed Park, and you said those worked. I'm curious to hear what works and doesn't work with this release!

legendofmi commented 1 year ago

On macOS, I can't open the app as I get an error.

Screenshot 2023-01-04 at 21 16 58

The good news is that on Windows 11 (ARM) it now works. Thanks for all your effort :)

Didero commented 1 year ago

Good to hear the Windows ARM version works now! And I uploaded a new Mac version, still called ThimbleMonkey0.1.2_Mac.zip. I had copied it to Windows before uploading, and apparently that breaks it, but that's fixed now, so you can try again.

legendofmi commented 1 year ago

Well done!! Now it also works on my macOS for both Thimbleweed Park and Return to Monkey Island. Thanks a lot for being persistent and fixing the issue. 👍

I only encountered a minor problem on macOS where I can't stop a sound while playing the audio (the stop button doesn't do anything). I need to wait for it to stop.

Didero commented 1 year ago

Oh, good to hear it works on ARM MacOS too now! I didn't expect that, so it's a nice bonus.

I had to change something in the soundbank parsing to fix a Windows-only crash, and I made a new release for it, could you perhaps quickly check if the sound parsing still works properly?

legendofmi commented 1 year ago

All (macOS and Windows) working now, including the stop button. Also, no more random crashes.

Didero commented 1 year ago

The stop button breaking and working is stil kind of weird, but I'm VERY glad everything is working now! Thanks so much for all your help with testing, I couldn't have fixed this otherwise!

I get to finally close this issue now, good feeling :)