LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 06-03-2022, 04:54 PM   #1
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,274

Rep: Reputation: 63
WM8960 soundcard on RPi Zero2 seems stuck at 48000Hz, how to change to 44100Hz


Greetings LQ. I am working on a Raspberry Pi Zero 2 and recently attached a Waveshare WM8960 Hi-Fi soundcard. The OS is RetroPie and the Waveshare driver installation did an apt upgrade so all of the packages are up-to-date and the kernel is 5.10.81+ (IIRC).

My plan for this Pi project is a dedicated MAME system, specifically mame2000. The monitor will be either VGA or DVI, and either way it will need an alternate soundcard, whether USB or GPIO. The libretro mame2000 core is okay but mame4all is preferred due to performance and supporting hiscores and cheat files.

Before adding the Waveshare card both the lr-mame2000 and mame4all cores played the games fine over HDMI audio. Now with the soundcard attached the lr-mame2000 works fine but mame4all fails to launch. At first the log file had an ALSA error of
Code:
Unable to set hw params for PLAYBACK: Invalid argument
I spent much of the past few days Googling the error and studying the .asoundrc file to find an answer. As far as I can tell, mame4all specifically wants an ALSA device named PCM, and I solved that by creating an alias in ~/.asoundrc. Now the error is
Code:
Rate doesn't match (requested 44100Hz, get 48000Hz)
I've seen some posts in other forums about this error with USB audio adapters and was solved by adding rate 44100 and format S16_LE somewhere in .asoundrc. I have been trying for several hours now, following the asoundrc guide at alsa-project.org, to get such a line in .asoundrc to work. I even tried editing the 10-xxxx files in /etc/alsa/conf.d to change the default rate from 48000 to 44100. Nothing worked.

After a while I started trying to use aplay with a .wav file from /usr/share/sounds/alsa to test if it is capable of 44100. I tested with several of the names in my .asoundrc with -r 44100 and every time the playback status shows 48000. Finally, I looked in the wm8960.c file of the source code and there is one section about alc_rates
Code:
} alc_rates[] = {
	{ 48000, 0 },
	{ 44100, 0 },
	{ 32000, 1 },
	{ 22050, 2 },
	{ 24000, 2 },
	{ 16000, 3 },
	{ 11025, 4 },
	{ 12000, 4 },
	{  8000, 5 },
};
Then further down is this
Code:
#define WM8960_RATES SNDRV_PCM_RATE_8000_48000
I may be wrong but it looks like it is capable, but how can I get it to work?

The source files are located at https://github.com/waveshare/WM8960-Audio-HAT
Also, the ~/.asoundrc file I am using is an unmodified copy of the asound.conf from the above link. At this point I have removed all of my failed attempts, and the only addition I have in place is the following alias which originally gives the "Rate doesn't match" error
Code:
pcm_slave.pcm { pcm "dmixed" }
Thank in advance

Last edited by dracolich; 06-06-2022 at 08:10 PM.
 
Old 06-06-2022, 04:17 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,443

Rep: Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340
If you need 44100 for some reason (?) you may be able to resample at that speed by setting that up in /etc/asound.conf. I had the reverse done to get over a hdmi quality issue on drivers at the time.

Last edited by business_kid; 06-06-2022 at 04:19 AM.
 
Old 06-06-2022, 08:07 PM   #3
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,274

Original Poster
Rep: Reputation: 63
Thanks for the idea. I'll give that a try as soon as I get a chance. I tried a lot of things in ~/.asoundrc, but not in /etc/asound.conf. I'm pretty sure mame4all specifically wants 44,100Hz just like it specifically wants a device named pcm.
 
Old 06-07-2022, 07:02 AM   #4
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,443

Rep: Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340Reputation: 2340
pcm is one of the alsa input channels. Frankly I don't think you setup is going to change the results. I'd be looking at the config.txt settings. If yopu're usingh u-boot, put the line calling u-boot.bin at the very end of config.txt, becausew the firmware doesn't seem to act on the rest of config.txt IME. It means all your 'dtparams' settings get acted on.
 
Old 06-09-2022, 03:59 PM   #5
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,274

Original Poster
Rep: Reputation: 63
I had a chance to check the /etc/asound.conf, and it is a symlink to the same asound config file provided by the soundcard driver.

I did find the mame.cfg file used by mame4all, and includes the default samplerate set to 44100. I tried changing it to 48000, but still get the same error.

Then I opened a terminal and navigated to /opt/retropie/emulators/mame4all to try it without the frontend. I run the command
Code:
./mame 1942b
and get the same error in the command output, instead of the /dev/shm/runcommand.log file. Then I found the mame option to specify the rate and tried it
Code:
./mame 1942b -samplerate 48000
and still get the same error.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Trying to mount USB drive of RPi A into RPi B suziecat Linux - Newbie 5 09-28-2021 08:23 AM
I'm an rpi user and at boot I get the message "failed to load kernel modules", however the system seems to work just fine. Using stretch. rsmith53 Linux - Newbie 1 11-26-2019 02:02 PM
LXer: GNOME 3.33.2 Released, Krita 4.2 Debuts, RPi Camera Modules on RPi Zeros Power the Penguin Watch Project, Intrinsyc Switches Its Home LXer Syndicated Linux News 0 05-30-2019 06:23 AM
LXer: Mini-PC taps RPi Compute Module and supports RPi 2 LXer Syndicated Linux News 0 02-22-2015 03:03 PM
48000Hz bitrate Audio distorted fabre Debian 5 12-09-2006 03:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 12:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration