Ninoh-FOX / POCKETGO2_ROGUE_CFW

Oficial Firmware for POCKETGO 2, thanks to Vincent of Retromimi
https://retromimi.com/products/new-pocketgo
141 stars 12 forks source link

How to fix PCM (Speaker) loud volume (edit asound.conf) #29

Closed Shut3n closed 4 years ago

Shut3n commented 4 years ago

Hi,

I managed to enable "Master" volume control on the alsa-mixer by editing /etc/asound.conf (/etc on the rootfs.squashfs file)

==ROGUE ORIGINAL==

defaults.ctl.card 1;
defaults.pcm.card 1;

==REPLACE WITH THIS LINES==

pcm.!default  {
 type plug     
 slave.pcm "speakerphat"
}

ctl.!default {
 type hw card 1
}

pcm.speakerphat {
  type softvol
  slave.pcm "plughw:1"
  control.name "Master"
  control.card 1
}

I had to reboot the handheld. First I open any app-emulator that uses audio. Then go to "Sound Mixer" and a new virtual controller that works as "Master" appears. So it is fixable the PCM loud volume without any wiring or soldering necessary.

Volume Keys continue linked to PCM channel, but now you can set Master in a low position to fit your commodity.

Please check that is working for everyone. It worked for me on a Playgo with Rogue 1.0.4

I noticed that the configuration is restarted when I reboot the device. So I must do the "Open App"+ open "Sound Mixer" everytime I reinit the handheld. I need for the config to be permanent.

tgeorgiadis commented 4 years ago

How did you edit /etc/asound.conf?

idonda commented 4 years ago

is this a fix for loud volume at the minimum level (after mute)?

Shut3n commented 4 years ago

How did you edit /etc/asound.conf?

Before anything make a backup of original rootfs.squashfs on the sdcard, and make a copy that one to work with it.

I followed this steps:

1) Mount 'rootfs.squashfs' file on /mnt (file from the system SD card, SDCard1 on Playgo/PG2). 2) See that it mounts in read-only mode, so we need to make a copy of the directory containing the file we need to edit with cp -a '/mnt/etc' $HOME/destination/etc. 3) Once we finish to edit asound.conf, we merge /mnt and modified $HOME/destination/etc and create a NEW rootfs.squashfs file.

I did it from linux that recognize both partitions on sdcard, but I'll only need to access to the first partition, the one that contents original rootfs.squashfs file.

mksquashfs /mnt new_rootfs.squashfs -e /mnt/etc (-e option exclude original etc dir for later add the modified one)

mksquashfs /$HOME/destination/etc  new_rootfs.squashfs -keep-as-directory (add the modified etc dir with asound.conf file that interest us)

umount /mnt (important don't forget to unmount)

cp newroot.squashfs rootfs.squashfs (an replace in the first partition of the sdcard1) -- remember make a backup of the original
Shut3n commented 4 years ago

is this a fix for loud volume at the minimum level (after mute)?

Yes, with it you enable a new control to adjust Master volume. For me it worked on a Playgo, but I still need a way to it for be saved after poweroff.

tgeorgiadis commented 4 years ago

Can confirm the changes @Shut3n made do work. Yes after powering on the device, you do have to go into an emulator, then change the Master levels in the "Sound Mixer" app again. Tested on a PlayGo with the Rogue 1.0.4 firmware.

Here are the commands on Linux I used to make the changes to /etc/asound.conf, refining the instructions @Shut3n gave

First make a backup of rootfs.squashfs, in case something goes wrong you can copy it back in the partition

Run these commands in the partition directory with rootfs.squashfs

mount rootfs.squashfs /mnt cp -a /mnt /home/user/pgo (copy the whole /mnt directory, not just /mnt/etc) gedit /home/user/pgo/etc/asound.conf (replace with the text @Shut3n gave, and then save)

mksquashfs /mnt newroot.squashfs -wildcards -e etc (this is the proper way to exclude the etc directory from our new squashfs. We will add our new /etc with the changed asound.conf in the next command) mksquashfs /home/user/pgo/etc newroot.squashfs -keep-as-directory umount /mnt

mv newroot.squashfs rootfs.squashfs (replacing current rootfs.squashfs with our new one)

So yes, making the speaker quieter is possible without having to do any hardware mods or putting sticky tape over the cover. Although sticky tape is still the easiest option for now!

Shut3n commented 4 years ago

More detailed steps specified on this comments: https://github.com/Ninoh-FOX/POCKETGO2_ROGUE_CFW/issues/37#issuecomment-628972924

I've searching for a way of saving the settings and restore them automatically on reboot. Then I generate this asound.state file with "alsa store -f /media/home/asound.state"

state.VirMIDI {
    control {
    }
}
state.GCW0 {
    control.1 {
        iface MIXER
        name 'Mic Volume'
        value 0
        comment {
            access 'read write'
            type INTEGER
            count 1
            range '0 - 5'
            dbmin 0
            dbmax 2000
            dbvalue.0 0
        }
    }
    control.2 {
        iface MIXER
        name 'Headphone Playback Volume'
        value.0 20
        value.1 20
        comment {
            access 'read write'
            type INTEGER
            count 2
            range '0 - 31'
            dbmin -2500
            dbmax 600
            dbvalue.0 -500
            dbvalue.1 -500
        }
    }
    control.3 {
        iface MIXER
        name 'PCM Capture Volume'
        value.0 0
        value.1 0
        comment {
            access 'read write'
            type INTEGER
            count 2
            range '0 - 23'
            dbmin 0
            dbmax 2300
            dbvalue.0 0
            dbvalue.1 0
        }
    }
    control.4 {
        iface MIXER
        name 'Line In Bypass Volume'
        value.0 20
        value.1 20
        comment {
            access 'read write'
            type INTEGER
            count 2
            range '0 - 31'
            dbmin -2500
            dbmax 600
            dbvalue.0 -500
            dbvalue.1 -500
        }
    }
    control.5 {
        iface MIXER
        name 'Headphone Switch'
        value true
        comment {
            access 'read write'
            type BOOLEAN
            count 1
        }
    }
    control.6 {
        iface MIXER
        name 'Speakers Switch'
        value true
        comment {
            access 'read write'
            type BOOLEAN
            count 1
        }
    }
    control.7 {
        iface MIXER
        name 'Line Out Source'
        value PCM
        comment {
            access 'read write'
            type ENUMERATED
            count 1
            item.0 PCM
            item.1 'Line In'
            item.2 Mic
        }
    }
    control.8 {
        iface MIXER
        name 'Headphone Source'
        value PCM
        comment {
            access 'read write'
            type ENUMERATED
            count 1
            item.0 PCM
            item.1 'Line In'
            item.2 Mic
        }
    }
    control.9 {
        iface MIXER
        name 'Capture Source'
        value 'Line In'
        comment {
            access 'read write'
            type ENUMERATED
            count 1
            item.0 'Line In'
            item.1 Mic
        }
    }
    control.10 {
        iface MIXER
        name 'PCM Playback Volume'
        value 1
        comment {
            access 'read write'
            type INTEGER
            count 1
            range '0 - 31'
            dbmin -9999999
            dbmax 0
            dbvalue.0 -3000
        }
    }
    control.11 {
        iface MIXER
        name Master
        value.0 129
        value.1 129
        comment {
            access 'read write user'
            type INTEGER
            count 2
            range '0 - 255'
            tlv '0000000100000008ffffec1400000014'
            dbmin -5100
            dbmax 0
            dbvalue.0 -2520
            dbvalue.1 -2520
        }
    }
}

With this way is not necessary to do the squash-mount-thing, you can easily copy to the homepart (in the sd card) to access later from the handheld.

Then I can restore the configuration everytime from the terminal app with command: "alsactl restore -f /media/home/asound.state"

But still not possible to restore from booting. I disabled the /etc/init.d/S90volume.sh script because overwrites volume and devices everytime at reboot. And I'm intending to save the asound.state in /var/lib/alsa directory.. so it can restore these audio settings everytime when rebooting.

When I run "alsactl store" I get permission error, not writable , and not found.

Shut3n commented 4 years ago

Done. It stores the state now. The passes I follow:

1) Make the squash-mount-thing, then replace etc/asound.conf, replace etc/init.d/S90Volume.sh with a new file like this (I named it etc/init.d/S90alsaconf.sh) that calls alsactl command to restore|store sound settings (state) everytime. Here's an example.

asound.conf

pcm.!default  {
 type plug     
 slave.pcm "speakerphat"
}

ctl.!default {
 type hw card 1
}

pcm.speakerphat {
  type softvol
  slave.pcm "plughw:1"
  control.name "Master"
  control.card 1
}

S90alsaconf.sh

#!/bin/sh

case "$1" in
    start)
        echo "alsa-config Starting.."
        /usr/sbin/alsactl restore -f /usr/local/etc/asound.state
        ;;
    stop)
        echo "alsa-config Stopping.."
        /usr/sbin/alsactl store -f /usr/local/etc/asound.state
        ;;
    *)
        exit 1
        ;;

esac

exit 0

2) Place the edited rootfs.squash in the card (with new /etc). Then you can start the handheld.

3) The file asound.state will be created automatically when opening one sound applications on the handheld, and after a first reboot.

Shut3n commented 4 years ago

screenshot011

I share my edited "rootfs.squashfs" file (with audio config and restoring enabled) and "asound.state" one (to place on /media/home). You can test if it works for yours

https://drive.google.com/drive/folders/1BHdTk2amB8MBvit-xeKI_ujERpkW2suP?usp=sharing

Ninoh-FOX commented 4 years ago

Great!! I need test this, I am very very busy in my work with the covid-19 problems, I am everytime out of home cleaning zones biohazard in my country.

sdabrowski commented 4 years ago

Fixing this issue would correct probably the BIGGEST bug on the Pocket Go 2. It doesn't look like it was corrected in the latest release, was it, @Ninoh-FOX ? I didn't see it listed as a change.

I hope you can get around to implementing the fix for this issue. I'd do it myself and submit a pull request, but I have unfamiliar with Linux programming. Thanks for all the work you have already done!

Ninoh-FOX commented 4 years ago

The fix not is perfect because not work with fisica keys and you need run first a opk and late go to sound setting, is for this that not is release this for the moment.

Ninoh-FOX commented 4 years ago

I finally find that PWSWD can asigned the control volumen to the keys, but only work PCM, I can't change to MASTES: this is the code: https://github.com/Ninoh-FOX/RG350_pwswd

Ninoh-FOX commented 4 years ago

i find one mode too of save the volumens after of change any valor, I am release this. theme close. psy congroo