Modify

Opened 7 years ago

Closed 4 years ago

Last modified 3 years ago

#9560 closed defect (worksforme)

Playing audio on USB sound results in horrible sound quality

Reported by: gertvdijk+openwrt@… Owned by: loswillios
Priority: normal Milestone: Barrier Breaker 14.07
Component: packages Version: Trunk
Keywords: alsa usb sound stutter clicks underrun Cc:

Description

Running OpenWRT trunk r27155 on a TP-Link WR1043ND device (ar71xx) and installed USB, sound and alsa kernel modules as well as alsa/pulseaudio packages.

When playing audio via alsa directly (pulseaudio not running) it gives me a lot of stutter, clicks and noises. However, the alsa 'aplay -vv' command outputs are completely normal. Using pulseaudio (over the network) is a little bit better but also fails for acceptable quality. Pulseaudio does give 'underruns' when the stutter/hickups/clicks occur; see the pastebin link below for full output.

D: protocol-native.c: Underrun on 'Logitech USB Headset for gert@gert-laptop', 0 bytes in queue.
D: protocol-native.c: Requesting rewind due to end of underrun.
D: alsa-sink.c: Requested to rewind 15672 bytes.

The box has a lot of free memory, the CPU usage is always below 20%. The has the default network configuration (WLAN disabled) and only one PC is connected.
Also, I've used two USB sound devices, results are equal.

Please refer to my forum post and the pulseaudio verbose log for details.

Let me know on how to tackle, debug or provide more info about this issue.
I'm quite new to building OpenWRT - if there's a guide on how to build it with an older/other kernel for example (but recent pulseaudio), I'm willing to try that out.

Attachments (0)

Change History (13)

comment:1 Changed 6 years ago by loswillios

  • Owner changed from developers to loswillios
  • Status changed from new to assigned

please try again with pulseaudio-1.0-rc2 (0.99.2) from trunk.

comment:2 Changed 6 years ago by nbd

  • Resolution set to no_response
  • Status changed from assigned to closed

comment:3 follow-up: Changed 6 years ago by anonymous

  • Resolution no_response deleted
  • Status changed from closed to reopened

I also have cracks and noise when playing via mpd in trunk.

When one and the same track is played, sometimes the sound may be clear, and sometimes it may be with noise. I wasn't able to figure out an algorithm for such behaviour. It seems to be random.

Moreover, I noticed that:

  1. Sound always stays clear till the end of the track if the track started to play clearly.
  2. Sound always stays with noise till the end of the track if the track started to play with noise.

Backfire with the analogous setup produces perfect sound.

So, is the problem in external packages or it's somewhere in openwrt core?

comment:4 Changed 6 years ago by Stefan Hellermann <stefan@…>

I think I had similar problems, but I could resolve them with only config changes. I'm using a USB-Soundcard over ALSA (I changed the mpd-compile options so that ALSA instead of OSS is included)

After changing the audio_output to the following the sound stays always clear:

audio_output {
        type            "alsa"
        name            "USB Soundcard"
        device          "hw:0,0"
        format          "44100:16:2"
}

Also try changing the Buffer-Settings.

comment:5 Changed 6 years ago by anonymous

Tested your settings.
"format" changes nothing.
"device" - this is it !!!
Don't know why but this option makes the problem go away.
Thanks.

comment:6 Changed 4 years ago by tripolar

  • Resolution set to fixed
  • Status changed from reopened to closed

comment:7 in reply to: ↑ 3 Changed 4 years ago by VittGam <openwrt@…>

  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to anonymous:

I also have cracks and noise when playing via mpd in trunk.

When one and the same track is played, sometimes the sound may be clear, and sometimes it may be with noise. I wasn't able to figure out an algorithm for such behaviour. It seems to be random.

Moreover, I noticed that:

  1. Sound always stays clear till the end of the track if the track started to play clearly.
  2. Sound always stays with noise till the end of the track if the track started to play with noise.

I'm having this same problem with latest trunk on a TP-LINK TL-MR3020, using plain aplay with no sound server. It occurs with PulseAudio and MPD too.

The audio sounds like there is a 200ms distorted echo in the output signal when it gets distorted.

It seems that one call to aplay gets audio perfect, then another gets the problem, then clear, then problem, and so on as a cycle.

comment:8 Changed 4 years ago by VittGam <openwrt@…>

The problem also occurs with a WR703N and a TL-MR3220, which both use the same SoC as the TL-MR3020.

I'm using an USB 2.0 HighSpeed hub to plug the audio card to the routers, as the USB audio cards I have are all FullSpeed devices, and they always sound pretty bad or they do not work at all without the hub, because of the USB 1.1 bug in these routers' SoC.

comment:9 follow-up: Changed 4 years ago by VittGam <openwrt@…>

Ok, I think I finally managed to solve the problem for me.

I removed period_time, period_size and buffer_size from the dmix section of /etc/asound.conf and things started working fine for me.

I had to use dmix time ago for a VoIP application to make the sound rate compatible with the hardware.

So if you need dmix, the following should fix your USB audio problems!

This is my /etc/asound.conf file:

pcm.dmixer {
    type dmix
    ipc_key 1024
    ipc_key_add_uid false
    ipc_perm 0666
    slave {
        pcm "hw:0,0"
        ### WARNING: do NOT add period_time, period_size or buffer_size here!!! ###
        rate 44100
    }
    bindings {
        0 0
        1 1
    }
}

pcm.dsp0 {
    type plug
    slave.pcm "dmixer"
}

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

pcm.default {
   type plug
   slave.pcm "dmixer"
}

ctl.mixer0 {
    type hw
    card 0
}

comment:10 Changed 4 years ago by nbd

  • Resolution set to worksforme
  • Status changed from reopened to closed

comment:11 Changed 4 years ago by VittGam <openwrt@…>

In case somebody else has problems with PulseAudio:

This is the /etc/pulse/system.pa line which has solved the crackling and echoed distortion problems with PulseAudio 4.0 and my USB sound card for me so far:

load-module module-alsa-sink device=hw:0,0 format=s16le rate=44100 channels=2 tsched=1 tsched_buffer_size=66156 sink_name=usbcard

You need to disable the static hardware detection module (comment with # the line load-module module-detect) before adding that line.

The problem here seems to be an hardware or driver one, as the cheap USB sound card seems not to be able to cope with big buffer sizes, so here the tsched_buffer_size can reduce the buffer size without disabling the tsched (time-based/"glitch-free") scheduling, which would lead to other instabilities, especially in remote PulseAudio setups with module-native-protocol-tcp and the like.

Remember that if you are using an AR9330-based router (like most recent TP-LINK models) and an USB 1.1 sound card, you still need a USB 2.0 High-Speed hub between the router and the card, to avoid triggering an hardware SoC bug. (But you will likely need an hub anyway to use an extroot, otherwise pulseaudio won't likely fit in the router's flash memory ;) ).

comment:12 Changed 4 years ago by jow

  • Milestone changed from Attitude Adjustment 12.09 to Barrier Breaker 14.07

Milestone Attitude Adjustment 12.09 deleted

comment:13 in reply to: ↑ 9 Changed 3 years ago by anonymous

Replying to VittGam <openwrt@…>:

Ok, I think I finally managed to solve the problem for me.

I removed period_time, period_size and buffer_size from the dmix section of /etc/asound.conf and things started working fine for me.

Thank you. That helped fix my issue too.
My problem was with shairport on TP-WDR3600 running BB 14.07. Every second attempt of switching to AirPlay on my computer resulted in garbled audio.

I added only pcm.dmixer and pcm.!default sections from your comment to my asound.conf and everything works great now.

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.