Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: CodenameMAT on March 03, 2014, 02:03:54 PM

Title: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 03, 2014, 02:03:54 PM
Hello all,

I'm new to Tiny Core Linux and over the past week I've managed to put together an audio based piCore build with alsa/mpd/ncmpc (compiling what I needed along the way)
unfortunately, there's a problem when playing 24bit files. There's a constant crackling noise over the top of all tracks that are played in this format. 16bit is fine.

Additionaly, I have no problem playing the same tracks with the same software on other distributions (e.g. PiBang linux) it seems that this problem only occurs with piCore.
In fact, the problem sounds very much like the problems that the Raspberry Pi kernel was suffering from last year (usb sound module?)

Is there anything I can do to fix this? Is it possible to upgrade the USB sound module in any way?

Thanks.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 03, 2014, 02:21:21 PM
We have kernel 3.13.3 which is newer than Raspbian is using (no idea on PiBang). What is the USB sound device are you using? Do you hear the same noise with the RPi's built in (analog or HDMI) sound device? Can you share a test file where you have an issue?
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 03, 2014, 02:40:11 PM
Hi Béla,

Thanks for the speedy reply! here's the dmesg from piCore just now
Code: [Select]
[    4.905892] usb 1-1.2: new full-speed USB device number 4 using dwc_otg
[    5.149898] usb 1-1.2: New USB device found, idVendor=262a, idProduct=10e1
[    5.149931] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[    5.149946] usb 1-1.2: Product: SA9023 USB Audio
[    5.149960] usb 1-1.2: Manufacturer: HiFimeDIY Audio
[    5.189583] input: HiFimeDIY Audio SA9023 USB Audio as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.0/input/input0
[    5.190148] hid-generic 0003:262A:10E1.0001: input,hidraw0: USB HID v1.00 Device [HiFimeDIY Audio SA9023 USB Audio] on usb-bcm2708_usb-1.2/input0

/proc/asound/card0/stream0
Code: [Select]
tc@box:/proc/asound/card0$ cat stream0
HiFimeDIY Audio SA9023 USB Audio at usb-bcm2708_usb-1.2, full speed : USB Audio

Playback:
  Status: Stop
  Interface 3
    Altset 1
    Format: S16_LE
    Channels: 2
    Endpoint: 3 OUT (ASYNC)
    Rates: 96000, 88200, 48000, 44100, 32000
  Interface 3
    Altset 2
    Format: S24_3LE
    Channels: 2
    Endpoint: 3 OUT (ASYNC)
    Rates: 96000, 88200, 48000, 44100, 32000

Capture:
  Status: Stop
  Interface 2
    Altset 1
    Format: S16_LE
    Channels: 2
    Endpoint: 2 IN (ASYNC)
    Rates: 96000, 88200, 48000, 44100, 32000
  Interface 2
    Altset 2
    Format: S24_3LE
    Channels: 2
    Endpoint: 2 IN (ASYNC)
    Rates: 96000, 88200, 48000, 44100, 32000

If I force 16bit then I have no problems at all. stream0 and hw shows that 16bit is playing and it sounds perfectly clear. When I use 24bit that's when I have problems.
However, as I said, when I use mpd on PiBang (Debian base) 24bit is not a problem. Volumio too (also Debian/Raspbian)

PiBang uname
Code: [Select]
root@PiBang:~# uname -arv
Linux PiBang 3.10.19+ #600 PREEMPT Sat Nov 16 20:34:43 GMT 2013 armv6l GNU/Linux
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 03, 2014, 03:11:43 PM
This can be an (Alsa) configuration issue and not necessarily a kernel/module/driver problem. Changing buffer size may help:

http://www.alsa-project.org/main/index.php/Asoundrc

I do not have such device, can't test. Probably a good idea to contact forum member 'sbp' who know much more about piCore audio than me.

Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 03, 2014, 03:28:21 PM
I've just tried a quick alsa test and all seems to be find on the alsa side.
Code: [Select]
tc@box:~$ aplay -vv wideband\%20sweep\%20\(w\)\%2096kHz\%2024bit.wav
Playing WAVE 'wideband%20sweep%20(w)%2096kHz%2024bit.wav' : Signed 24 bit Little Endian in 3bytes, Rate 96000 Hz, Stereo
Hardware PCM card 0 'SA9023 USB Audio' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S24_3LE
  subformat    : STD
  channels     : 2
  rate         : 96000
  exact rate   : 96000 (96000/1)
  msbits       : 24
  buffer_size  : 48000
  period_size  : 12000
  period_time  : 125000
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 12000
  period_event : 0
  start_threshold  : 48000
  stop_threshold   : 48000
  silence_threshold: 0
  silence_size : 0
  boundary     : 1572864000
  appl_ptr     : 0
  hw_ptr       : 0

Playback at 96k and 24Bit is crystal clear. There's a distinct possibility that it could be due to my less-than-average compiling skills. I compiled mpd myself and maybe I missed something.
Béla, would it be too much for me to ask if you could compile mpd and add it to the repo? it's the key component of a project I'm working on and I'd just like to rule out the possibility that it's something piCore related.

http://www.musicpd.org/download/mpd/stable/ source is here. I'd very much appreciate it.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 03, 2014, 03:48:02 PM
Can you try cmus just for testing?
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 03, 2014, 10:28:40 PM
Cmus works fine but it appears to be locking the format to 16bit. I can't find any configuration setting to select bit depth.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 04, 2014, 08:14:59 AM
I stand corrected, forget the last post. cmus works fine and plays back my 96k 24bit wave file correctly.

cat stream0
Code: [Select]
HiFimeDIY Audio SA9023 USB Audio at usb-bcm2708_usb-1.2, full speed : USB Audio

Playback:
  Status: Running
    Interface = 3
    Altset = 2
    Packet Size = 582
    Momentary freq = 96000 Hz (0x60.0000)
  Interface 3
    Altset 1
    Format: S16_LE
    Channels: 2
    Endpoint: 3 OUT (ASYNC)
    Rates: 96000, 88200, 48000, 44100, 32000
  Interface 3
    Altset 2
    Format: S24_3LE
    Channels: 2
    Endpoint: 3 OUT (ASYNC)
    Rates: 96000, 88200, 48000, 44100, 32000

So, my problem really is mpd and not piCore. Is it possible for you to compile it, Béla?
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 04, 2014, 09:05:33 AM
Which version you would like to have?
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 04, 2014, 09:12:41 AM
Ah, is it a .wav file? Did you try aplay?
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 04, 2014, 09:52:56 AM
yep, take a look at reply #4 :)
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 04, 2014, 09:54:36 AM
and no particular preference regarding version! thanks!
be aware, there's quite a lot of dependencies. Just out of interest, do you compile directly on the Pi or cross-compile from x86?
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 04, 2014, 10:00:35 AM
Just to be sure, are we talking about this http://www.musicpd.org/ ?

Compiling nativeley on Pi
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 04, 2014, 10:06:53 AM
Yes, Music Player Daemon. Interestingly, there's a new release that addresses audio issues on the Pi http://www.musicpd.org/news/2014/03/new-post/
although, the issues it addresses don't affect me. my problem is constant noise over 24bit files.

As a quick info, I couldn't compile mpd with ffmpeg due to avcodec, avutil and avformat not having pkg-config .pc files in the repo. there are also no 'include' files for mpd to use so I simply disabled ffmpeg support in mpd. Could this affect playback? it's all very strange. Like I said, mpd with 16bit = no problem. mpd with 24bit = problem!
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 04, 2014, 10:12:56 AM
ffmpeg just recently updated/reorganized, -dev is not yet in the repo. I will build the latest mpd, lets see the result
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 04, 2014, 10:30:10 AM
Thank you! Much appreciated.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 04, 2014, 11:51:17 PM
mpd.tcz posted as well as clients ncmpc.tcz and ncmpcpp.tcz
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 05, 2014, 04:14:35 AM
Brilliant! Thanks so much. Will test it when I get home later.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 05, 2014, 10:58:16 AM
unfortunately, there's no change. I'm still experiencing the same problem with playback at 24bit. It's quite frustrating actually!
I even used a fresh install of piCore. did tce-load -wi mpd ncmpcpp alsa and ran mpd and I'm still hearing constant noise over the top of any audio at 24bit.

Something very strange I did notice though. Immediately upon starting mpd, it begins to build the database of music (from the specified music directory) while this was happening, the cpu was busy reading files etc. etc. I started to play a song while the DB was being built and there was NO NOISE, it sounded perfect. as SOON as the database was built the noise started. What could cause this really? I'm no hardware guy but drivers? IRQ problems?...I would put all my problems down to the USB DAC if it wasn't for the fact that it works perfectly at 24bit with the PiBang distro. I'm going to try shortly with Arch Linux + mpd and see what the results are.

so far, I've tried a lot. different nice settings, 'noswap' in the cmdline.txt it's just all very strange.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 05, 2014, 11:06:48 AM
Is it related to the daemon or client? What is about listening with a client on a different machine or listening with a client on RPi a server running on another machine?

Did you try to increase ALSA buffer size?
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: curaga on March 05, 2014, 11:11:51 AM
Noise depending on cpu load sounds like voltage issues. Try powered usb hub, etc.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 05, 2014, 12:08:50 PM
Such crackling noise is usually caused by resampling or buffering problems. When system is busy, it slows down and can't fill buffer too fast, which results lack of crackling. Increasing buffer size can eliminate it adding some delay to processing.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 05, 2014, 01:43:43 PM
After quite a bit of testing between piCore and Arch Linux (both fresh installs) it has to be something on piCore's end
Arch has no problems with 16 or 24 bit. piCore has the noise when playing 24bit.
I was starting to suspect madlib (mpd's mp3 decoder) so I tried with a 44.1k 24bit FLAC and got the same results. I also swapped between direct USB port and powered hub (btw, my DAC is externally powered)

It MUST be something to do with piCore and how it deals with mpd. Or, piCore is doing something that mpd really doesn't like.
aplay worked correctly with a 96k 24bit wave file but anything via mpd and it has a problem.

Thanks for all your help guys. mpd has no problem at all on piCore with 16bit music but I had hoped to build an "Audiophile" system with my new DAC and play around a bit. For now, it looks like I'll have to reluctantly stick with Arch. btw here's a verbose portion of the mpd log from each respective distro playing exactly the same FLAC file.

piCore mpd log
Code: [Select]
Mar 05 21:15 : decoder_thread: probing plugin flac
Mar 05 21:15 : decoder: audio_format=44100:24:2, seekable=true
...
Mar 05 21:15 : alsa_output: opened hw:0,0 type=HW
Mar 05 21:15 : alsa_output: format=S24_3LE (Signed 24 bit Little Endian in 3bytes)
Mar 05 21:15 : alsa_output: buffer: size=90..174762 time=2040..3962858
Mar 05 21:15 : alsa_output: period: size=45..87381 time=1020..1981429
Mar 05 21:15 : alsa_output: default period_time = buffer_time/4 = 500000/4 = 125000
Mar 05 21:15 : alsa_output: buffer_size=22050 period_size=5513
Mar 05 21:15 : output: opened plugin=alsa name="My ALSA Device" audio_format=44100:24:2

Arch linux
Code: [Select]
Mar 05 14:24 : decoder_thread: probing plugin flac
Mar 05 14:24 : decoder: audio_format=44100:24:2, seekable=true
Mar 05 14:24 : alsa_output: opened hw:1,0 type=HW
Mar 05 14:24 : alsa_output: format=S24_3LE (Signed 24 bit Little Endian in 3bytes)
Mar 05 14:24 : alsa_output: buffer: size=90..174762 time=2040..3962858
Mar 05 14:24 : alsa_output: period: size=45..87381 time=1020..1981429
Mar 05 14:24 : alsa_output: default period_time = buffer_time/4 = 500000/4 = 125000
Mar 05 14:24 : alsa_output: buffer_size=22050 period_size=5513
Mar 05 14:24 : output: opened plugin=alsa name="My ALSA Device" audio_format=44100:24:2

as you can see, buffer sizes etc. are identical. I'm really stumped. Hopefully we'll see a fix for this in the future. I'm suspecting the problem will affect any 24bit DAC.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 05, 2014, 01:55:07 PM
Can you provide the file you are playing and noisy?
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 05, 2014, 02:02:27 PM
It's just a regular FLAC. The main thing would be the 24bit capable DAC. My Behringer UCA202 is fine (but limited to 16bit)

Could it be possible that there's a kernel module conflict? I tried modprobe -r for the onboard sound bcm2835
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 05, 2014, 10:10:53 PM
If you play 24-bit files with ffplay (ffmpeg2.tcz) do you get the same crackling noise?

Quote
Something very strange I did notice though. Immediately upon starting mpd, it begins to build the database of music (from the specified music directory) while this was happening, the cpu was busy reading files etc. etc. I started to play a song while the DB was being built and there was NO NOISE

Can you load the CPU during playback for example compressing a longer file during MPD playback for 5-10 seconds to see whether nois goes away during?
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 05, 2014, 10:26:45 PM
I'll try ffmpeg. I also noticed that even something like scrolling through the log in nan stopped the noise.

Play song
Open nano
Hold page down = no noise. As soon as I stop holding page down the noise returns.

 I realise all this sounds incredibly weird. I'm finding it hard to believe myself! Btw, I'm running the ssh version of picore.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 05, 2014, 11:02:17 PM
Still I would increase ALSA buffer size.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: bmarkus on March 05, 2014, 11:43:29 PM
This article may help: http://www.raspyfi.com/raspberry-pi-usb-audio-fix/

Omit Rpi firmware update part as we have the current firmware already, but other parts may be useful.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: sbp on March 06, 2014, 04:28:54 AM
Sorry for seeing your post ealier.

In the piCorePlayer I always use:
smsc95xx.turbo_mode=N   
in the cmdline.txt file. It helps on some of these crackling noises. So I will suggest that you try this (if you haven't already).

Steen
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 06, 2014, 05:08:03 AM
Bela thanks but I've tried similar steps. Raspify was the successor to Volumio. So those fixes have already been implemented in Volumio. If you read the guide you'll see that previously he was limiting the mpd output to 16bit to get around the problems with async USB dacs. All those problems do indeed sound familiar to the problems I'm having, the difference being that I only have a problem with picore. As I said, Volumio and arch have no problems.
Title: Re: USB Audio Problem (piCore 5.2 final. 24 bit)
Post by: CodenameMAT on March 06, 2014, 05:09:59 AM
Steen thanks! I'll give that a go. Unfortunately I have no access to my pi until tomorrow but I'll let you know.