Closed DrUm78 closed 1 year ago
Thank you for contacting us!
The FunkeyOS you created is a wonderful OS, and I have the impression that more and more users are using FunkeyOS through RG nano.
Please feel free to share the source code! Before that, I have to apologize for releasing without releasing the source code in the first place. I am sorry.
One problem is that I'm not following the buildroot conventions and have manually changed some files in the output/build directory. I am backing up the entire FunKey-OS directory because running make clean all will erase all those changes.
After that, we will create a new repository and upload all the source code.
Thanks for your answer! My source code is already public btw.
No problem for your source code, but what was the main changes you made to fix the USB-C audio? I've tried a lot of things in the kernel but that did not work. I even installed eudev, ucm2, Alsa Python, took all the shell scripts of the Anbernic OS but that damn card1 never appeared in proc/asound/
... I also took the same kernel modules than the Anbernic ones (from lib\modules\4.14.14-anbernic/modules.builtin
.
Did you rewrite the GPIO to support the USB device? Here is an interesting link that fixes a few stuff (GPIO for instance):
https://lore.kernel.org/linux-sunxi/20230620200022.295674-4-macroalpha82@gmail.com/
Can you send me a zipped archive with the kernel files you modified so I can have a look and tell me what the entries in linux.config
you added to make the USB audio work?
Thanks you. 👍
Ok, first archive the modified files in a zip to make the USB-DAC work!
I think that unnecessary settings have been made due to too much trial and error, but please refer to them (^-^)
I will let you know once the zip is uploaded.
zip file I have uploaded the file. The main change is running usb as "host" instead of "otg". As a result, the function of USB gadget is lost, but it is now possible to use USB-DAC.
The ultimate goal is to get the USB-DAC to work in otg mode, but that hasn't happened yet.
Thanks I will have a look at all this!
Indeed, the host mode breaks usb mount capability in RetroFE and GMenu2X. Also, the cpu usage is very high with USB-C audio, much more than the stock RG Nano OS, we'll have to fix all that. 🤞
yes! As you said, the CPU usage is abnormally high. I'm at a loss because I don't have an environment where I can debug with the USB-DAC connected.(T.T)
Hmm it does not work for me with your .config
and the other files, card1
is still not mounted... 🤔
Could you send me your FunKey-OS/FunKey/configs/funkey_defconfig
and FunKey-OS/FunKey/board/funkey/linux.config
please? That would help to check that I missed nothing. Thanks. 👍
[funkey_defconfig]https://github.com/game-de-it/RGnano/blob/main/asset/funkey_defconfig [linux.config]https://github.com/game-de-it/RGnano/blob/main/asset/linux.config
I have uploaded the file. Feel free to let me know if any other files are missing.
Ok thanks. That does not work on top of my code so I guess there is something else you did not send me.
Anyway, we have to find another method as this one breaks the usb mount, uses way too much the cpu and added too many new packages (.img file is huge now) but Anbernic still refuse to give me any information about their method.
The main interesting part is there in lib/modules/4.14.14-anbernic/modules.builtin
about the kernel modules:
Anbernic do not want to say anything about that driver and I cannot find any clue about what it is on internet. 🤔
Here are the complete list of the modules that were added by Anbernic:
kernel/fs/fat/msdos.ko
kernel/fs/nls/nls_cp936.ko
kernel/fs/nls/nls_ascii.ko
kernel/fs/ntfs/ntfs.ko
kernel/drivers/recognition/translogic.ko
kernel/drivers/rtc/rtc-pcf8563.ko
kernel/sound/core/snd-hwdep.ko
kernel/sound/core/snd-rawmidi.ko
kernel/sound/usb/snd-usb-audio.ko
kernel/sound/usb/snd-usbmidi-lib.ko
The 1st 4 ones are not needed I think, only the Translogic, RTC and snd-* but that does not work (not sure that damn Translogic is mandatory here though) and there are also all the Alsa Python/eudev/ucm2 packages they added... So I'm still unsure what makes it work in Anbernic OS... 🤔
https://github.com/game-de-it/RGnano/blob/main/asset/dmesg_OFF_USB-DAC https://github.com/game-de-it/RGnano/blob/main/asset/dmesg_ON_USB-DAC
dmesg file with USB-DAC removed, I uploaded the dmseg file with the USB-DAC connected. Are there any differences in the USB related logs on your RGnano?
Here are the lines that do not appear with my code, whatever I do (headset plugged in or not): https://github.com/game-de-it/RGnano/blob/main/asset/dmesg_ON_USB-DAC#L208-L258
My dmesg: dmesg.txt
As you can see, it does not detect the USB device (I used RG Nano code, not yours).
https://github.com/game-de-it/RGnano/blob/main/asset/tmp_sc1.png https://github.com/game-de-it/RGnano/blob/main/asset/tmp_sc2.png
Checking the log, dr_mode seems to be mismatched. Match the dts settings and linux-menuconfig settings before building.
Ah indeed that was the reason, that works, thanks. At least now we are on the same page. 👍
Glad your USB works!
Yes, we have a common goal to make OTG mode work (^-^) I would like to advance my understanding of the differences in the modules you taught me, the contents of dts, and GPIO.
Hey, I found the reason why some programs have a very high cpu usage with USB-C audio.... their output sampling rate..... Some like PocketSNES, Gambatte or gpSP run perfectly because they run either at 32 kHz or 48kHz (8 and 16 kHz also work good) or at a compatible sampling rate. I set PicoDrive to 16 kHz (it does not support 32 kHz nor 48 kHz), EDuke to 48 kHz and MAME to 32 kHz and that works perfectly. If you want to try: just set "Snd. Rate" to "32000" in PicoArch options of MAME 2000 core and that will fix the high CPU usage.
Now I need to fix that on the OS side (I have no idea how I will proceed though) as otherwise it would require to force 48 kHz for all apps that do not allow users to change the sample rate, which would be a bad practice.
I tried to force some different sampling rates in usr/local/sbin/audio
or etc/asound.conf
but that does not work, 48000
is still set in proc/asound/card1/stream0
.
Seems like Anbernic added a "libswresample" lib that the FunKey OS does not have but I cannot find the buildroot package, maybe that does the job here. 🤔
Do you have any idea?
Hi! Ohhhh! "This is a great survey result!"
I have no proof, but why not try installing libsamplerate.
I will continue to look into this issue!
That one is already included by default. The other one Anbernic use is libswresample
, which I cannot find.
kroot@kroot:~/FunKey-OS$ ll SDK/output/build/Emu/ffplay/libs/libswresample.so.1
-rwxrwxrwx 1 kroot kroot 278708 Sep 10 2022 SDK/output/build/Emu/ffplay/libs/libswresample.so.1*
is this file?
Ah indeed, but it's part of ffmpeg in fact. I built an OS with this package (it includes this lib) but that does not change anything.
I also investigated about how to disable Alsa dmix that resamples every output to 48 kHz (might the problem here) but no success. I found some articles on internet about that: https://www.slackwiki.com/Disable_dmix_for_alsa
Oh... was it bad . .
By the way, is the .asoundrc file set as follows?
/mnt/FunKey/.asoundrc
pcm.!default {
type asym
playback.pcm {
type plug
slave {
pcm "hw:1,0"
rate 48000
}
}
capture.pcm {
type plug
slave.pcm "hw:1,0"
}
}
defaults.ctl.card 1
defaults.pcm.card 1
defaults.timer.card 1
Yeah I already tried the rate thing but in vain... :(
I see. . I removed the capture.pcm section and wrote a configuration file that uses dmix.
pcm.!default {
type plug
playback.pcm {
type dmix
ipc_key 1024
slave {
pcm "hw:1,0"
rate 48000
}
}
}
defaults.ctl.card 1
defaults.pcm.card 1
defaults.timer.card 1
Nope, it just does not launch and gets back to the desktop.
For now, I patched PicoArch and EDuke to fix the performance issue while using USB-C audio, here they are: Patched EDuke32 here. Patched PicoArch binary is available here. For some reason, FBA 2012 still stutters (it does not like 32/48 kHz despite its own core options).
For EDuke32, I basically set the audio sample rate to 48 kHz instead of 44 kHz. For PicoArch I set the limit to 32 kHz instead of 48 kHz as several cores do not support 48 kHz and sound with headphones is still really awesome.
Of course, that's only a workaround and we still need to fix this expensive resampling issue on the OS side.
good morning. It's 9:30 in the morning. I was taking a little nap.
Thanks for pointing me to the EDuke32 and PicoArch files! I would like to get these working.
Yes, as you say, I believe that all sounds should be played with the sampling specified by the OS. :)
I've confirmed that the patched picoarch works great! I would like to deal with it on the OS side no matter what!
The rate item in .asoundrc seems to work fine. When running patched picoarch, CPU usage increased when set to rate 44100 and executed.
I would like to review this issue, but my understanding is that the CPU usage rate will increase if I try to play sounds other than the sampling set by rate.Is this perception wrong?
Is there a pattern that does not increase the CPU usage even for sounds other than sampling set by rate?
I did not modify directly FunKey/.asoundrc
but usr/local/sbin/audio
which populates it but maybe I was too tired yesterday ah ah.
About the pattern, I first thought that the CPU usage was high only when sampling rate is different from 48000 but 8, 16 and 32 kHz work fine too, something to do with 8 multipliers it seems, who knows as only 11025, 22050 and 44100 are CPU intensive. BTW, it looks like FBA 2012 is forced in 44 kHz mode no matter what.
Another interesting thing: I found the code that creates proc/asound/card1/stream0
file (see screenshot below), it is in FunKey/output/build/linux-custom/sound/usb/proc.c
, I removed the "Rates" field but in vain, will try some other things, not sure that can be fixed here though but that may interest you.
Thanks for the detailed explanation! I was able to sort out the pattern that causes the problem. :D
If all games and emulators running on FunkeyOS use SDL, I wondered if SDL_MIXER could control the sampling rate. I don't really have an image in my head of what to do. .
Yeah that's definitely something to investigate but I think the resampling is done after SDL mixer does its job but not sure, I'm bad at all those kernel and package tracking...
BTW, good catch for the SLEEP_SECS=1
instead of SLEEP_SECS=0.1
in the audio
file, I would have spent ages to find it ah ah.
Oh and another question: why are you working on the very outdated FunKey stock OS source? I mean, it does not even have 60 Hz support not the RG Nano RTC support, so I was wondering.
You should really start from my usb_audio
branch: https://github.com/DrUm78/FunKey-OS/tree/usb_audio
I'm also supporting USB audio in my beta version (it includes PicoArch fix):
https://drive.google.com/drive/folders/1tDBBpScsff1wBmzMCVJWyRMIjK0mOrB9
So I was wondering what the benefit of your OS was for users. Could we join our forces and make only one (maybe you could send me some pull requests?)?
Yes, I will answer your question.
I didn't know FunkeyOS existed until I got RGnano. I started with the original FunkeyOS after someone's tweet told me that FunkeyOS works. And it's only recently that I learned about your improved picodrive and your custom FunkeyOS. If I had known your custom FunkeyOS from the beginning, I would have started there. (^^;)
While the Japanese community recognizes RGnano as a game machine, there are requests to use it as a portable audio player. For that reason, I didn't put much effort into adding functions to the game in my custom FunkeyOS.
Instead, Introduction of ffplay (fast forward/rewind/random list playback) and USB-DAC (the DAC recognized as PCM by ALSA and the DAC recognized as Headphone by ALSA can be adjusted) . We have added niche functions requested by users, such as Japanese language support (some characters are garbled) and the ability to adjust the volume in 5% increments. Also, picoarch has individual opk for each core. Ability to automatically turn screenshots into thumbnails. Shut down with start button + A. I have made changes like this.
I'm worried that by incorporating these functions into your FunkeyOS, you may end up modifying your FunKeyOS.
Your FunkeyOS is optimized for users who play games, so some users in Japan use your FunkeyOS instead of my FunkeyOS. (^o^)
Ah ah no problem, was just wondering. 👍
thank you for understanding!
And if OTG, our common mission, becomes available. Or if OTG is not available, I would like to restart from your USB branch. We would like to use the RTC, 60Hz monitor, and a number of finely tuned emulators, while also combining the functions of a music player! (^o^)
For a while there will be me and your FunkeyOS, but in the near future we will unify into an OS originating from your FunkeyOS.
Hey, I have some good news:
Bug fixes
Known issue
Download https://drive.google.com/drive/folders/1tDBBpScsff1wBmzMCVJWyRMIjK0mOrB9
wonderful! ! you did a great job! !
You seem to have enabled OSS emulation, does this resolve sampling rate issues and enable USB hotplug functionality?
On a separate note, some USB audio products have two types of volume control: PCM and Headphone. By default, only PCM volume is adjusted, so we made it possible to adjust the volume on the Headphone side as well.
/usr/local/sbin/volume
Yeah I needed to enable OSS emulation to support hotplug/unplugg and it also fixed the USB-C cpu usage. 3 commits were needed here:
Nice, gonna take your fix on my repo then, thanks! 🙏
Thank you for the information! I was able to confirm the operation using your custom OS image file! I was able to apply the changes to my custom OS and check the operation!
Can I advertise the download URL for your OS on Twitter? https://drive.google.com/drive/folders/1tDBBpScsff1wBmzMCVJWyRMIjK0mOrB9
Oh, I see. The fact that the URL is listed here means that there is no problem even if it is open to the public.
Tweeted right away!
Yes sure, please do! 🙏
Hey I have a question: I bought a new DAC adapter but it does not work on the RG Nano, only on my computer (Windows sees it as "USB audio", no more information), here it is: https://www.amazon.fr/dp/B0BYVM9XJB/ref=pe_27091421_487052621_TE_item
You added some DAC support in your OS I believe right? If so, can you tell me what kernel configs you enabled so I can try my incompatible adapter? 🙏
So far I have 2 working DACs out of 3: AB13X USB Audio
(the one included with the Nano) and KM_B2 Digital Audio
.
Sorry for the late reply.
Even in Japan, there are reports that the DAC is recognized or not with a bifurcated cable. There have also been reports of the DAC not working at all when using the power cable. I don't have a bifurcated cable and I can't confirm the operation.
The situation is confusing because there are also reports that the DAC became usable after performing a USB check in recovery mode. .
Conversely, such reports have not come up with USB-DACs that are not bifurcated cables.
Whether it is a characteristic of RGnano or a problem on the Linux side has not been investigated at all. . .
By the way, is it recognized as /proc/asound/card1? In this case, I can't log in to the console from USB, so I check with the commander app in Applications.
Nope, it's not recognized as a sound card as it does not appear in proc/asound/card1
so it needs a driver. Will try some kernel tweaks I guess. :)
Ok no problem, I just saw that you added support for some Bluetooth dongles, maybe I will do the same. Is there any BT dongle that works right out of the bow btw?
If it's a product that conforms to the Linux USB audio class, you can use it right away, but if it's not, you may need a driver as you said (^^;)
The audio BT dongles that have been confirmed here are as follows
You mean those are compatible without adding any kernel drivers right?
Hey, I'm the author of the custom OS on the FunKey S and I just ported it to the RG Nano (60 Hz and RTC now work but not the USB-C audio yet): https://github.com/DrUm78/FunKey-OS/tree/rg_nano (the branch to use is rg_nano). This custom OS is much more advanced than the stock one (see my release page). I just saw your work on Twitter and that you made some progress about the USB-C audio part (I tried many things but in vain) and I would be interested in your source code for the FunKey OS and the Linux kernel, could you share them or create a PR for my Git repos? 🙏 That way, we would have the best of the 2 worlds:
Here you can find the test version of my OS for the RG Nano: IMG file: https://drive.google.com/file/d/1-ETJwMIre0YAFubo6ojEqEEFrAmjTNY0/view?usp=drive_link FWU file: https://drive.google.com/file/d/1Wx7WHtZBdBpzeUjAGhd57ENxu5fUa49j/view?usp=drive_link
BTW, I'm on the FunKey S, RG Handhelds and Anbernic Discords.
Thanks!