Distorted audio - Samplerate on DAC not being set correctly

Hi, I’m new to Volumio so I may have a setting wrong somewhere, I did check the FAQ and searched the forum but

I’m using a E-Mu 0404 USB as a DAC and it works really nicely on Windows and Mac systems.

However it’s showing strange behaviour under Volumio, here’s what happens.

Upon booting all audio sounds distorted/terrible/unlistenable unless it’s 48Khz audio, or if I turn on resampling to 48Khz. The bad sound is because the DAC is at the wrong samplerate.

It seems that Volumio is not setting the sample rate of my DAC correctly, I can change it manually like this:

If I SSH in and load up alsamixer then I can change the samplerate manually with the ‘Clock rate Selector’ slider - this way I can listen to 44.1Khz audio without resampling with the slider at the bottom, it sounds great/not-distorted and if I need a higher sampling rate I can increase the Clockrate slider until there is no distortion.

Now while this works having to use terminal to change the samplerate is pretty clunky. Is there a setting somewhere or something I need to configure also sample rate switching? It would be really nice auto Samplerate switching.

Thanks

I had something similar some versions ago, although my DAC would only output distorted noise regardless of the input file.
The solution to force a certain communication mode might work though. Worth a try at least.

In the file /boot/cmdline.txt, add the line below. You can vary from 0x1 to 0x7, try which one works.

dwc_otg.fiq_fsm_mask=0x1

Hi! I have the same troubles with 0404… :frowning:
Here:
bugs.launchpad.net/ubuntu/+sour … ug/1416702
something VERY-VERY similar to our issue. Only one sample rate played and on the others - distortion instead of sound.
And again in that description, TS says about this patch:
mailman.alsa-project.org/piperma … 79103.html
and about successfully solving a problem with this patch. And looks like it worked for PI kernel too.

I very far from all this things(kernels, patch etc) and my english very bad, but maybe somebody can take note of
michelangelo
member61.html
on this links…

That patch never made it to the official RPi kernel.
Module quirks.c still has the original contents:

if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1) return; }

The same code is also still in the latest stable mainline kernel.
For RPi we do not maintain our own kernel, so if it is not in the RPI kernel, there is nothing much we can do.

Too baaad… :cry:
Any possibility to apply this patch to working OS or to clean image?.. any else? :blush:

Nope, it is a source code change, the kernel needs to be recompiled after that.

Then… May be someone who closer enough to all this development things, can push this patch to official PI-kernel ?
Only on this forum I see 5-6 topics about E-MU USB DACs problems…

We cannot push a patch of which we cannot be certain that it will not break something else.
This may very well be the reason why it was never implemented in upstream kernels.

Some google searching help me to find one tricky solution…

This script:

#!/bin/bash

# if this is the first run, EMU-rate does not exist,create it
if [ ! -f /dev/shm/EMU-rate ]; then    # file does not exist
    echo "00" > /dev/shm/EMU-rate
fi


while : ; do
   mpc idle
   # stuff below executes when mpc is not idle

   sleep 0.4 # wait for actual track to start playing (fist 0,4 sec., to determine the sample rate)
   old_rate=$(cat /dev/shm/EMU-rate)
   # echo "old rate:$old_rate"
   sRateStr=$(cat /proc/asound/card1/stream0 | grep Momentary)
   # echo "full line: " $sRateStr
   cur_rate=${sRateStr:21:2} # here we get just the first two digits (44, 48, 96, etc.)
   # echo "cur rate:$cur_rate"
   # if $cur_rate is empty, next iteration ("continue")
   if [ -z "$cur_rate" ] # string is empty
   then
     # echo "No song playing"
     continue  # $cur_rate is null/empty, nothing to do, wait for next iteration
   fi

   # echo "Track sample rate: $cur_rate"
   if [ "$old_rate" = "$cur_rate" ]
   then
     # echo "The rates are the same"
     continue # rates are the same, nothing to do, wait for next iteration
   fi

   # here we actually compare rates and take appropriate action (change EMU clock rate using "amixer")
   # E-MU 0404 is visible as "card 1" on my system, i.e. it needs switch "-c1" for manipulation

   case $cur_rate in
   44)
   amixer -c1 set 'Clock rate Selector' 0
   echo "$cur_rate" > /dev/shm/EMU-rate
   continue
   ;;
   48)
   amixer -c1 set 'Clock rate Selector' 1
   echo "$cur_rate" > /dev/shm/EMU-rate
   continue
   ;;
   88)
   amixer -c1 set 'Clock rate Selector' 2
   echo "$cur_rate" > /dev/shm/EMU-rate
   continue
   ;;
   96)
   amixer -c1 set 'Clock rate Selector' 3
   echo "$cur_rate" > /dev/shm/EMU-rate
   continue
   ;;
   17)
   amixer -c1 set 'Clock rate Selector' 4
   echo "$cur_rate" > /dev/shm/EMU-rate
   continue
   ;;
   19)
   amixer -c1 set 'Clock rate Selector' 5
   echo "$cur_rate" > /dev/shm/EMU-rate
   continue
   ;;
   esac     

   echo "$cur_rate" > /dev/shm/EMU-rate

done 

place to the /home/clock.sh

Then need to create service:
/etc/systemd/system/clock.service
with this code:

[Unit]
Description=Samplerate EMU Fix

[Install]
WantedBy=multi-user.target

[Service]
Type=idle
RemainAfterExit=yes
ExecStart=/home/clock.sh

And then start this new service (in terminal):
systemctl enable clock.service

After all this need to reboot PI.

After this, while track changing, this service will automaticaly change samplerate of E-MU. If samplerate of new played track is different with previous, you may hear some little noise or “swallowed” beat (only for a short moment).

May be somebody can do this as plugin, so that it would be possible to continue updating the system without losing this functionality and if I wish or need to have it, it`ll be possible to disable it…
Thanks ))

1 Like

I forgot to say that I did all this and everything works very well. The only problem happens if I turn off the DAC without turning off the raspberry,and on the next time turning on the DAC, I need to restart the service manually. But I think it can be solved somehow.

Added after week:

Here is the “full” solution for E-MU USB 0404:
guid-for-customize-volumio-image-t11628.html#p60036