Bug 87713 - "Transistor" game makes every client playing at double speed
Summary: "Transistor" game makes every client playing at double speed
Status: RESOLVED MOVED
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-25 17:34 UTC by rkfg
Modified: 2018-07-30 10:16 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
pulseaudio log (256.63 KB, text/plain)
2014-12-25 17:34 UTC, rkfg
Details
PA startup log (251.54 KB, text/plain)
2014-12-30 20:04 UTC, rkfg
Details
ALSA time test (247.65 KB, text/plain)
2014-12-30 20:06 UTC, rkfg
Details
ALSA test log (2.72 MB, text/plain)
2014-12-31 16:22 UTC, rkfg
Details
Fixed PA log (232.22 KB, text/plain)
2015-01-01 15:56 UTC, rkfg
Details
pcm_avail log (19.10 KB, text/plain)
2015-01-01 15:59 UTC, rkfg
Details
ALSA info (74.69 KB, text/plain)
2015-01-02 10:17 UTC, rkfg
Details
Pulse log (184.63 KB, text/plain)
2015-01-02 17:28 UTC, rkfg
Details
pactl list log (26.00 KB, text/plain)
2015-01-02 17:29 UTC, rkfg
Details

Description rkfg 2014-12-25 17:34:04 UTC
Created attachment 111331 [details]
pulseaudio log

The game uses MonoGame as the engine, it outputs audio via ALSA. Often, but not every time, when I start the game the sound is played at double speed. What's worse all other apps also start playing audio too fast, including paplay, Chrome etc. Even those which are started after I exit the game. This can be fixed by restarting PA or after killing all clients connections with paman (if there are none after I exit the game, sound seems to be working correctly). I believe no client should affect other clients like this, no matter how it's broken. A friend of mine completed Transistor without such issues using PA. I also found that something like this was long ago fixed in Wine but this game is native. At least more native than pure Win32 apps+Wine and it doesn't use Wine. It uses Mono though and FMOD as the sound engine.

My soundcard is CA0106 Soundblaster (SB0410 SBLive! 24-bit), CPU is Intel Core i7-2600, 32Gb RAM, NVIDIA GeForce 770 GTX driver v340.65, Debian Jessie GNU/Linux amd64, Awesome WM 3.4.15, kernel v3.16.

I also have another sound chip, ALC889 Analog. It's disabled in pavucontrol.

You can also see some ALSA underruns, I couldn't fix it no matter what priorities and realtime priorities I set. They happen on both snd-hda-intel and snd-ca0106.
Comment 1 rkfg 2014-12-25 17:58:43 UTC
The issue seems to go away after I set the default sample spec to s32le (default is s16le). I also noticed that with s16le both Chrome and Transistor use "resample method: (null)" (according to pacmd list-sink-inputs), and with s32le it becomes "resample method: copy" for both. And no, Chrome isn't the culprit as it happens even when it's not running, I've tried. The speedup happens right after starting the game, I've run a song in Chrome and launched Transistor. First time it was ok in both Chrome and the game but on the second run the song immediately sped up to double speed. I have no idea how the sample spec (not the sample rate!) affects the speed but it's what it is.

SBLive! seems not to support 44100 Hz as it switches to 48k by default and even if I set 44100 explicitly in the daemon.conf. Though here paman and pacmd disagree with each other, pacmd says "sample spec: s16le 2ch 48000Hz" and paman says "Default Sample Type: s16le 2ch 44100Hz". Mumble notification sounds doesn't
crackle as they do on ALC889 @ 44100Hz so I believe pacmd is correct here.
Comment 2 Raymond 2014-12-29 15:41:41 UTC
https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/plain/sound/pci/ca0106/ca0106_main.c

static struct snd_pcm_hardware snd_ca0106_playback_hw = {
	.info =			SNDRV_PCM_INFO_MMAP | 
				SNDRV_PCM_INFO_INTERLEAVED |
				SNDRV_PCM_INFO_BLOCK_TRANSFER |
				SNDRV_PCM_INFO_MMAP_VALID |
				SNDRV_PCM_INFO_SYNC_START,
	.formats =		SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
	.rates =		(SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
				 SNDRV_PCM_RATE_192000),
	.rate_min =		48000,
	.rate_max =		192000,
	.channels_min =		2,  //1,
	.channels_max =		2,  //6,
	.buffer_bytes_max =	((65536 - 64) * 8),
	.period_bytes_min =	64,
	.period_bytes_max =	(65536 - 64),
	.periods_min =		2,
	.periods_max =		8,
	.fifo_size =		0,
};

seem support both s16_le and s32_le but require SNDRV_PCM_INFO_SYNC_START


post the pulseaudio  verbose log

and


aplay -D hw:CARD=CA0106  --dump-hw-params any.wav
Comment 3 rkfg 2014-12-29 17:28:08 UTC
> aplay -D hw:CARD=CA0106  --dump-hw-params /usr/share/sounds/alsa/Front_Center.wav
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
HW Params of device "hw:CARD=CA0106":
--------------------
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE S32_LE
SUBFORMAT:  STD
SAMPLE_BITS: [16 32]
FRAME_BITS: [32 64]
CHANNELS: 2
RATE: [48000 192000]
PERIOD_TIME: (41 170667)
PERIOD_SIZE: [8 8192]
PERIOD_BYTES: [64 65472]
PERIODS: [2 8]
BUFFER_TIME: (83 341334)
BUFFER_SIZE: [16 16384]
BUFFER_BYTES: [64 65536]
TICK_TIME: ALL
--------------------
aplay: set_params:1239: Channels count non available

The pulseaudio log is attached to the first message. This is the debug level, AFAIK, it's the most verbose one.
Comment 4 Raymond 2014-12-30 02:34:12 UTC
how about

aplay -D surround40:CARD=CA0106  --dump-hw-params any.wav


aplay -D surround51:CARD=CA0106  --dump-hw-params any.wav

pulseaudio does not support SND_PCM_ACCESS_MMAP_COMPLEX and fallback to use SND_PCM_ACCESS_RW_INTERLEAVED

this force pulseaudio to use irq polling instead of timer scheduling 
for those surround devices

http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa-util.c?id=045c1d602dcba57868845ba3270510593c39480f

+    if (!_use_mmap)
+        _use_tsched = FALSE;
+



your log did not contain the probing of your ca0106 and those errors

alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_START failed (-77)

and

pulseaudio] (alsa-lib)setup.c: Cannot lock ctl elem



http://lists.freedesktop.org/archives/pulseaudio-discuss/2014-November/022670.html

https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1315212
Comment 5 Raymond 2014-12-30 03:03:08 UTC
static snd_pcm_uframes_t
snd_ca0106_pcm_pointer_playback(struct snd_pcm_substream *substream)
{
	struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct snd_ca0106_pcm *epcm = runtime->private_data;
	unsigned int ptr, prev_ptr;
	int channel = epcm->channel_id;
	int timeout = 10;

	if (!epcm->running)
		return 0;

	prev_ptr = -1;
	do {
		ptr = snd_ca0106_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
		ptr = (ptr >> 3) * runtime->period_size;
		ptr += bytes_to_frames(runtime,
			snd_ca0106_ptr_read(emu, PLAYBACK_POINTER, channel));
		if (ptr >= runtime->buffer_size)
			ptr -= runtime->buffer_size;
		if (prev_ptr == ptr)
			return ptr;
		prev_ptr = ptr;
	} while (--timeout);
	dev_warn(emu->card->dev, "ca0106: unstable DMA pointer!\n");
	return 0;
}

pointer callback return value from hardware register, 

do the sound card report realtime accurate update poistion ?


http://cgit.freedesktop.org/pulseaudio/pulseaudio/plain/src/tests/alsa-time-test.c

try different fill rate 

do the sound card report hw_ptr better than period size ?
Comment 6 rkfg 2014-12-30 20:04:57 UTC
Created attachment 111535 [details]
PA startup log

Here's the startup log.

> aplay -D surround40:CARD=CA0106  --dump-hw-params /usr/share/sounds/alsa/Front_Center.wav 
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
HW Params of device "surround40:CARD=CA0106":
--------------------
ACCESS:  MMAP_COMPLEX RW_INTERLEAVED RW_NONINTERLEAVED
FORMAT:  S16_LE S32_LE
SUBFORMAT:  STD
SAMPLE_BITS: [16 32]
FRAME_BITS: [64 128]
CHANNELS: 4
RATE: [48000 192000]
PERIOD_TIME: (41 170667)
PERIOD_SIZE: [8 8192]
PERIOD_BYTES: [64 131072]
PERIODS: [2 8]
BUFFER_TIME: (83 341334)
BUFFER_SIZE: [16 16384]
BUFFER_BYTES: [128 262144]
TICK_TIME: ALL
--------------------
aplay: set_params:1239: Channels count non available

> aplay -D surround51:CARD=CA0106  --dump-hw-params /usr/share/sounds/alsa/Front_Center.wav 
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
HW Params of device "surround51:CARD=CA0106":
--------------------
ACCESS:  MMAP_COMPLEX RW_INTERLEAVED RW_NONINTERLEAVED
FORMAT:  S16_LE S32_LE
SUBFORMAT:  STD
SAMPLE_BITS: [16 32]
FRAME_BITS: [96 192]
CHANNELS: 6
RATE: [48000 192000]
PERIOD_TIME: (41 170667)
PERIOD_SIZE: [8 8192]
PERIOD_BYTES: [96 196608]
PERIODS: [2 8]
BUFFER_TIME: (83 341334)
BUFFER_SIZE: [16 16384]
BUFFER_BYTES: [192 393216]
TICK_TIME: ALL
--------------------
aplay: set_params:1239: Channels count non available
Comment 7 rkfg 2014-12-30 20:06:17 UTC
Created attachment 111536 [details]
ALSA time test

The output of alsa-time-test.c

It ends with:
a.out: alsa-time-test.c:244: main: Assertion `(unsigned) avail <= buffer_size' failed.
zsh: abort      ./a.out > timetest.log

I think it's ok.
Comment 8 Raymond 2014-12-31 02:36:46 UTC
(In reply to rkfg from comment #7)
> Created attachment 111536 [details]
> ALSA time test
> 
> The output of alsa-time-test.c
> 
> It ends with:
> a.out: alsa-time-test.c:244: main: Assertion `(unsigned) avail <=
> buffer_size' failed.
> zsh: abort      ./a.out > timetest.log
> 
> I think it's ok.

how did you run the program ?

the program is hardcoded to use 44100Hz , it should run continously without any error if fillrate is equal to period size

if sound card can report hw_ptr with better grannularity, the program can still run continously when fillrate is smaller than period size (e.g. dma brust size )
Comment 9 Raymond 2014-12-31 03:01:56 UTC
(In reply to rkfg from comment #6)
> Created attachment 111535 [details]
> PA startup log
> 
> Here's the startup log.



Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-util.c: Successfully attached to mixer 'hw:0'
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] (alsa-lib)control.c: Invalid CTL iec958:0
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-util.c: Unable to attach to mixer iec958:0: No such file or directory
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-util.c: Successfully attached to mixer 'hw:0'
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] (alsa-lib)setup.c: Cannot lock ctl elem
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] (alsa-lib)setup.c: Cannot lock ctl elem
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] (alsa-lib)setup.c: Cannot lock ctl elem
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] (alsa-lib)setup.c: Cannot lock ctl elem
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] (alsa-lib)setup.c: Cannot lock ctl elem
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-util.c: snd_pcm_hw_params failed: Device or resource busy


git.alsa-project.org/?p=alsa-lib.git;a=blob_plain;f=src/conf/cards/CA0106.conf;hb=HEAD


seem related to lock in iec958 playback when pulseaudio try to open iec958 for playback and capture

need to use asym plugin if your ca0106 support both iec958 playback and capture
Comment 10 Raymond 2014-12-31 03:04:37 UTC
	}
	type hooks
	slave.pcm {
		type hw
		card $CARD
	}
	hooks.0 {
		type ctl_elems
		hook_args [
			{
				name "IEC958 Front Playback Volume"
				index 0
				lock true
				preserve true
				value [ 207 207 ]   # Puts 0x30303030 in the Volume register. 0xff - 0x30 = 0xcf = 207
			}
			{
				name "IEC958 Playback Switch"
				lock true
				preserve true
				value 1
			}
			{
				interface PCM
				name "IEC958 Playback Default"
				index 1
				lock true
				preserve true
				optional true
				value [ $AES0 $AES1 $AES2 $AES3 ]
			}
			{
				# for compatibility with older drivers
				name "IEC958 Playback Default"
				index 1
				lock true
				preserve true
				optional true
				value [ $AES0 $AES1 $AES2 $AES3 ]
			}
		]
	}
}
Comment 11 Raymond 2014-12-31 03:12:07 UTC
alternative is to force pulseaudio not to open iec958 for capture


by removing all paths-input of iec958 from

 http://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/modules/alsa/mixer/profile-sets/default.conf


[Mapping iec958-stereo]
device-strings = iec958:%f
channel-map = left,right
paths-input = iec958-stereo-input
paths-output = iec958-stereo-output
priority = 5
Comment 12 Raymond 2014-12-31 03:37:52 UTC
APLAY

**** List of PLAYBACK Hardware Devices ****
card 0: CA0106 [CA0106], device 0: ca0106 [CA0106]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: CA0106 [CA0106], device 1: ca0106 [CA0106]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: CA0106 [CA0106], device 2: ca0106 [CA0106]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: CA0106 [CA0106], device 3: ca0106 [CA0106]
  Subdevices: 1/1
  Subdevice #0: subdevice #0


ARECORD

**** List of CAPTURE Hardware Devices ****
card 0: CA0106 [CA0106], device 0: ca0106 [CA0106]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: CA0106 [CA0106], device 1: ca0106 [CA0106]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: CA0106 [CA0106], device 2: ca0106 [CA0106]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: CA0106 [CA0106], device 3: ca0106 [CA0106]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
Comment 13 rkfg 2014-12-31 11:18:30 UTC
(In reply to Raymond from comment #8)
> 
> how did you run the program ?
> 
> the program is hardcoded to use 44100Hz , it should run continously without
> any error if fillrate is equal to period size
> 
> if sound card can report hw_ptr with better grannularity, the program can
> still run continously when fillrate is smaller than period size (e.g. dma
> brust size )

I did:
gcc alsa-time-test.c -lasound
./a.out

That's all. What exactly should I do now and what information do you need?
Comment 14 Raymond 2014-12-31 11:57:42 UTC
http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html

pcm.name {
        type asym               # Asym PCM
        playback STR            # Playback slave name
        # or
        playback {              # Playback slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        }
        capture STR             # Capture slave name
        # or
        capture {               # Capture slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        }
}

pcm.NAME {
        type hooks              # PCM with hooks
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        }
        hooks {
                ID STR          # Hook name (see pcm_hook)
                # or
                ID { }          # Hook definition (see pcm_hook)
        }
}

you need to put the current ca0106 iec958 slave pcm and hook into playback slave and create capture slave of asym plugin
Comment 15 rkfg 2014-12-31 12:12:46 UTC
(In reply to Raymond from comment #14)
> you need to put the current ca0106 iec958 slave pcm and hook into playback
> slave and create capture slave of asym plugin

Sorry, I don't understand. I'm not that familiar with low-level ALSA configs, I only did some basic operations with ~/.asoundrc
What file exactly should I change and what should I write into it?
Comment 16 Raymond 2014-12-31 13:11:35 UTC
/usr/share/alsa/cards/CA0106.conf
Comment 17 rkfg 2014-12-31 13:21:54 UTC
Good, the file is there and it has those lines you mentioned in #10. Now how should I modify them? Could you provide a diff to apply? I don't really get what "to put the current ca0106 iec958 slave pcm and hook into playback slave and create capture slave of asym plugin" means. If the alternative method is effectively equal to ALSA hacks, I can go that way, it seems to be much easier.

>alternative is to force pulseaudio not to open iec958 for capture
>by removing all paths-input of iec958 from

Should I comment out the entire [Mapping iec958-stereo] section or just "paths-input = iec958-stereo-input"?
Comment 18 Raymond 2014-12-31 14:18:23 UTC
CA0106.pcm.iec958.0 {
	@args [ CARD AES0 AES1 AES2 AES3 ]
	@args.CARD {
		type string
	}
	@args.AES0 {
		type integer
	}
	@args.AES1 {
		type integer
	}
	@args.AES2 {
		type integer
	}
	@args.AES3 {
		type integer
	}
+       type asym
+       playback.pcm {
	type hooks
	slave.pcm {
		type hw
		card $CARD
	}
	hooks.0 {
		type ctl_elems
		hook_args [
			{
				name "IEC958 Front Playback Volume"
				index 0
				lock true
				preserve true
				value [ 207 207 ]   # Puts 0x30303030 in the Volume register. 0xff - 0x30 = 0xcf = 207
			}
			{
				name "IEC958 Playback Switch"
				lock true
				preserve true
				value 1
			}
			{
				interface PCM
				name "IEC958 Playback Default"
				index 1
				lock true
				preserve true
				optional true
				value [ $AES0 $AES1 $AES2 $AES3 ]
			}
			{
				# for compatibility with older drivers
				name "IEC958 Playback Default"
				index 1
				lock true
				preserve true
				optional true
				value [ $AES0 $AES1 $AES2 $AES3 ]
			}
		]
	}
+       }
+       capture.pcm {
+                type hw
+                card $CARD
+        }
}
Comment 19 Raymond 2014-12-31 14:39:01 UTC
for alsa-time-test.c

dev = argc > 1 ? argv[1] : "front:0";
    cap = argc > 2 ? atoi(argv[2]) : 0;
    fillrate = argc > 3 ? atoi(argv[3]) : 1;


there are three parameter which allow you to change 

device
capture or playback
fillrate


most sound cards cannot use default fill rate 1 

for hda-intel, the hw_ptr increase by 16/32 frames  for each dma transfer,  fill rate can be lower than the period size
Comment 20 rkfg 2014-12-31 16:22:34 UTC
Created attachment 111585 [details]
ALSA test log

I've applied those changes for the ALSA config. I ran the test as ./a.out front:0 0 4 > alsa-test.log and here's the output. I stopped it with Ctrl-C. When I set the fillrate less than 4, it stops with the assertion failure like before. Setting the fillrate to 1 with playback test mode (./a.out front:0 1 1 > alsa1-test.log) doesn't fail.

That aside, I don't understand how IEC capture is related to the playback issue though. The game doesn't use microphone.
Comment 21 Raymond 2014-12-31 16:46:01 UTC
those locks in hook plugin prevent you running

aplay -D iec958:CARD=CA0106 stereo48000.wav

and 

arecord -D iec958:CARD=CA0106 test.wav


at same time


those message "Cannot lock ctl elem" should disaapear when you can playback and capture iec958 at same time ?




post pulseaudio verbose log
Comment 22 Raymond 2015-01-01 06:21:42 UTC
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-September/081501.html

you can try Alexander's pcm_avail.c to find out whether your ca0106 can report DMA_RESIDUE_GRANULARITY_BURST ?
Comment 23 Raymond 2015-01-01 09:10:15 UTC
do the error 

alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_START failed (-77)

appear when  you fix the error "cannot lock ctl elem" as pulseaudio start the probing of those surround40, 51 and71 ?
Comment 24 Raymond 2015-01-01 09:17:25 UTC
http://mailman.alsa-project.org/pipermail/alsa-devel/2008-October/011913.html

: module-alsa-sink.c: Using 4 fragments of size 8816 bytes, buffer time is 99.95ms
D: module-alsa-sink.c: hwbuf_unused_frames=0
D: module-alsa-sink.c: setting avail_min=1
I: module-alsa-sink.c: Volume ranges from 0 to 31.
I: module-alsa-sink.c: Volume ranges from -46.50 dB to 0.00 dB.
I: alsa-util.c: ALSA device lacks separate volumes control for channel 'rear-left'
I: module-alsa-sink.c: Using hardware volume control. Hardware dB scale supported.
D: alsa-util.c: snd_pcm_dump():
D: alsa-util.c: Multi PCM
D: alsa-util.c:   Channel bindings:
D: alsa-util.c:     0: slave 0, channel 0
D: alsa-util.c:     1: slave 0, channel 1
D: alsa-util.c:     2: slave 1, channel 0
D: alsa-util.c:     3: slave 1, channel 1
D: alsa-util.c: Its setup is:
D: alsa-util.c:   stream       : PLAYBACK
D: alsa-util.c:   access       : RW_INTERLEAVED
D: alsa-util.c:   format       : S16_LE
D: alsa-util.c:   subformat    : STD
D: alsa-util.c:   channels     : 4
D: alsa-util.c:   rate         : 44100
D: alsa-util.c:   exact rate   : 44100 (44100/1)
D: alsa-util.c:   msbits       : 16
D: alsa-util.c:   buffer_size  : 4408
D: alsa-util.c:   period_size  : 1102
D: alsa-util.c:   period_time  : 24988
D: alsa-util.c:   tstamp_mode  : NONE
D: alsa-util.c:   period_step  : 1
D: alsa-util.c:   avail_min    : 1102
D: alsa-util.c:   period_event : 0
D: alsa-util.c:   start_threshold  : -1
D: alsa-util.c:   stop_threshold   : -1
D: alsa-util.c:   silence_threshold: 0
D: alsa-util.c:   silence_size : 0
D: alsa-util.c:   boundary     : 1155530752
D: alsa-util.c: Slave #0: Hooks PCM
D: alsa-util.c: Its setup is:
D: alsa-util.c:   stream       : PLAYBACK
D: alsa-util.c:   access       : MMAP_INTERLEAVED
D: alsa-util.c:   format       : S16_LE
D: alsa-util.c:   subformat    : STD
D: alsa-util.c:   channels     : 2
D: alsa-util.c:   rate         : 44100
D: alsa-util.c:   exact rate   : 44100 (44100/1)
D: alsa-util.c:   msbits       : 16
D: alsa-util.c:   buffer_size  : 4408
D: alsa-util.c:   period_size  : 1102
D: alsa-util.c:   period_time  : 24988
D: alsa-util.c:   tstamp_mode  : NONE
D: alsa-util.c:   period_step  : 1
D: alsa-util.c:   avail_min    : 1102
D: alsa-util.c:   period_event : 0
D: alsa-util.c:   start_thr
D: module-alsa-sink.c: Thread starting up
D: rtpoll.c: Acquired POSIX realtime signal SIGRTMIN+29
D: module-alsa-sink.c: Read hardware volume: 0:  87% 1:  87% 2:  87% 3:  87%
I: module-alsa-sink.c: Starting playback.
I: (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_START failed


the playback stream has been started and pcm state is running but pulseaudio still call snd_pcm_start()
Comment 25 Raymond 2015-01-01 15:44:57 UTC
seem default sample 16 bits has no effect on format , pulseaudio prefer 32 bits


Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] card.c: Created 2 "alsa_card.pci-0000_06_00.0"
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-util.c: cannot disable ALSA period wakeups
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-util.c: ALSA period wakeups were not disabled
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-sink.c: Successfully opened device front:0.
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-sink.c: Selected mapping 'Analog Stereo' (analog-stereo).
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-sink.c: Successfully enabled mmap() mode.
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-sink.c: Successfully enabled timer-based scheduling mode.
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] (alsa-lib)control.c: Invalid CTL front:0
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-util.c: Unable to attach to mixer front:0: No such file or directory
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] alsa-util.c: Successfully attached to mixer 'hw:0'
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] module-device-restore.c: Restoring port for sink sink:alsa_output.pci-0000_06_00.0.analog-stereo.
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] module-device-restore.c: Restoring volume for sink alsa_output.pci-0000_06_00.0.analog-stereo: front-left: 65536 / 100%,   front-right: 65536 / 100%
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] sink.c: Default and alternate sample rates are the same.
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] sink.c: Created sink 0 "alsa_output.pci-0000_06_00.0.analog-stereo" with sample spec s32le 2ch 48000Hz and channel map front-left,front-right
Dec 30 22:56:29 homecomp pulseaudio[1103]: [pulseaudio] sink.c:     alsa.resolution_bits = "32"
Comment 26 rkfg 2015-01-01 15:56:54 UTC
Created attachment 111615 [details]
Fixed PA log

It now doesn't report "Cannot lock ctl elem".
Comment 27 rkfg 2015-01-01 15:59:40 UTC
Created attachment 111616 [details]
pcm_avail log

Here's the output of pcm_avail.c program.
Comment 28 rkfg 2015-01-01 16:02:09 UTC
(In reply to Raymond from comment #25)
> seem default sample 16 bits has no effect on format , pulseaudio prefer 32
> bits

No, it does. I have these options uncommented in my daemon.conf:

default-sample-format = s32le
default-sample-rate = 48000

I have them enabled for some time and PA startup logs were provided with them on. If that's wrong tell me and I'll provide logs without them.
Comment 29 Raymond 2015-01-02 01:07:55 UTC
(In reply to rkfg from comment #27)
> Created attachment 111616 [details]
> pcm_avail log
> 
> Here's the output of pcm_avail.c program.

avail increment at 8 frames which is less than min period size 16 and period size 1024

this mean some tsched feature are supported

hwbuf_unused can be set to non zero (e.g. multiple of 8 frames instead of period size)


min_period_size: 16 frames, dir: 0
Playback hwparams: FIFO size is 0
Hardware PCM card 0 'CA0106' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 4096
  period_size  : 1024
  period_time  : 21333
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 1024
  period_event : 0
  start_threshold  : 1024
  stop_threshold   : 4096
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
  appl_ptr     : 0
  hw_ptr       : 0
Playing silence
Available: 64, loop iteration: 0
Available: 72, loop iteration: 8
Available: 80, loop iteration: 16
Available: 88, loop iteration: 24
Available: 96, loop iteration: 31
Comment 30 Raymond 2015-01-02 01:42:02 UTC
(In reply to rkfg from comment #26)
> Created attachment 111615 [details]
> Fixed PA log
> 
> It now doesn't report "Cannot lock ctl elem".

it is strange that pulseaudio still don't probe surround profiles




pactl list should list those surround profiles similar to  https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1299857



		device.vendor.name = "Creative Labs"
		device.product.name = "CA0106 Soundblaster"
		device.string = "0"
		device.description = "CA0106 Soundblaster"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	profiles:
		output:analog-stereo: Analog Stereo Output (priority 6000)
		output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (priority 6060)
		output:analog-stereo+input:iec958-stereo: Analog Stereo Output + Digital Stereo (IEC958) Input (priority 6055)
		output:analog-surround-40: Analog Surround 4.0 Output (priority 700)
		output:analog-surround-40+input:analog-stereo: Analog Surround 4.0 Output + Analog Stereo Input (priority 760)
		output:analog-surround-40+input:iec958-stereo: Analog Surround 4.0 Output + Digital Stereo (IEC958) Input (priority 755)
Comment 31 Raymond 2015-01-02 03:56:07 UTC
can you post the output of alsa-info.sh ?

did it support 7.1 since there are only 4  jacks ?


speaker-test -c 4 -t wav -D surround40:CARD=CA0106 


speaker-test -c 6 -t wav -D surround51:CARD=CA0106 

speaker-test -c 8 -t wav -D surround71:CARD=CA0106
Comment 32 rkfg 2015-01-02 10:17:53 UTC
Created attachment 111649 [details]
ALSA info

Here's the output of alsa-info.sh. The speaker test works, all three commands without errors. However, I only have 2 speakers so I hear "front left" and "front right".
Comment 33 Raymond 2015-01-02 13:17:44 UTC
analog source seem supported by pulseaudio

http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa/mixer/paths/analog-input.conf.common?id=67e3925795ad939f2c9acb3aa93122a18672fade

pactl list

do pulseaudio show four input ports : phone, mic, line in and aux


SImple mixer control 'Analog Source',0
  Capabilities: cenum
  Items: 'Phone' 'Mic' 'Line in' 'Aux'
  Item0: 'Mic'
Simple mixer control 'CAPTURE feedback',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 0 [0%] [-99999.99dB]
  Front Right: Playback 0 [0%] [-99999.99dB]
Simple mixer control 'Digital Source',0
  Capabilities: cenum
  Items: 'IEC958 out' 'i2s mixer out' 'IEC958 in' 'i2s in' 'AC97 in' 'SRC out'
  Item0: 'i2s in'
Simple mixer control 'Shared Mic/Line in',0
  Capabilities: cenum
  Items: 'Line in' 'Mic in'
  Item0: 'Mic in'
Comment 34 Raymond 2015-01-02 13:31:33 UTC
CA0106 use specific name, you may need to add them to 

http://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/modules/alsa/mixer/paths/analog-output.conf

Simple mixer control 'Analog Center/LFE',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 207 [81%] [0.00dB]
  Front Right: Playback 207 [81%] [0.00dB]
Simple mixer control 'Analog Front',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 207 [81%] [0.00dB]
  Front Right: Playback 207 [81%] [0.00dB]
Simple mixer control 'Analog Rear',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 207 [81%] [0.00dB]
  Front Right: Playback 207 [81%] [0.00dB]
Simple mixer control 'Analog Side',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 207 [81%] [0.00dB]
  Front Right: Playback 207 [81%] [0.00dB]
Comment 35 Raymond 2015-01-02 14:38:40 UTC
Jan 01 18:52:27 homecomp pulseaudio[14807]: [pulseaudio] alsa-mixer.c: Skipping profile output:iec958-stereo+input:iec958-stereo - will not be able to open input:iec958-stereo

seem cannot opem iec958 for input


can you specify device 0

+       capture.pcm {
+                type hw
+                card $CARD
+                 device 0
+
Comment 36 Raymond 2015-01-02 16:33:26 UTC
http://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/modules/alsa/mixer/profile-sets/default.conf


[Mapping iec958-stereo]
device-strings = iec958:%f
channel-map = left,right
paths-input = iec958-stereo-input
paths-output = iec958-stereo-output
priority = 5


as pulseaudio already define iec958-stereo-input


when there is iec958-stereo-output.conf

why there is no iec958-stereo-input.conf 



http://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/modules/alsa/mixer/paths
Comment 37 rkfg 2015-01-02 17:28:19 UTC
Created attachment 111662 [details]
Pulse log

(In reply to Raymond from comment #35)
> can you specify device 0
> 
> +       capture.pcm {
> +                type hw
> +                card $CARD
> +                 device 0
> +

Added this, here's the startup log.
Comment 38 rkfg 2015-01-02 17:29:03 UTC
Created attachment 111663 [details]
pactl list log

Log of pactl list.
Comment 39 Raymond 2015-01-03 04:41:34 UTC
arecord -v -d 1 -D iec958:CARD=CA0106 -f dat -t wav --dump-hw-params test.wav
Comment 40 Raymond 2015-01-03 06:38:58 UTC
device.description = "CA0106 Soundblaster (SB0410 SBLive! 24-bit) Analog Stereo"
		alsa.mixer_name = "CA0106"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	Ports:
		analog-input-mic: Microphone (priority: 8700)
		analog-input-aux;input-microphone+input-microphone: Analog Input / Microphone / Microphone (priority: 8000)
		analog-input-aux;input-microphone+input-linein: Analog Input / Microphone / Line In (priority: 8000)
		analog-input-aux;input-linein+input-microphone: Analog Input / Line In / Microphone (priority: 8000)
		analog-input-aux;input-linein+input-linein: Analog Input / Line In / Line In (priority: 8000)
		analog-input-aux;input+input-microphone: Analog Input / Input / Microphone (priority: 8000)
		analog-input-aux;input+input-linein: Analog Input / Input / Line In (priority: 8000)
	Active Port: analog-input-mic
	Formats:
		pcm

seem  phone is still missing


SImple mixer control 'Analog Source',0
  Capabilities: cenum
  Items: 'Phone' 'Mic' 'Line in' 'Aux'
  Item0: 'Mic'



Simple mixer control 'Line in',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 255
  Front Left: Capture 0 [0%] [-99999.99dB]
  Front Right: Capture 0 [0%] [-99999.99dB]
Simple mixer control 'Mic',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 255
  Front Left: Capture 255 [100%] [24.00dB]
  Front Right: Capture 255 [100%] [24.00dB]
Simple mixer control 'Phone',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 255
  Front Left: Capture 0 [0%] [-99999.99dB]
  Front Right: Capture 0 [0%] [-99999.99dB]
Simple mixer control 'Aux',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 255
  Front Left: Capture 0 [0%] [-99999.99dB]
  Front Right: Capture 0 [0%] [-99999.99dB]
Comment 41 rkfg 2015-01-03 11:35:08 UTC
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
HW Params of device "iec958:CARD=CA0106":
--------------------
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE S32_LE
SUBFORMAT:  STD
SAMPLE_BITS: [16 32]
FRAME_BITS: [32 64]
CHANNELS: 2
RATE: [48000 192000]
PERIOD_TIME: (41 170334)
PERIOD_SIZE: [8 8176]
PERIOD_BYTES: [64 32704]
PERIODS: 2
BUFFER_TIME: (83 340667)
BUFFER_SIZE: [16 16352]
BUFFER_BYTES: [64 65408]
TICK_TIME: ALL
--------------------
Hardware PCM card 0 'CA0106' device 0 subdevice 0
Its setup is:
  stream       : CAPTURE
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 8160
  period_size  : 4080
  period_time  : 85000
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 4080
  period_event : 0
  start_threshold  : 1
  stop_threshold   : 8160
  silence_threshold: 0
  silence_size : 0
  boundary     : 9187343239835811840
  appl_ptr     : 0
  hw_ptr       : 0
overrun!!! (at least 0.017 ms long)
Status:
  state       : XRUN
  trigger_time: 847573.10484226
  tstamp      : 847573.10498485
  delay       : 0
  avail       : 8160
  avail_max   : 8160
^CAborted by signal Interrupt...
Comment 42 Raymond 2015-01-03 16:20:16 UTC
does analog capture also overrun ?

arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 test.wav



https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/tree/sound/pci/ca0106/ca0106_mixer.c

if your sb0410 only have four jacks and support 7.1

it need snd_ca0106_capture_line_in_side_out which change blue line in jack as side line out jack 


if (emu->details->i2c_adc == 1) {
		ADD_CTLS(emu, snd_ca0106_volume_i2c_adc_ctls);
		if (emu->details->gpio_type == 1)
			err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu));
		else  /* gpio_type == 2 */
			err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_line_in_side_out, emu));
		if (err < 0)
			return err;
	}
Comment 43 rkfg 2015-01-03 16:22:06 UTC
It does:
> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.084 ms long)
^CAborted by signal Interrupt...
Comment 44 Raymond 2015-01-03 16:25:03 UTC
https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/plain/sound/pci/ca0106/ca0106_main.c

GENERAL INFO:
 *    Model: SB0410
 *    P17 Chip: CA0106-DAT
 *    AC97 Codec: None
 *    ADC: WM8775EDS (4 Channel)
 *    DAC: CS4382 (114 dB, 24-Bit, 192 kHz, 8-Channel D/A Converter with DSD Support)


	 /* New Sound Blaster Live! 7.1 24bit. This does not have an AC97. 53SB041000001 */
	 { .serial = 0x10061102,
	   .name   = "Live! 7.1 24bit [SB0410]",
	   .gpio_type = 1,
	   .i2c_adc = 1 } ,
Comment 45 rkfg 2015-01-03 16:27:37 UTC
BTW, my mic is connected to the blue jack, not the usual pink one. This is the only configuration I've found to be working, others result in noise or silence. The mic is a bit more quiet (not _almost silent_ as if it's connected to a Line-In jack, just not comfortable enough) than it was on the ALC889 internal card so I had to increase the volume via software means. There's no boost setting in the alsamixer but PulseAudio can handle that.
Comment 46 Raymond 2015-01-03 16:48:33 UTC
(In reply to rkfg from comment #43)
> It does:
> > arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 test.wav
> Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz,
> Stereo
> overrun!!! (at least 0.084 ms long)
> ^CAborted by signal Interrupt...

https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/sound/pci/ca0106/ca0106_main.c?id=34fdeb2d07102e07ecafe79dec170bd6733f2e56

you have to report to the author if overrun occur 

do it work better if you specify buffer size power of two (eg. 1024, 2048 or 4096


arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size= 2048  test.wav
Comment 47 rkfg 2015-01-03 16:56:33 UTC
It happens more likely with small buffers and sometimes doesn't happen with larger buffer. However, this behavior is not consistent:
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=2048 test.wav  
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.025 ms long)
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=4096 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.023 ms long)
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=8192 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.023 ms long)
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=16384 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.028 ms long)
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=32768 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.045 ms long)
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=65536 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.039 ms long)
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=131072 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.046 ms long)
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=262144 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=262144 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.039 ms long)
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=524288 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=524288 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.046 ms long)
^CAborted by signal Interrupt...
%[homecomp]:[/tmp/test]> arecord -f dat -D hw:CARD=CA0106 -t wav -d 5 --buffer-size=524288 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
overrun!!! (at least 0.044 ms long)
^CAborted by signal Interrupt...

Ok, what about the original issue? I don't quite get what we are doing here. It looks like we're debugging something completely unrelated, for example, I don't use the digital output like iec958 and this game doesn't capture sound so this is probably unrelated, too. I'm fine with improving ALSA but all this looks like other bugs and should probably be filed separately...
Comment 48 David Henningsson 2015-01-05 11:13:10 UTC
Raymond tends to be side-tracked from time to time and ask questions which are related to your original issue. Also apologies for not having read the entire thread through.

PulseAudio closes the audio stream five seconds after no applications are active, so that's probably when the issue goes back to normal too.

The resampler changed from "null" to "copy" means that we have a resampler engine active for the stream, but all it does is to convert from s16le (as being input by Chrome) to s32le.

You're probably hitting a driver issue, but I wonder how we can prove it. Also the fact that it seems to hit one application only is a bit strange, maybe it's related to the requested latency by that specific application or something.
Comment 49 Raymond 2015-01-05 12:43:28 UTC
did your sb0410 have these two chips ?

ADC: WM8775EDS (4 Channel)
  DAC: CS4382 


if you look at cs4382 datasheet , it has three modes which can double or quad the speed 


for wm8775 which does not have any boost for mic, you have to ask the author who add support of mic line in switch since the datasheet does not mention any usage of input pins as mic

https://bugzilla.kernel.org/enter_bug.cgi?product=Drivers

you have to file upstream bug for overrun when recording using arecord
Comment 51 Raymond 2015-01-05 13:01:09 UTC
http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=1af088e39b75a0a0897c7036487b143e983cd423;hp=57b5076c30b3453ee843912c0aeb3df8dbee3f68

it is strange the pulseaudio no longer probe surround40 , 51, and 71


your log have no traces of surround21 too


http://git.alsa-project.org/?p=alsa-lib.git;a=blob_plain;f=test/chmap.c;hb=HEAD

chmap -D surround40 query

chmap -D surround40 get
Comment 52 rkfg 2015-01-05 15:11:29 UTC
(In reply to Raymond from comment #49)
> did your sb0410 have these two chips ?
> 
> ADC: WM8775EDS (4 Channel)
>   DAC: CS4382 
> 
My card looks exactly like this: http://www.ixbt.com/multimedia/creative-live!24bit/card-big.jpg
Probably, it has all these chips.
Comment 53 Raymond 2015-01-05 15:54:13 UTC
http://www.ixbt.com/multimedia/creative-live!24bit.shtml

seem need specific jack to support 7.1
Comment 54 Raymond 2015-01-05 16:18:59 UTC
control.29 {
		iface MIXER
		name 'Phone Capture Volume'
		value.0 0
		value.1 0
		comment {
			access 'read write'
			type INTEGER
			count 2
			range '0 - 255'
			dbmin -9999999
			dbmax 2400
			dbvalue.0 -9999999
			dbvalue.1 -9999999
		}
	}
	control.30 {
		iface MIXER
		name 'Mic Capture Volume'
		value.0 255
		value.1 255
		comment {
			access 'read write'
			type INTEGER
			count 2
			range '0 - 255'
			dbmin -9999999
			dbmax 2400
			dbvalue.0 2400
			dbvalue.1 2400
		}
	}
	control.31 {
		iface MIXER
		name 'Line in Capture Volume'
		value.0 0
		value.1 0
		comment {
			access 'read write'
			type INTEGER
			count 2
			range '0 - 255'
			dbmin -9999999
			dbmax 2400
			dbvalue.0 -9999999
			dbvalue.1 -9999999
		}
	}
	control.32 {
		iface MIXER
		name 'Aux Capture Volume'
		value.0 0
		value.1 0
		comment {
			access 'read write'
			type INTEGER
			count 2
			range '0 - 255'
			dbmin -9999999
			dbmax 2400
			dbvalue.0 -9999999
			dbvalue.1 -9999999
		}
	}

refer to table 11 wm8775 datasheet

0dB is at 0xcf and 24 dB at 0xff
Comment 56 Raymond 2015-01-06 00:50:53 UTC
 Four Stereo ADC Inputs with Analogue Gain Adjust from +24dB to –21dB in 0.5dB Steps
 Digital Gain Adjust from -21.5dB to -103dB.
 

table 10 of wm8775 mention that 0.5 dB per steps and min 0 is mute

As max 255 is +24 dB , 0xcf is 0 dB , 

step 1 is -103 dB





Source #1
	State: SUSPENDED
	Name: alsa_input.pci-0000_06_00.0.analog-stereo
	Description: CA0106 Soundblaster (SB0410 SBLive! 24-bit) Analog Stereo
	Driver: module-alsa-card.c
	Sample Specification: s32le 2ch 48000Hz
	Channel Map: front-left,front-right
	Owner Module: 8
	Mute: no
	Volume: front-left: 99957 / 153% / 11.00 dB,   front-right: 99957 / 153% / 11.00 dB
	        balance 0.00
	Base Volume: 26090 /  40% / -24.00 dB
	Monitor of Sink: n/a
	Latency: 0 usec, configured 0 usec
	Flags: HARDWARE HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY
Comment 57 Raymond 2015-01-06 01:09:58 UTC
seem 

chmap -Dsurround41:CARD=CA0106 query 


fail but


chmap -Dsurround41:CARD=CA0106 get

return channel map



in ca0106.conf

there is no definition of ca0106.pcm.surround41

just 

 <confdir:pcm/surround21.conf>
  <confdir:pcm/surround41.conf>
 <confdir:pcm/surround50.conf>





Do surround21 , surround41 appear in 

aplay -L
Comment 58 Raymond 2015-01-06 02:03:25 UTC
static unsigned int i2c_adc_init[][2] = {
	{ 0x17, 0x00 }, /* Reset */
	{ 0x07, 0x00 }, /* Timeout */
	{ 0x0b, 0x22 },  /* Interface control */
	{ 0x0c, 0x22 },  /* Master mode control */
	{ 0x0d, 0x08 },  /* Powerdown control */
	{ 0x0e, 0xcf },  /* Attenuation Left  0x01 = -103dB, 0xff = 24dB */
	{ 0x0f, 0xcf },  /* Attenuation Right 0.5dB steps */
	{ 0x10, 0x7b },  /* ALC Control 1 */
	{ 0x11, 0x00 },  /* ALC Control 2 */
	{ 0x12, 0x32 },  /* ALC Control 3 */
	{ 0x13, 0x00 },  /* Noise gate control */
	{ 0x14, 0xa6 },  /* Limiter control */
	{ 0x15, ADC_MUX_LINEIN },  /* ADC Mixer control */

seem default is linein and 0dB
Comment 59 Raymond 2015-01-06 05:03:49 UTC
https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/sound/pci/ca0106/ca0106_mixer.c?id=fff36e472b4315df77513f4339c5c199c6aad28b

static DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1);

the scale only define step 1 is -103.50 dB and step size 0.5dB
Comment 60 Raymond 2015-01-06 08:01:18 UTC
for unknown reason which pulseaudio did not probe surround40 



pulseaudio still using timer base scheduling in your last log

but it was strange tradtional mode was used in your first log



20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     alsa.name = "CA0106"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     alsa.id = "ca0106"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     alsa.subdevice = "0"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     alsa.subdevice_name = "subdevice #0"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     alsa.device = "0"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     alsa.card = "0"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     alsa.card_name = "CA0106"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     alsa.long_card_name = "Live! 7.1 24bit [SB0410] at 0xcf00 irq 19"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     alsa.driver_name = "snd_ca0106"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.bus_path = "pci-0000:06:00.0"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     sysfs.path = "/devices/pci0000:00/0000:00:1c.3/0000:05:00.0/0000:06:00.0/sound/card0"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.bus = "pci"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.vendor.id = "1102"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.vendor.name = "Creative Labs"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.product.id = "0007"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.product.name = "CA0106 Soundblaster (SB0410 SBLive! 24-bit)"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.string = "front:0"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.buffering.buffer_size = "65536"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.buffering.fragment_size = "32768"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.access_mode = "mmap+timer"
Jan 02 20:25:49 homecomp pulseaudio[11971]: [pulseaudio] sink.c:     device.profile.name = "analog-stereo"










Dec 25 19:33:27 homecomp pulseaudio[1911]:     module-stream-restore.id = "sink-input-by-application-name:paplay"
Dec 25 19:33:27 homecomp pulseaudio[1911]: Requested tlength=2000.00 ms, minreq=20.00 ms
Dec 25 19:33:27 homecomp pulseaudio[1911]: Traditional mode enabled, modifying sink usec only for compat with minreq.
Dec 25 19:33:27 homecomp pulseaudio[1911]: Requested latency=1960.00 ms, Received latency=341.33 ms
Dec 25 19:33:27 homecomp pulseaudio[1911]: memblockq requested: maxlength=4194304, tlength=192000, base=2, prebuf=190082, minreq=1920 maxrewind=0
Dec 25 19:33:27 homecomp pulseaudio[1911]: memblockq sanitized: maxlength=4194304, tlength=192000, base=2, prebuf=190082, minreq=1920 maxrewind=0
Dec 25 19:33:27 homecomp pulseaudio[1911]: Final latency 2341.33 ms = 1960.00 ms + 2*20.00 ms + 341.33 ms
Dec 25 19:33:27 homecomp pulseaudio[1911]: Latency set to 26.00ms
Dec 25 19:33:27 homecomp pulseaudio[1911]: hwbuf_unused=60544
Dec 25 19:33:27 homecomp pulseaudio[1911]: setting avail_min=15617


the driver need to provide accurate hw_ptr  position in order to set hwbuf_unused to non zero

the actual buffer used = buffer size (65536) - hwbuf_unused (60544) is 5012 bytes
Comment 61 rkfg 2015-01-06 12:52:19 UTC
(In reply to Raymond from comment #57)
> Do surround21 , surround41 appear in 
> 
> aplay -L

null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
default:CARD=CA0106
    CA0106, CA0106
    Default Audio Device
sysdefault:CARD=CA0106
    CA0106, CA0106
    Default Audio Device
front:CARD=CA0106,DEV=0
    CA0106, CA0106
    Front speakers
rear:CARD=CA0106,DEV=0
    CA0106, CA0106
    Rear speakers
center_lfe:CARD=CA0106,DEV=0
    CA0106, CA0106
    Center and Subwoofer speakers
side:CARD=CA0106,DEV=0
    CA0106, CA0106
    Side speakers
surround21:CARD=CA0106,DEV=0
    CA0106, CA0106
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=CA0106,DEV=0
    CA0106, CA0106
    4.0 Surround output to Front and Rear speakers
surround41:CARD=CA0106,DEV=0
    CA0106, CA0106
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=CA0106,DEV=0
    CA0106, CA0106
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=CA0106,DEV=0
    CA0106, CA0106
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=CA0106,DEV=0
    CA0106, CA0106
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=CA0106,DEV=0
    CA0106, CA0106
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=CA0106,DEV=0
    CA0106, CA0106
    Direct sample mixing device
dmix:CARD=CA0106,DEV=1
    CA0106, CA0106
    Direct sample mixing device
dmix:CARD=CA0106,DEV=2
    CA0106, CA0106
    Direct sample mixing device
dmix:CARD=CA0106,DEV=3
    CA0106, CA0106
    Direct sample mixing device
dsnoop:CARD=CA0106,DEV=0
    CA0106, CA0106
    Direct sample snooping device
dsnoop:CARD=CA0106,DEV=1
    CA0106, CA0106
    Direct sample snooping device
dsnoop:CARD=CA0106,DEV=2
    CA0106, CA0106
    Direct sample snooping device
dsnoop:CARD=CA0106,DEV=3
    CA0106, CA0106
    Direct sample snooping device
hw:CARD=CA0106,DEV=0
    CA0106, CA0106
    Direct hardware device without any conversions
hw:CARD=CA0106,DEV=1
    CA0106, CA0106
    Direct hardware device without any conversions
hw:CARD=CA0106,DEV=2
    CA0106, CA0106
    Direct hardware device without any conversions
hw:CARD=CA0106,DEV=3
    CA0106, CA0106
    Direct hardware device without any conversions
plughw:CARD=CA0106,DEV=0
    CA0106, CA0106
    Hardware device with all software conversions
plughw:CARD=CA0106,DEV=1
    CA0106, CA0106
    Hardware device with all software conversions
plughw:CARD=CA0106,DEV=2
    CA0106, CA0106
    Hardware device with all software conversions
plughw:CARD=CA0106,DEV=3
    CA0106, CA0106
    Hardware device with all software conversions
default:CARD=PCH
    HDA Intel PCH, ALC889 Analog
    Default Audio Device
sysdefault:CARD=PCH
    HDA Intel PCH, ALC889 Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    Front speakers
surround21:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Digital
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    Direct sample mixing device
dmix:CARD=PCH,DEV=1
    HDA Intel PCH, ALC889 Digital
    Direct sample mixing device
dsnoop:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    Direct sample snooping device
dsnoop:CARD=PCH,DEV=1
    HDA Intel PCH, ALC889 Digital
    Direct sample snooping device
hw:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    Direct hardware device without any conversions
hw:CARD=PCH,DEV=1
    HDA Intel PCH, ALC889 Digital
    Direct hardware device without any conversions
plughw:CARD=PCH,DEV=0
    HDA Intel PCH, ALC889 Analog
    Hardware device with all software conversions
plughw:CARD=PCH,DEV=1
    HDA Intel PCH, ALC889 Digital
    Hardware device with all software conversions
hdmi:CARD=NVidia,DEV=0
    HDA NVidia, HDMI 0
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=1
    HDA NVidia, HDMI 1
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=2
    HDA NVidia, HDMI 2
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=3
    HDA NVidia, HDMI 3
    HDMI Audio Output
dmix:CARD=NVidia,DEV=3
    HDA NVidia, HDMI 0
    Direct sample mixing device
dmix:CARD=NVidia,DEV=7
    HDA NVidia, HDMI 1
    Direct sample mixing device
dmix:CARD=NVidia,DEV=8
    HDA NVidia, HDMI 2
    Direct sample mixing device
dmix:CARD=NVidia,DEV=9
    HDA NVidia, HDMI 3
    Direct sample mixing device
dsnoop:CARD=NVidia,DEV=3
    HDA NVidia, HDMI 0
    Direct sample snooping device
dsnoop:CARD=NVidia,DEV=7
    HDA NVidia, HDMI 1
    Direct sample snooping device
dsnoop:CARD=NVidia,DEV=8
    HDA NVidia, HDMI 2
    Direct sample snooping device
dsnoop:CARD=NVidia,DEV=9
    HDA NVidia, HDMI 3
    Direct sample snooping device
hw:CARD=NVidia,DEV=3
    HDA NVidia, HDMI 0
    Direct hardware device without any conversions
hw:CARD=NVidia,DEV=7
    HDA NVidia, HDMI 1
    Direct hardware device without any conversions
hw:CARD=NVidia,DEV=8
    HDA NVidia, HDMI 2
    Direct hardware device without any conversions
hw:CARD=NVidia,DEV=9
    HDA NVidia, HDMI 3
    Direct hardware device without any conversions
plughw:CARD=NVidia,DEV=3
    HDA NVidia, HDMI 0
    Hardware device with all software conversions
plughw:CARD=NVidia,DEV=7
    HDA NVidia, HDMI 1
    Hardware device with all software conversions
plughw:CARD=NVidia,DEV=8
    HDA NVidia, HDMI 2
    Hardware device with all software conversions
plughw:CARD=NVidia,DEV=9
    HDA NVidia, HDMI 3
    Hardware device with all software conversions
Comment 62 Raymond 2015-01-07 01:12:21 UTC
what is the smallest buffer size which aplay without underrun ? 1024,512,256,128,64,...


aplay -D front:CARD=CA0106 -v --buffer-size=1024 stereo48000.wav


19:29:42 homecomp pulseaudio[1911]: Protocol version: remote 26, local 29
Dec 25 19:29:42 homecomp pulseaudio[1911]: Got credentials: uid=1000 gid=1000 success=1
Dec 25 19:29:42 homecomp pulseaudio[1911]: SHM possible: yes
Dec 25 19:29:42 homecomp pulseaudio[1911]: Negotiated SHM: yes
Dec 25 19:29:42 homecomp pulseaudio[1911]: Looking for .desktop file for Transistor.bin.x86_64
Dec 25 19:29:42 homecomp pulseaudio[1911]: Not setting device for stream ALSA Playback, because it lacks role.
Dec 25 19:29:42 homecomp pulseaudio[1911]: Negotiated format: pcm, format.sample_format = "\"s16le\""  format.rate = "48000"  format.channels = "2"  format.channel_map = "\"front-left,front-right\""
Dec 25 19:29:42 homecomp pulseaudio[1911]: Sink alsa_output.pci-0000_06_00.0.analog-stereo becomes busy, resuming.
Dec 25 19:29:42 homecomp pulseaudio[1911]: memblockq requested: maxlength=33554432, tlength=0, base=4, prebuf=0, minreq=1 maxrewind=0
Dec 25 19:29:42 homecomp pulseaudio[1911]: memblockq sanitized: maxlength=33554432, tlength=33554432, base=4, prebuf=0, minreq=4 maxrewind=0
Dec 25 19:29:42 homecomp pulseaudio[1911]: Created input 15 "ALSA Playback" on alsa_output.pci-0000_06_00.0.analog-stereo with sample spec s16le 2ch 48000Hz and channel map front-left,front-right
Dec 25 19:29:42 homecomp pulseaudio[1911]:     media.name = "ALSA Playback"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.name = "ALSA plug-in [Transistor.bin.x86_64]"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     native-protocol.peer = "UNIX socket client"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     native-protocol.version = "26"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.id = "9536"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.user = "rkfg"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.host = "homecomp"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.binary = "Transistor.bin.x86_64"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.language = "en_GB.UTF-8"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     window.x11.display = ":0.0"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.machine_id = "3be8f38f291dd2003af500d051c0a849"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.session_id = "10"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     module-stream-restore.id = "sink-input-by-application-name:ALSA plug-in [Transistor.bin.x86_64]"
Dec 25 19:29:42 homecomp pulseaudio[1911]: Requested tlength=85.33 ms, minreq=21.33 ms
Dec 25 19:29:42 homecomp pulseaudio[1911]: Early requests mode enabled, configuring sink latency to minreq.
Dec 25 19:29:42 homecomp pulseaudio[1911]: Requested latency=21.33 ms, Received latency=26.00 ms
Dec 25 19:29:42 homecomp pulseaudio[1911]: memblockq requested: maxlength=4194304, tlength=16384, base=4, prebuf=11396, minreq=4992 maxrewind=0
Dec 25 19:29:42 homecomp pulseaudio[1911]: memblockq sanitized: maxlength=4194304, tlength=16384, base=4, prebuf=11396, minreq=4992 maxrewind=0
Dec 25 19:29:42 homecomp pulseaudio[1911]: Final latency 111.33 ms = 33.33 ms + 2*26.00 ms + 26.00 ms
Dec 25 19:29:42 homecomp pulseaudio[1911]: Latency set to 26.00ms
Dec 25 19:29:42 homecomp pulseaudio[1911]: hwbuf_unused=60544
Dec 25 19:29:42 homecomp pulseaudio[1911]: setting avail_min=15617
Dec 25 19:29:42 homecomp pulseaudio[1911]: Requested volume: front-left: 52559 /  80% / -5.75 dB,   front-right: 52559 /  80% / -5.75 dB
Dec 25 19:29:42 homecomp pulseaudio[1911]: Got hardware volume: front-left: 53066 /  81% / -5.50 dB,   front-right: 53066 /  81% / -5.50 dB
Dec 25 19:29:42 homecomp pulseaudio[1911]: Calculated software volume: front-left: 64910 /  99% / -0.25 dB,   front-right: 64910 /  99% / -0.25 dB (accurate-enough=yes)
Dec 25 19:29:42 homecomp pulseaudio[1911]: Volume not changing
Dec 25 19:29:42 homecomp pulseaudio[1911]: Requesting rewind due to end of underrun.
Dec 25 19:29:42 homecomp pulseaudio[1911]: Requested to rewind 65536 bytes.
Dec 25 19:29:42 homecomp pulseaudio[1911]: Limited to 3904 bytes.
Dec 25 19:29:42 homecomp pulseaudio[1911]: before: 976
Dec 25 19:29:42 homecomp pulseaudio[1911]: after: 976
Dec 25 19:29:42 homecomp pulseaudio[1911]: Rewound 3904 bytes.
Dec 25 19:29:42 homecomp pulseaudio[1911]: Processing rewind...
Dec 25 19:29:42 homecomp pulseaudio[1911]: latency = 65877
Dec 25 19:29:42 homecomp pulseaudio[1911]: Have to rewind 3904 bytes on render memblockq.
Dec 25 19:29:42 homecomp pulseaudio[1911]: Have to rewind 3904 bytes on render memblockq.
Dec 25 19:29:42 homecomp pulseaudio[1911]: Have to rewind 3904 bytes on render memblockq.
Dec 25 19:29:42 homecomp pulseaudio[1911]: Processing rewind...
Dec 25 19:29:42 homecomp pulseaudio[1911]: Wakeup from ALSA!
Dec 25 19:29:42 homecomp pulseaudio[1911]: Wakeup from ALSA!
Dec 25 19:29:42 homecomp pulseaudio[1911]: Wakeup from ALSA!
Dec 25 19:30:19 homecomp pulseaudio[1911]: Requesting rewind due to corking
Dec 25 19:30:19 homecomp pulseaudio[1911]: Requested to rewind 65536 bytes.
Dec 25 19:30:19 homecomp pulseaudio[1911]: Limited to 4544 bytes.
Dec 25 19:30:19 homecomp pulseaudio[1911]: before: 1136
Dec 25 19:30:19 homecomp pulseaudio[1911]: after: 1136
Dec 25 19:30:19 homecomp pulseaudio[1911]: Rewound 4544 bytes.
Dec 25 19:30:19 homecomp pulseaudio[1911]: Processing rewind...
Dec 25 19:30:19 homecomp pulseaudio[1911]: latency = 1234
Dec 25 19:30:19 homecomp pulseaudio[1911]: Have to rewind 4544 bytes on render memblockq.
Dec 25 19:30:19 homecomp pulseaudio[1911]: Have to rewind 4544 bytes on render memblockq.
Dec 25 19:30:19 homecomp pulseaudio[1911]: Have to rewind 4544 bytes on render memblockq.
Dec 25 19:30:19 homecomp pulseaudio[1911]: Have to rewind 4544 bytes on implementor.
Dec 25 19:30:19 homecomp pulseaudio[1911]: Processing rewind...
Dec 25 19:30:19 homecomp pulseaudio[1911]: Found underrun 4864 bytes ago (128 bytes ahead in playback buffer)
Dec 25 19:30:19 homecomp pulseaudio[1911]: Found underrun 4864 bytes ago (64 bytes ahead in playback buffer)
Dec 25 19:30:19 homecomp pulseaudio[1911]: Latency set to 26.00ms
Dec 25 19:30:19 homecomp pulseaudio[1911]: hwbuf_unused=60544
Dec 25 19:30:19 homecomp pulseaudio[1911]: setting avail_min=15617
Comment 63 rkfg 2015-01-07 01:39:53 UTC
This command doesn't work, it says "aplay: set_params:1239: Channels count non available". The -D default:CARD=CA0106 variant works and it does not overrun. I only had overruns on recording (at least, explicit). That said, I've made a huge improvement in my system, I compiled a pf-kernel and set CONFIG_PREEMPT=y, CONFIG_HZ_1000=y and CONFIG_HZ=1000. The default Debian kernel is on 250 Hz and is not preemptible. Now that my kernel supports preemption I (crossing fingers) don't have ALSA over- and underruns anymore. They were quite sudden and audible as clicks/gaps. I saw this in the log:

Jan  4 20:25:15 homecomp pulseaudio[26848]: [alsa-sink-ca0106] alsa-sink.c: Scheduling delay of 11.42 ms > 11.31 ms, you might want to investigate this to improve latency...
Jan  4 20:25:15 homecomp pulseaudio[26848]: [alsa-sink-ca0106] alsa-sink.c: Underrun!
Jan  4 20:25:15 homecomp pulseaudio[26848]: [alsa-sink-ca0106] alsa-sink.c: Increasing minimal latency to 1.00 ms
Jan  4 20:25:15 homecomp pulseaudio[26848]: [alsa-sink-ca0106] alsa-sink.c: Latency set to 21.33ms
Jan  4 20:25:15 homecomp pulseaudio[26848]: [alsa-sink-ca0106] alsa-sink.c: hwbuf_unused=57352
Jan  4 20:25:15 homecomp pulseaudio[26848]: [alsa-sink-ca0106] alsa-sink.c: setting avail_min=7651
Jan  4 20:25:15 homecomp pulseaudio[26848]: [alsa-sink-ca0106] alsa-sink.c: Latency set to 21.33ms
Jan  4 20:25:15 homecomp pulseaudio[26848]: [alsa-sink-ca0106] alsa-sink.c: hwbuf_unused=57352
Jan  4 20:25:15 homecomp pulseaudio[26848]: [alsa-sink-ca0106] alsa-sink.c: setting avail_min=7651

With the preempt kernel this doesn't happen at all (I grepped the log) and sound is just as good as with pure ALSA.

However, arecord still drops overrun for CA0106. It doesn't do it for PCH (ALC889) though.
Comment 64 Raymond 2015-01-08 16:30:40 UTC
if you cannot find stereo 48000Hz wav file

aplay -D plughw:CARD=CA0106 -v --buffer-size=1024 any.wav

try to find minimum buffer size 1024,512, 256,128,64,... without underrun


1024 frames = 21.33 ms x 48000Hz
4096 = 85.33 ms x 48000Hz

if request tlength 85.33ms is buffer time and 21.33ms is period time

not sure why pulseaudio received latency is 26ms



alsa_output.pci-0000_06_00.0.analog-stereo with sample spec s16le 2ch 48000Hz and channel map front-left,front-right
Dec 25 19:29:42 homecomp pulseaudio[1911]:     media.name = "ALSA Playback"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.name = "ALSA plug-in [Transistor.bin.x86_64]"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     native-protocol.peer = "UNIX socket client"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     native-protocol.version = "26"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.id = "9536"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.user = "rkfg"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.host = "homecomp"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.binary = "Transistor.bin.x86_64"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.language = "en_GB.UTF-8"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     window.x11.display = ":0.0"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.machine_id = "3be8f38f291dd2003af500d051c0a849"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     application.process.session_id = "10"
Dec 25 19:29:42 homecomp pulseaudio[1911]:     module-stream-restore.id = "sink-input-by-application-name:ALSA plug-in [Transistor.bin.x86_64]"
Dec 25 19:29:42 homecomp pulseaudio[1911]: Requested tlength=85.33 ms, minreq=21.33 ms
Dec 25 19:29:42 homecomp pulseaudio[1911]: Early requests mode enabled, configuring sink latency to minreq.
Dec 25 19:29:42 homecomp pulseaudio[1911]: Requested latency=21.33 ms, Received latency=26.00 ms
Comment 65 rkfg 2015-01-09 14:09:33 UTC
# aplay -D plughw:CARD=CA0106 -v --buffer-size=128 /usr/share/sounds/alsa/Side_Left.wav
Playing WAVE '/usr/share/sounds/alsa/Side_Left.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Plug PCM: Route conversion PCM (sformat=S16_LE)
  Transformation table:
    0 <- 0
    1 <- 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 1
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 128
  period_size  : 32
  period_time  : 666
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 32
  period_event : 0
  start_threshold  : 128
  stop_threshold   : 128
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
Slave: Hardware PCM card 0 'CA0106' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 128
  period_size  : 32
  period_time  : 666
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 32
  period_event : 0
  start_threshold  : 128
  stop_threshold   : 128
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
  appl_ptr     : 0
  hw_ptr       : 0

128 seems to be fine. It's not consistent, sometimes 64 works ok, sometimes it overruns (says so in the console and hitches). 128 has never overrun, neither visually (saying it in the console), nor audible (clicks/pops).
Comment 66 rkfg 2015-01-09 14:13:38 UTC
Tried with a stereo 48k file (converted /usr/share/sounds/KDE-Im-Cant-Connect.ogg to wav, tested with ffprobe that it's truly 48k/2chan) and 64 bytes buffer size:
# aplay -D plughw:CARD=CA0106 -v --buffer-size=64 /tmp/kde.wav
Playing WAVE '/tmp/kde.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
Plug PCM: Hardware PCM card 0 'CA0106' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 64
  period_size  : 16
  period_time  : 333
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 16
  period_event : 0
  start_threshold  : 64
  stop_threshold   : 64
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
  appl_ptr     : 0
  hw_ptr       : 0
underrun!!! (at least 0.010 ms long)
Status:
  state       : XRUN
  trigger_time: 260136.459825170
  tstamp      : 260136.459834181
  delay       : 0
  avail       : 64
  avail_max   : 64
underrun!!! (at least 0.020 ms long)
Status:
  state       : XRUN
  trigger_time: 260136.460064991
  tstamp      : 260136.460084242
  delay       : 0
  avail       : 64
  avail_max   : 64

No underruns with 128b buffer.
Comment 67 Raymond 2015-01-10 01:14:09 UTC
how about CD audio (44100Hz stereo) using plughw?
Comment 68 rkfg 2015-01-10 02:02:43 UTC
Interesting. I've converted that file to 44100 Hz and now it reveals a strange behavior. When I play it with buffer size of 64 it sounds like the pitch is lower than it should be (even if it doesn't overrun though it does from time to time). When the size is 128 it sounds fine.

# aplay -D plughw:CARD=CA0106 -v --buffer-size=64 /tmp/kde44100.wav
Playing WAVE '/tmp/kde44100.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Plug PCM: Rate conversion PCM (48000, sformat=S16_LE)
Converter: libspeex (builtin)
Protocol version: 10002
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 58
  period_size  : 14
  period_time  : 333
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 14
  period_event : 0
  start_threshold  : 58
  stop_threshold   : 58
  silence_threshold: 0
  silence_size : 0
  boundary     : 4179340454199820288
Slave: Hardware PCM card 0 'CA0106' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 64
  period_size  : 16
  period_time  : 333
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 16
  period_event : 0
  start_threshold  : 64
  stop_threshold   : 64
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
  appl_ptr     : 0
  hw_ptr       : 0
underrun!!! (at least 0.116 ms long)
Status:
  state       : XRUN
  trigger_time: 301642.243139271
  tstamp      : 301642.243254519
  delay       : 2
  avail       : 56
  avail_max   : 56

# aplay -D plughw:CARD=CA0106 -v --buffer-size=128 /tmp/kde44100.wav             
Playing WAVE '/tmp/kde44100.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Plug PCM: Rate conversion PCM (48000, sformat=S16_LE)
Converter: libspeex (builtin)
Protocol version: 10002
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 117
  period_size  : 29
  period_time  : 666
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 29
  period_event : 0
  start_threshold  : 117
  stop_threshold   : 117
  silence_threshold: 0
  silence_size : 0
  boundary     : 4215369251218784256
Slave: Hardware PCM card 0 'CA0106' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 128
  period_size  : 32
  period_time  : 666
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 32
  period_event : 0
  start_threshold  : 128
  stop_threshold   : 128
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
  appl_ptr     : 0
  hw_ptr       : 0

This pitch (or maybe speed?) weirdness occurs only on playing stereo files with rate of 44100. I've tried playing music and it indeed sounds a bit transposed. Bufsize of 128 frames also seems to produce underruns after some time, my testing clip was too small to reveal it. So it required bufsize 512 to be played completely without underruns:

# aplay -D plughw:CARD=CA0106 -v --buffer-size=512 /tmp/ksp44100.wav
Playing WAVE '/tmp/ksp44100.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Plug PCM: Rate conversion PCM (48000, sformat=S16_LE)
Converter: libspeex (builtin)
Protocol version: 10002
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 529
  period_size  : 132
  period_time  : 3000
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 132
  period_event : 0
  start_threshold  : 529
  stop_threshold   : 529
  silence_threshold: 0
  silence_size : 0
  boundary     : 4764808405757984768
Slave: Hardware PCM card 0 'CA0106' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 576
  period_size  : 144
  period_time  : 3000
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 144
  period_event : 0
  start_threshold  : 576
  stop_threshold   : 576
  silence_threshold: 0
  silence_size : 0
  boundary     : 5188146770730811392
  appl_ptr     : 0
  hw_ptr       : 0

The same song converted to 48000 Hz plays without underruns with buffer size of 256 frames:

Playing WAVE '/tmp/ksp48000.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
Plug PCM: Hardware PCM card 0 'CA0106' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 256
  period_size  : 64
  period_time  : 1333
  tstamp_mode  : NONE
  period_step  : 1
  avail_min    : 64
  period_event : 0
  start_threshold  : 256
  stop_threshold   : 256
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
  appl_ptr     : 0
  hw_ptr       : 0
Comment 69 GitLab Migration User 2018-07-30 10:16:31 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/308.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.