Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound issue on pi3 clone (le potato) #295

Open
DrDecagon opened this issue Jun 8, 2023 · 16 comments
Open

Sound issue on pi3 clone (le potato) #295

DrDecagon opened this issue Jun 8, 2023 · 16 comments

Comments

@DrDecagon
Copy link
Contributor

DrDecagon commented Jun 8, 2023

With the shortage of affordable Raspberry Pi hardware, I've decided to try Le Potato. (Libre Computers Pi 3B+ clone) This board is Raspbian compatible, has the same cores with higher clocks, and more/faster ram than the official Pi 3B+.

This game used to work on the Pi 3 but some have mentioned performance issues.
#182
#226

I have gotten the game successfully installed and the controllers paired, but sound does not work (it works fine before installing). Often I cannot connect more than 4 or 5 controllers. CPU utilisation is completely maxed out all the time.

I have tried Raspbian 10 (both ARMv6 and v8), Raspbian 11, and some straight Debian builds. I have also tried headless images to try to make things as lite as possible. I've tried altering the setup.sh in the old v2.0 release of joustmania to account for slightly different repos available on Le Potato.

Can anyone confirm this still works on the Pi 3B or has anyone gotten it to work on Le Potato?

@DrDecagon
Copy link
Contributor Author

DrDecagon commented Jun 9, 2023

A couple chunks of the log file

fatal: detected dubious ownership in repository at '/home/pi/JoustMania'
To add an exception for this directory, call:

        git config --global --add safe.directory /home/pi/JoustMania
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>
fatal: detected dubious ownership in repository at '/home/pi/JoustMania'
To add an exception for this directory, call:

        git config --global --add safe.directory /home/pi/JoustMania

Ran
sudo git config --global --add safe.directory /home/pi/JoustMania
as instructed, which resolved the above error. Is this for auto updates?

Press CTRL+C to quit
logname: no login name
Process Process-4:
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "/home/pi/JoustMania/piaudio.py", line 132, in audio_loop
    format=alsaaudio.PCM_FORMAT_S16_LE, periodsize=PERIOD, device='default')
alsaaudio.ALSAAudioError: Device or resource busy [default]
ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred

And the audio error. I have tried installing pulse, but it dosen't seem to resolve the issue.
Without the game installed, pushing sound to alsa works just fine. Le potato uses I2S rather than PCM for control (but not transmission?) of audio sent to the 3.5mm jack codec. Testing wav files included with the game works fine when the game isn't running, so I don't think its a PCM_format issue.

@DrDecagon DrDecagon changed the title Performance issue on pi3 clone (le potato) Sound issue on pi3 clone (le potato) Jun 12, 2023
@DrDecagon
Copy link
Contributor Author

DrDecagon commented Jun 14, 2023

So I'm trying to see if there are 2 sound operations happening at once when starting the program.

It appears that piaudio.py

def InitAudio():
    pygame.mixer.init(47000, -16, 2 , 4096)

does initialize the audio settings. Changing these values changes the output to the soundcard.

cat /proc/asound/card0/pcm0p/sub0/hw_params

access: MMAP_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 48000 (48000/1)
period_size: 4160
buffer_size: 12480

I've experimented using different settings such as using 48000 or 44100. Both settings result in RW_INTERLEAVED being output instead of MMAP. It appears that the InitAudio is started from both update.py and piparty.py.

@adangert
Copy link
Owner

Interesting work! There might be some settings that could improve performance, the period might also work, Joustmania did used to run on a pi3, but the modules have been updated since then too. One way that could also work is to have a setting in the yaml settings that disables the audio changing speeds, thus reducing the load on the cpu.

@DrDecagon
Copy link
Contributor Author

Thanks! I've commented out all calls to update.py and all references to performing updates. It does not appear to be an issue with the update.py conflicting with piparty. But I'm still not sure I completely understand everything.

I'll try messing with the audio speed change, but cpu seems to be maxed out even in the menu before those speed changes would happen.

@DrDecagon
Copy link
Contributor Author

DrDecagon commented Jun 15, 2023

So I've messed with audio a bit, voices are now working while background audio is not. Still getting
alsaaudio.ALSAAudioError: Device or resource busy [default]
Are the voices and the music given to separate mixers? (simultaneously trying to grab exclusive access)

Also, now when starting a match and then ending it, the system drops to only 80% CPU usage in the main menu and one of the 3 heaviest python3 processes disappears. Sometimes on game exit, things hang and a python process gets left running, killing it manually throws a piaudio error. It seems to confirm that the background audio is malfunctioning and is chewing up the CPU. Maybe preprocessing of audio?

@DrDecagon
Copy link
Contributor Author

DrDecagon commented Jun 15, 2023

I have tried running pulseaudio in system-wide mode and now /proc/asound/card0/pcm0p/sub0/hw_params reads

MMAP_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 44096
buffer_size: 88192

This is consistent with what I would expect from pulseaudio. However, I still see the "Device or resource busy" error.

The strange thing is that if I set device = alsaaudio.PCM(device='null') in piaudio.py, the busy error goes away as expected HOWEVER, the narrator and sound effects STILL PLAY. How can this be if I have set the sound device to null? Are the sound effects and voices using different code (sound mixer) than the background music?

@adangert
Copy link
Owner

The sound effects and narrator are using pygame to play them, that's probably why you are seeing that I would think!

@DrDecagon
Copy link
Contributor Author

DrDecagon commented Jun 16, 2023

I tried using system libraries instead of venv, with varying results. I tried feeding pygame.mixer.init(47000, -16, 2, 4096, devicename='null') but couldn't get it to accept any device names I threw at it when in the virtual env. It will accept some names when using system libraries, but it doesn't seem to make changes (system libraries are up to date). This would be the elegant solution if I could get it to work.

Eventually I tried just forcing dmix systemwide via /etc/asound.conf. This works!!, but narration is a little scratchy. Now that I understand what is happening, I'll test out some different configs to see what performs best.

EDIT: I got everything working on my fork.

@ntappin
Copy link

ntappin commented Jul 25, 2023

Interesting work! There might be some settings that could improve performance, the period might also work, Joustmania did used to run on a pi3, but the modules have been updated since then too. One way that could also work is to have a setting in the yaml settings that disables the audio changing speeds, thus reducing the load on the cpu.

Does this mean it will no longer work on the Pi 3? I've been trying to run it on one, and it reboots after install, but nothing happens.

@DrDecagon
Copy link
Contributor Author

DrDecagon commented Jul 26, 2023

I'm running this on an AML-S905X-CC which is roughly equivalent to a Pi 3b+. It works but maxes out the cpu at all times. Try running the top command and see if there are multiple Python processes running near the top of that list. If so, try connecting a move controller, it should light up white, even if you have no sound. If that works, I have a workaround if it's only a sound issue.

@adangert
Copy link
Owner

I don't think there is anything theoretically stopping it from running on a pi3, I have only tested on pi4s since they launched. @DrDecagon may have the closest solution. The cpu is usually maxed on a pi4 as well.

Also recently the price of pi4s has started to decrease! Hopefully this is a trend

@ntappin
Copy link

ntappin commented Jul 26, 2023

I noticed the prices had dropped too, so I picked up a pi4 since it seemed like it would run better there anyway.

I'm able to run the ./setup.sh command and it successfully reboots, however it doesn't reboot into the game, and controllers don't pair.

Is there another command I should be running to get the game to run?

@adangert
Copy link
Owner

You can try sudo ./joust.sh to run joust in a terminal and see if there are any issues(this also could be why it's not running on the pi3 at the moment)

@ntappin
Copy link

ntappin commented Jul 27, 2023

That did it thanks! Now to fix the sound issue. I've got controllers paired, but no sound yet.

@adangert
Copy link
Owner

A simple solution that might work, is making sure that the audio output is through the headphone jack(usually the top right corrner of the screen there is a sound option) and that you have headphones plugged in too.

@ntappin
Copy link

ntappin commented Jul 27, 2023

That did the trick! Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants