You are not logged in.

#1 2017-02-22 20:42:22

MickeyMouth
Member
Registered: 2017-02-18
Posts: 7

[SOLVED] Soundcard buffer_size and fragment_size

Greetings and thank you for reading this post beloved member of the community.

This question is mostly fueled by my curiosity and I have pretty much already accepted that I must buy an external USB sound card.

Ok so I have an Asus Phoebus card aka CM8888 that runs on driver snd_hda_intel. The card works for me without any configuration, but it produces a horrible crackling noise.
I've been following the PulseAudio troubleshooting wiki page to see if I could fix it, but alas no.

The thing that made me curious is on the wiki page it tells me to calculate my fragment size in msecs + number of fragments.
The example output from pactl list sinks on the wiki shows:

        device.buffering.buffer_size = "352800"
        device.buffering.fragment_size = "176400"

while on my card it prints:

        device.buffering.buffer_size = "35328"
        device.buffering.fragment_size = "8832"

Ok.. so my card apparently has 1/10th the buffer size as theirs, and 1/20th the fragment size.. Right so next step is to calculate how many msecs that is @ s16le 2ch 44100Hz:

device.buffering.buffer_size = "35328" => 35328/1411200 = ~25ms
device.buffering.fragment_size = "8832" => 8832/1411200 = ~6ms

So my soundcard, external soundcard mind you, that I paid like 150$ for is capable of buffering 25ms of audio at that mediocre quality? It is advertised for much higher quality, and on windows I was quite happy with it as well.

Can this really be right? Am I misunderstanding the specs? Where is this information retrieved anyway?
I've tried to adjust my /etc/pulse/daemon.conf accordingly as well, and it just got even more horrible, however when I just tried something higher (and random) like

default-fragments = 2
default-fragment-size-msec = 250

it got better, but playing the guessing game gives me big OCD.. I'd really appreciate some insight on this, even if it doesnt directly answer my questions!

Last edited by MickeyMouth (2017-02-26 16:52:50)

Offline

#2 2017-02-23 09:39:34

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,660

Re: [SOLVED] Soundcard buffer_size and fragment_size

Do you get crackling if you try to use pulseaudio with the default of tsched=1? It should usually just work, especially if your card is using the snd-hda-intel driver. Do you get crackling if you bypass pulseaudio and use direct hardware access with ALSA?

aplay -Dhw:0,0 somewav.wav

can you post, for us to take a look as well

pacmd list-cards
pacmd list-sinks
pacmd list-sink-inputs #While playing something

Offline

#3 2017-02-23 11:44:08

mich41
Member
Registered: 2012-06-22
Posts: 796

Re: [SOLVED] Soundcard buffer_size and fragment_size

MickeyMouth wrote:

while on my card it prints:

        device.buffering.buffer_size = "35328"
        device.buffering.fragment_size = "8832"

This should be adjustable within some reasonable limits, check PA configuration. My card seems to accept up to 128kB per period, but normally it's set much lower.

Also, verify the real parameters the underlying ALSA driver is using, they may or may not be equal to what PA thinks they are wink

cat /proc/asound/card0/pcm0p/sub0/hw_params

Here they are reported in frames (i.e. sample times, 1/sampling rate), so 44.1 means 1ms and so on. And card0 is the first card in the system, there may be more - find the right one.

Offline

#4 2017-02-23 19:42:17

MickeyMouth
Member
Registered: 2017-02-18
Posts: 7

Re: [SOLVED] Soundcard buffer_size and fragment_size

mich41 wrote:
MickeyMouth wrote:

while on my card it prints:

        device.buffering.buffer_size = "35328"
        device.buffering.fragment_size = "8832"

This should be adjustable within some reasonable limits, check PA configuration. My card seems to accept up to 128kB per period, but normally it's set much lower.

Also, verify the real parameters the underlying ALSA driver is using, they may or may not be equal to what PA thinks they are wink

cat /proc/asound/card0/pcm0p/sub0/hw_params

Here they are reported in frames (i.e. sample times, 1/sampling rate), so 44.1 means 1ms and so on. And card0 is the first card in the system, there may be more - find the right one.

Thanks a lot, this is certainly helpful. I wonder where you gathered this information? Anyhow, if I interpreted this correctly then I could take my period_size / 44.1 = ms and same with buffer_size so I arrived at these numbers:

period_size: 50ms
buffer_size = 200ms
so 200 / 50 = 4 fragments @ 50ms would that make sense? I tried setting the card to that for this testing, it sure yields better results than the last calculation..


V1del wrote:

Do you get crackling if you try to use pulseaudio with the default of tsched=1? It should usually just work, especially if your card is using the snd-hda-intel driver. Do you get crackling if you bypass pulseaudio and use direct hardware access with ALSA?

aplay -Dhw:0,0 somewav.wav

can you post, for us to take a look as well

pacmd list-cards
pacmd list-sinks
pacmd list-sink-inputs #While playing something

Hello and thanks a lot for your reply

I've set my tsched to 0, I tried doing tsched=1 now and it got a lot worse so I let it stay at 0. One thing I wanna make clear is that the sound quality is generally really good, I can listen to a song and it sounds flawless but then some parts will get this crackling.. I haven't been able to find any pattern, but one thing that I noticed this time was that if I:

Play a song on youtube, and just let the windows stay in focus while listening, it's pretty good with minimal but unacceptable amounts of crackling. However if I switch to another tab in chromium then the crackling is continous and more intense.
I also tried spotify, here the crackling was always as bad as unfocused youtube. The aplay thing didn't work, it gave me: aplay: main:788: audio open error: No such file or directory  -> so I just uninstalled pulseaudio after some minor ADD crisis while trying to google a way to temporarily disable pulseaudio.

Thankfully I did run the pacmd commands you asked for before that, so let's see.

pacmd list-cards

2 card(s) available.
    index: 0
	name: <alsa_card.pci-0000_01_00.1>
	driver: <module-alsa-card.c>
	owner module: 6
	properties:
		alsa.card = "0"
		alsa.card_name = "HDA NVidia"
		alsa.long_card_name = "HDA NVidia at 0xf7080000 irq 17"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:01:00.1"
		sysfs.path = "/devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card0"
		device.bus = "pci"
		device.vendor.id = "10de"
		device.vendor.name = "NVIDIA Corporation"
		device.product.id = "0e1a"
		device.product.name = "GK110 HDMI Audio"
		device.string = "0"
		device.description = "GK110 HDMI Audio"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	profiles:
		output:hdmi-stereo: Digital Stereo (HDMI) Output (priority 5400, available: no)
		output:hdmi-surround: Digital Surround 5.1 (HDMI) Output (priority 300, available: no)
		output:hdmi-surround71: Digital Surround 7.1 (HDMI) Output (priority 300, available: no)
		output:hdmi-stereo-extra1: Digital Stereo (HDMI 2) Output (priority 5200, available: no)
		output:hdmi-surround-extra1: Digital Surround 5.1 (HDMI 2) Output (priority 100, available: no)
		output:hdmi-surround71-extra1: Digital Surround 7.1 (HDMI 2) Output (priority 100, available: no)
		output:hdmi-stereo-extra2: Digital Stereo (HDMI 3) Output (priority 5200, available: no)
		output:hdmi-surround-extra2: Digital Surround 5.1 (HDMI 3) Output (priority 100, available: no)
		output:hdmi-surround71-extra2: Digital Surround 7.1 (HDMI 3) Output (priority 100, available: no)
		output:hdmi-stereo-extra3: Digital Stereo (HDMI 4) Output (priority 5200, available: no)
		output:hdmi-surround-extra3: Digital Surround 5.1 (HDMI 4) Output (priority 100, available: no)
		output:hdmi-surround71-extra3: Digital Surround 7.1 (HDMI 4) Output (priority 100, available: no)
		off: Off (priority 0, available: unknown)
	active profile: <off>
	ports:
		hdmi-output-0: HDMI / DisplayPort (priority 5900, latency offset 0 usec, available: no)
			properties:
				device.icon_name = "video-display"
		hdmi-output-1: HDMI / DisplayPort 2 (priority 5800, latency offset 0 usec, available: no)
			properties:
				device.icon_name = "video-display"
		hdmi-output-2: HDMI / DisplayPort 3 (priority 5700, latency offset 0 usec, available: no)
			properties:
				device.icon_name = "video-display"
		hdmi-output-3: HDMI / DisplayPort 4 (priority 5600, latency offset 0 usec, available: no)
			properties:
				device.icon_name = "video-display"
    index: 1
	name: <alsa_card.pci-0000_06_00.0>
	driver: <module-alsa-card.c>
	owner module: 7
	properties:
		alsa.card = "1"
		alsa.card_name = "HDA C-Media"
		alsa.long_card_name = "HDA C-Media at 0xf7100000 irq 16"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:06:00.0"
		sysfs.path = "/devices/pci0000:00/0000:00:1c.4/0000:06:00.0/sound/card1"
		device.bus = "pci"
		device.vendor.id = "13f6"
		device.vendor.name = "C-Media Electronics Inc"
		device.product.id = "5011"
		device.product.name = "CM8888 [Oxygen Express] (HDA Controller)"
		device.string = "1"
		device.description = "CM8888 [Oxygen Express] (HDA Controller)"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	profiles:
		input:analog-stereo: Analog Stereo Input (priority 60, available: unknown)
		output:analog-stereo: Analog Stereo Output (priority 6000, available: unknown)
		output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (priority 6060, available: unknown)
		output:analog-surround-21: Analog Surround 2.1 Output (priority 800, available: no)
		output:analog-surround-21+input:analog-stereo: Analog Surround 2.1 Output + Analog Stereo Input (priority 860, available: unknown)
		output:analog-surround-40: Analog Surround 4.0 Output (priority 700, available: no)
		output:analog-surround-40+input:analog-stereo: Analog Surround 4.0 Output + Analog Stereo Input (priority 760, available: unknown)
		output:analog-surround-41: Analog Surround 4.1 Output (priority 800, available: no)
		output:analog-surround-41+input:analog-stereo: Analog Surround 4.1 Output + Analog Stereo Input (priority 860, available: unknown)
		output:analog-surround-50: Analog Surround 5.0 Output (priority 700, available: no)
		output:analog-surround-50+input:analog-stereo: Analog Surround 5.0 Output + Analog Stereo Input (priority 760, available: unknown)
		output:analog-surround-51: Analog Surround 5.1 Output (priority 800, available: no)
		output:analog-surround-51+input:analog-stereo: Analog Surround 5.1 Output + Analog Stereo Input (priority 860, available: unknown)
		output:analog-surround-71: Analog Surround 7.1 Output (priority 700, available: no)
		output:analog-surround-71+input:analog-stereo: Analog Surround 7.1 Output + Analog Stereo Input (priority 760, available: unknown)
		output:iec958-stereo: Digital Stereo (IEC958) Output (priority 5500, available: unknown)
		output:iec958-stereo+input:analog-stereo: Digital Stereo (IEC958) Output + Analog Stereo Input (priority 5560, available: unknown)
		off: Off (priority 0, available: unknown)
	active profile: <output:analog-stereo+input:analog-stereo>
	sinks:
		alsa_output.pci-0000_06_00.0.analog-stereo/#0: CM8888 [Oxygen Express] (HDA Controller) Analog Stereo
	sources:
		alsa_output.pci-0000_06_00.0.analog-stereo.monitor/#0: Monitor of CM8888 [Oxygen Express] (HDA Controller) Analog Stereo
		alsa_input.pci-0000_06_00.0.analog-stereo/#1: CM8888 [Oxygen Express] (HDA Controller) Analog Stereo
	ports:
		analog-input-mic: Microphone (priority 8700, latency offset 0 usec, available: yes)
			properties:
				device.icon_name = "audio-input-microphone"
		analog-input-linein: Line In (priority 8100, latency offset 0 usec, available: no)
			properties:
				
		analog-input-aux: Analog Input (priority 8000, latency offset 0 usec, available: unknown)
			properties:
				
		analog-output-lineout: Line Out (priority 9900, latency offset 0 usec, available: no)
			properties:
				
		analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: yes)
			properties:
				device.icon_name = "audio-headphones"
		iec958-stereo-output: Digital Output (S/PDIF) (priority 0, latency offset 0 usec, available: unknown)
			properties:
				

pacmd list-sinks

1 sink(s) available.
  * index: 0
	name: <alsa_output.pci-0000_06_00.0.analog-stereo>
	driver: <module-alsa-card.c>
	flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
	state: RUNNING
	suspend cause: 
	priority: 9059
	volume: front-left: 24045 /  37% / -26.13 dB,   front-right: 24045 /  37% / -26.13 dB
	        balance 0.00
	base volume: 65536 / 100% / 0.00 dB
	volume steps: 65537
	muted: no
	current latency: 200.27 ms
	max request: 34 KiB
	max rewind: 34 KiB
	monitor source: 0
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	used by: 1
	linked by: 5
	fixed latency: 200.27 ms
	card: 1 <alsa_card.pci-0000_06_00.0>
	module: 7
	properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "CMI8888 Analog"
		alsa.id = "CMI8888 Analog"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "1"
		alsa.card_name = "HDA C-Media"
		alsa.long_card_name = "HDA C-Media at 0xf7100000 irq 16"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:06:00.0"
		sysfs.path = "/devices/pci0000:00/0000:00:1c.4/0000:06:00.0/sound/card1"
		device.bus = "pci"
		device.vendor.id = "13f6"
		device.vendor.name = "C-Media Electronics Inc"
		device.product.id = "5011"
		device.product.name = "CM8888 [Oxygen Express] (HDA Controller)"
		device.string = "front:1"
		device.buffering.buffer_size = "35328"
		device.buffering.fragment_size = "8832"
		device.access_mode = "mmap"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "CM8888 [Oxygen Express] (HDA Controller) Analog Stereo"
		alsa.mixer_name = "C-Media CMI8888"
		alsa.components = "HDA:13f68888,104384d5,00101400"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	ports:
		analog-output-lineout: Line Out (priority 9900, latency offset 0 usec, available: no)
			properties:
				
		analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: yes)
			properties:
				device.icon_name = "audio-headphones"
	active port: <analog-output-headphones>

pacmd list_sink_inputs #youtube focused

1 sink input(s) available.
    index: 5
	driver: <protocol-native.c>
	flags: START_CORKED 
	state: RUNNING
	sink: 0 <alsa_output.pci-0000_06_00.0.analog-stereo>
	volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
	        balance 0.00
	muted: no
	current latency: 203.49 ms
	requested latency: 200.27 ms
	sample spec: float32le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	resample method: copy
	module: 9
	client: 13 <Chromium>
	properties:
		application.icon_name = "chromium-browser"
		media.name = "Playback"
		application.name = "Chromium"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "32"
		application.process.id = "694"
		application.process.user = "pwetgfl"
		application.process.host = "qwwqrr"
		application.process.binary = "chromium"
		window.x11.display = ":0.0"
		application.language = "en_US.UTF-8"
		application.process.machine_id = "2cec023c598b4503aed6bf2e75d06873"
		application.process.session_id = "c2"
		module-stream-restore.id = "sink-input-by-application-name:Chromium"

pacmd list_sink_inputs #unfocused

yeah ok this was basically the same as the focused one

Offline

#5 2017-02-25 10:23:53

mich41
Member
Registered: 2012-06-22
Posts: 796

Re: [SOLVED] Soundcard buffer_size and fragment_size

MickeyMouth wrote:

I wonder where you gathered this information?

Too many years using Linux. And there is some documentation at alsa-project.org, though it's probably best to search it with google rather then try to find something on the website.

Anyhow, if I interpreted this correctly then I could take my period_size / 44.1 = ms and same with buffer_size so I arrived at these numbers:

period_size: 50ms
buffer_size = 200ms
so 200 / 50 = 4 fragments @ 50ms would that make sense? I tried setting the card to that for this testing, it sure yields better results than the last calculation..

Not sure if I follow. What exactly did you do and what happened?

MickeyMouth wrote:

Play a song on youtube, and just let the windows stay in focus while listening, it's pretty good with minimal but unacceptable amounts of crackling. However if I switch to another tab in chromium then the crackling is continous and more intense.

This may possibly be a matter of too little buffering, though your pacmd output suggests that PA uses 200ms buffer (I think that's what they mean by "latency") which should be plenty enough. Check hw_params to be sure if this is right.

MickeyMouth wrote:

The aplay thing didn't work, it gave me: aplay: main:788: audio open error: No such file or directory

You have two soundcards (this and some GPU HDMI output). Use -D hw:1 instead. Or better, run aplay -l to see the current list of soundcards and their numbers, because the numbers can change after reboot. Check hw_params while aplay is playing, buffer_size should be 22050 (500ms) and period_size maybe 1/2, 1/4 or 1/8 of that. If buffer_size is that large but it still cracks then the problem is with buggy driver, not insufficient buffering. Now this reminded me that a year ago there was a thread here about this card not working at all, so well...

Offline

#6 2017-02-26 16:50:19

MickeyMouth
Member
Registered: 2017-02-18
Posts: 7

Re: [SOLVED] Soundcard buffer_size and fragment_size

mich41 wrote:

You have two soundcards (this and some GPU HDMI output). Use -D hw:1 instead. Or better, run aplay -l to see the current list of soundcards and their numbers, because the numbers can change after reboot. Check hw_params while aplay is playing, buffer_size should be 22050 (500ms) and period_size maybe 1/2, 1/4 or 1/8 of that. If buffer_size is that large but it still cracks then the problem is with buggy driver, not insufficient buffering. Now this reminded me that a year ago there was a thread here about this card not working at all, so well...

Yes I have tried now just playing around a bit with the settings and what not, I've also googled and found the same thread you're talking about. That's why I had initially given up already when I posted this, but my initial question was also pretty much answered! It did also confuse me that I had been reading that the card didn't work at all, but for me the sound is excellent except for the artifacts.

But I am going to buy a new card, a usb one and get it over with smile Thanks both of you for good help, I appreciate it a lot.

Offline

Board footer

Powered by FluxBB