Bug 84804 - Pulseaudio doesn't work on (pro audio- non interleaved access mode) soundcards with high channel counts
Summary: Pulseaudio doesn't work on (pro audio- non interleaved access mode) soundcard...
Status: RESOLVED MOVED
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: alsa (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-10-08 14:49 UTC by benjamin
Modified: 2018-07-30 10:29 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Pulseaudio verbose log (187.65 KB, text/plain)
2014-10-08 16:31 UTC, benjamin
Details
alsa-info.sh output (18.83 KB, text/plain)
2014-10-08 16:31 UTC, benjamin
Details
logging when only non-interleaved PCM available (2.54 KB, patch)
2014-11-15 12:41 UTC, Peter Meerwald
Details | Splinter Review
add SNDRV_PCM_INFO_BATCH when precise_ptr is not enabled (894 bytes, patch)
2015-02-17 13:06 UTC, Raymond
Details | Splinter Review
attachment-5407-0.html (2.17 KB, text/html)
2016-07-19 19:10 UTC, benjamin
Details

Description benjamin 2014-10-08 14:49:49 UTC
Pulseaudio doesn't know how to handle soundcards like the RME HDSP 9652 I use (26 channels, 24bit only). I tried to alter the default.pa file since there are some soundcard specific workarounds available* but I had no success. This is pretty frustrating because pulseaudio is the standard soundsystem of most distros nowadays and the only real workaround is to remove it and use plain alsa.

I use Debian testing (Jessie/Sid) with pulseaudio 5.0.

*
http://ccrma-mail.stanford.edu/pipermail/planetccrma/2011-April/017566.html
http://ubuntuforums.org/showthread.php?t=1871685

Thanks,
Benjamin
Comment 1 Raymond 2014-10-08 15:56:23 UTC
http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa/alsa-mixer.c?id=48edd0a00f455df075efcf1986103e5f507c816f

do you mean multichannel profile still not fix your problem?
Comment 2 Raymond 2014-10-08 15:58:52 UTC
you have to post pulseaudio verbose log,  output of alsa-info.sh if tje multichannel profile still not work
Comment 3 benjamin 2014-10-08 16:31:05 UTC
Created attachment 107567 [details]
Pulseaudio verbose log
Comment 4 benjamin 2014-10-08 16:31:34 UTC
Created attachment 107568 [details]
alsa-info.sh output
Comment 5 benjamin 2014-10-08 16:34:00 UTC
Hi,

I only use pulseaudio 5.0 from Debian testing. If the multichannel profile has been added to the 5.0 release then I have it, otherwise I need some help on how to use it. I've attached what you asked for.

I should probably add that pulseaudio itself runs fine, but doesn't give me any audio output at all, I've checked this via hdspmixer.
Comment 6 Raymond 2014-10-08 22:50:43 UTC
2014-08-23	alsa: Remove four channel input profile	

2014-08-01	alsa: Add a multichannel fallback mapping	
2014-08-01	alsa: Allow "fallback" configuration for mappings and profiles	
2014-08-01	alsa: Add "exact-channels" mapping configurability

those patches were supposed to support firewire audio which don't support mono, stereo surround40,..surround71 playback and mono,stereo4 ch capture
Comment 8 benjamin 2014-10-10 16:44:55 UTC
Hey Raymond,

again, is the multichannel profile included in pulseaduio 5.0? It seems to me that these commits are more recent, and I don't build pulseaudio from source.
Comment 9 Tanu Kaskinen 2014-10-10 19:38:13 UTC
Yes, the multichannel fix is newer than 5.0.

If you feel adventurous enough to install pulseaudio from source, here are steps for installing the current git version:

git clone git://anongit.freedesktop.org/pulseaudio/pulseaudio
cd pulseaudio
./bootstrap.sh
make
sudo make install
sudo ldconfig

The bootstrap.sh script will probably give you all kinds of errors, if you don't have the development tools and the headers of various dependecy libraries already installed. I think debian has some tool for installing the build dependencies, which should make it pretty painless to get everything installed, something like "apt-get build-dependencies pulseaudio". I don't know the exact command, google will help you.
Comment 10 Raymond 2014-10-11 03:03:54 UTC
your driver seem need to set autosync source


 1992.311070] snd_hdsp 0000:04:07.0: No AutoSync source for requested rate
[ 2007.259919] snd_hdsp 0000:04:07.0: No AutoSync source for requested rate
[ 2029.877275] snd_hdsp 0000:04:07.0: No AutoSync source for requested rate
[ 2050.904205] snd_hdsp 0000:04:07.0: No AutoSync source for requested rate
[ 2072.123263] snd_hdsp 0000:04:07.0: No AutoSync source for requested rate
Comment 11 benjamin 2014-10-13 12:31:51 UTC
That's true, I use an external autosync source with 44100hz, so that's the only possible rate. Alsa has no issues with this.
Comment 12 Raymond 2014-10-16 04:46:53 UTC
seem no active ports/ports 

https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/1381475/+attachment/4237185/+files/pulseverbose.log


Card #3
	Name: alsa_card.firewire-0x000aac0300592827
	Driver: module-alsa-card.c
	Owner Module: 8
	Properties:
		alsa.card = "0"
		alsa.card_name = "PHASE 88 Rack FW"
		alsa.long_card_name = "TerraTec Electronic Gmb PHASE 88 Rack FW (id:3, rev:1), GUID 000aac0300592827 a"
		alsa.driver_name = "snd_bebob"
		device.bus_path = "pci-0000:01:09.0"
		sysfs.path = "/devices/pci0000:00/0000:00:09.0/0000:01:09.0/fw2/fw2.0/sound/card0"
		udev.id = "firewire-0x000aac0300592827"
		device.bus = "firewire"
		device.vendor.name = "Texas Instruments"
		device.product.name = "TSB43AB22A IEEE-1394a-2000 Controller (PHY/Link) [iOHCI-Lynx]"
		device.string = "0"
		device.description = "TSB43AB22A IEEE-1394a-2000 Controller (PHY/Link) [iOHCI-Lynx]"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-firewire"
	Profiles:
		input:10-channels: 10 Channels Input (sinks: 0, sources: 1, priority. 10)
		output:10-channels: 10 Channels Output (sinks: 1, sources: 0, priority. 1000)
		output:10-channels+input:10-channels: 10 Channels Output + 10 Channels Input (sinks: 1, sources: 1, priority. 1010)
		off: Off (sinks: 0, sources: 0, priority. 0)
	Active Profile: output:10-channels+input:10-channels
Comment 13 Raymond 2014-10-16 04:56:07 UTC
why did pulseaidio still probe channels higher than channels_max ?



(   2.896|   0.000) I: [pulseaudio] alsa-util.c: Device hw:0 doesn't support sample format s16le, changed to s32le.
(   2.909|   0.012) D: [pulseaudio] alsa-mixer.c: Profile output:10-channels+input:10-channels supported.
(   2.909|   0.000) D: [pulseaudio] alsa-mixer.c: Skipping profile output:10-channels+input:12-channels - will not be able to open input:12-channels
(   2.910|   0.000) D: [pulseaudio] alsa-mixer.c: Skipping profile output:10-channels+input:14-channels - will not be able to open input:14-channels
(   2.910|   0.000) D: [pulseaudio] alsa-mixer.c: Skipping profile output:10-channels+input:16-channels - will not be able to open input:16-channels
(   2.910|   0.000) D: [pulseaudio] alsa-mixer.c: Skipping profile output:10-channels+input:18-channels - will not be able to open input:18-channels
(   2.911|   0.000) D: [pulseaudio] alsa-mixer.c: Looking at profile output:12-channels
(   2.911|   0.000) D: [pulseaudio] alsa-mixer.c: Checking for playback on 12 Channels (12-channels)
(   2.911|   0.000) D: [pulseaudio] alsa-util.c: Trying hw:0 with SND_PCM_NO_AUTO_FORMAT ...
Comment 14 benjamin 2014-10-27 11:01:54 UTC
I finally tried out the multichannel fallback patch (with the help of the Debian pulseaudio maintenance team) but it doesn't solve my problem.

I have no clue why there are no active ports or why pa probes higher channels.
Comment 15 Raymond 2014-10-27 11:34:22 UTC
http://colin.guthr.ie/2010/09/compiling-and-running-pulseaudio-from-git/

you can try build and run pulseaudio from git without install 

and post the verbose log if it still not work
Comment 16 Raymond 2014-10-27 12:01:50 UTC
post the output of

aplay -v --dump-hw-params -Dhw:0,0  test.wav

arecord -v --dump-hw-params -Dhw:0,0  test.wav
Comment 17 benjamin 2014-10-27 14:49:15 UTC
---
$ arecord -v --dump-hw-params -Dhw:0,0  test.wav
Aufnahme: WAVE 'test.wav' : Unsigned 8 bit, Rate: 8000 Hz, mono
HW Params of device "hw:0,0":
--------------------
ACCESS:  MMAP_NONINTERLEAVED RW_NONINTERLEAVED
FORMAT:  S32_LE
SUBFORMAT:  STD
SAMPLE_BITS: 32
FRAME_BITS: [448 832]
CHANNELS: [14 26]
RATE: [32000 96000]
PERIOD_TIME: (666 256000]
PERIOD_SIZE: [64 8192]
PERIOD_BYTES: [3584 851968]
PERIODS: 2
BUFFER_TIME: (1333 512000]
BUFFER_SIZE: [128 16384]
BUFFER_BYTES: [7168 1703936]
TICK_TIME: ALL
--------------------
arecord: set_params:1228: Zugriffs-Modus nicht unterstützt
--

The last message means "Access-mode not supported"

---

aplay -v --dump-hw-params -Dhw:0,0 music.wav
Wiedergabe: WAVE 'music.wav' : Signed 16 bit Little Endian, Rate: 44100 Hz, stereo
HW Params of device "hw:0,0":
--------------------
ACCESS:  MMAP_NONINTERLEAVED RW_NONINTERLEAVED
FORMAT:  S32_LE
SUBFORMAT:  STD
SAMPLE_BITS: 32
FRAME_BITS: [448 832]
CHANNELS: [14 26]
RATE: [32000 96000]
PERIOD_TIME: (666 256000]
PERIOD_SIZE: [64 8192]
PERIOD_BYTES: [3584 851968]
PERIODS: 2
BUFFER_TIME: (1333 512000]
BUFFER_SIZE: [128 16384]
BUFFER_BYTES: [7168 1703936]
TICK_TIME: ALL
--------------------
aplay: set_params:1228: Zugriffs-Modus nicht unterstützt
Comment 18 Raymond 2014-10-27 16:14:05 UTC
 those pa_log_debug() should be pa_log_error() to indicate both MMAP_NONINTERLEAVED RW_NONINTERLEAVED are not supported





if (_use_mmap) {

        if (snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_MMAP_INTERLEAVED) < 0) {

            /* mmap() didn't work, fall back to interleaved */

            if ((ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
                pa_log_debug("snd_pcm_hw_params_set_access() failed: %s", pa_alsa_strerror(ret));
                goto finish;
            }

            _use_mmap = false;
        }

    } else if ((ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
        pa_log_debug("snd_pcm_hw_params_set_access() failed: %s", pa_alsa_strerror(ret));
        goto finish;
    }
Comment 19 Raymond 2014-10-27 23:18:50 UTC
need to test whether sound card only support non interleaved mode  by using snd_pcm_hw_params_test_access instead of snd_pcm_hw_params_set_access
Comment 20 Raymond 2014-10-29 23:37:51 UTC
http://git.alsa-project.org/?p=alsa-lib.git;a=blob;f=include/pcm.h;hb=HEAD

/** PCM access type */
typedef enum _snd_pcm_access {
	/** mmap access with simple interleaved channels */
	SND_PCM_ACCESS_MMAP_INTERLEAVED = 0,
	/** mmap access with simple non interleaved channels */
	SND_PCM_ACCESS_MMAP_NONINTERLEAVED,
	/** mmap access with complex placement */
	SND_PCM_ACCESS_MMAP_COMPLEX,
	/** snd_pcm_readi/snd_pcm_writei access */
	SND_PCM_ACCESS_RW_INTERLEAVED,
	/** snd_pcm_readn/snd_pcm_writen access */
	SND_PCM_ACCESS_RW_NONINTERLEAVED,
	SND_PCM_ACCESS_LAST = SND_PCM_ACCESS_RW_NONINTERLEAVED
} snd_pcm_access_t;


there are five pcm access type but pulseaudio only support two and does not report any error when the sound card does not support interleaved modes
Comment 21 Peter Meerwald 2014-11-15 12:41:38 UTC
Created attachment 109516 [details] [review]
logging when only non-interleaved PCM available

patch which adds logging if no suitable access format found; non-interleaved PCM is still unsupported
Comment 22 Raymond 2014-11-15 14:25:57 UTC
(In reply to Peter Meerwald from comment #21)
> Created attachment 109516 [details] [review] [review]
> logging when only non-interleaved PCM available
> 
> patch which adds logging if no suitable access format found; non-interleaved
> PCM is still unsupported

did your patch really works ?

if you want to test different accesses, you need to use  test_access to find out whether the access is support before you use set_access which is destructive when error ocurrs
Comment 24 Raymond 2014-11-15 14:54:39 UTC
(In reply to Peter Meerwald from comment #21)
> Created attachment 109516 [details] [review] [review]
> logging when only non-interleaved PCM available
> 
> patch which adds logging if no suitable access format found; non-interleaved
> PCM is still unsupported

this is a fatal error when the interleaced access is not supported by the alsa driver  the card is unusable by pulseaudio
Comment 25 Raymond 2014-11-16 15:05:49 UTC
Read / Write transfer

There are two versions of read / write routines. The first expects the interleaved samples at input (SND_PCM_ACCESS_RW_INTERLEAVED access method), and the second one expects non-interleaved (samples in separated buffers - SND_PCM_ACCESS_RW_NONINTERLEAVED access method) at input. There are these functions for interleaved transfers: snd_pcm_writei() snd_pcm_readi(). For non-interleaved transfers, there are these functions: snd_pcm_writen() and snd_pcm_readn().


this mean pulseaudio still need snd_pcm_writen() and snd_pcm_readn() to support SND_PCM_ACCESS_RW_NONINTERLEAVED access method
Comment 26 David Henningsson 2015-02-16 09:16:45 UTC
Hi benjamin,

PulseAudio 6.0 has now been released and it includes the multichannel fallback, which should have solved your issue, but apparently it has not.

Could you submit a new PulseAudio verbose log with PA 6.0? Thanks.
Comment 27 David Henningsson 2015-02-16 09:17:56 UTC
Comment on attachment 109516 [details] [review]
logging when only non-interleaved PCM available

Review of attachment 109516 [details] [review]:
-----------------------------------------------------------------

Well, that is a truth with modification, I believe - PulseAudio as a last resort tries to open plug:hw:* and that should auto-convert from noninterleaved to interleaved. So this should not be an issue.
Comment 28 David Henningsson 2015-02-16 09:39:40 UTC
Peter, forget the last comment. I read your patch again and it looks good, so I've pushed it now.

(This does not change the fact that we still need a new verbose log from Benjamin with PA 6.0.)
Comment 29 benjamin 2015-02-16 12:32:38 UTC
Hi,

I built PA 6 from git and got the exact same verbose output of aplay and arecord than I posted on 2014-10-27.

The apps are working though - partly. Browsers and music apps like aqualung play sounds now, but there are a lot of dropouts in the sound. Sometimes, it even plays back at the wrong speed.

I started PA, fired up a browser, played back the beginning of a youtube video and closed everything again:
http://pastebin.com/HbRc2yQF
Comment 30 David Henningsson 2015-02-17 07:50:07 UTC
Thanks, so in fact the card is detected now. 

The crackling looks like a driver problem but I'm not sure. You could try to change this line in default.pa:

load-module module-udev-detect

to this:

load-module module-udev-detect tsched=0

...and try again.
Comment 31 benjamin 2015-02-17 11:54:42 UTC
tsched=0 !!!
That seems to do the trick! Pulseaudio 6.0 is running with every app simultaneously without a glitch! I will do more testing, but it looks perfect right now!

Thank you all!
Comment 32 Raymond 2015-02-17 12:37:18 UTC
refer rme9652_hw_pointer() to rme9652.c

if (!rme9652->precise_ptr)
		return (status & RME9652_buffer_id) ? period_size : 0;

if precise_ptr is not enabled by module parameter, it just return pointer value as period_size or zero, this mean time scheduling should be disabled since driver can only use two periods (impossible to rewind)
Comment 33 Raymond 2015-02-17 13:06:17 UTC
Created attachment 113564 [details] [review]
add SNDRV_PCM_INFO_BATCH when precise_ptr is not enabled

rme9652 driver need to specify SNDRV_PCM_INFO_BATCH when precise_ptr is not enabled
Comment 34 David Henningsson 2015-02-23 07:53:24 UTC
Ok. So the "high channel count" part is fixed with 6.0.

The "non interleaved access" was never a problem (emulated by alsa plug layer).

Tsched=0 workarounds...should in general be fixed in ALSA rather than PulseAudio. Raymond's patch is probably correct but I'm not qualified to review it. Raymond, could you turn the patch into a proper commit (git commit -s ) and then send it upstream on the alsa-devel mailinglist (using git send-email or git format-patch)? Thanks.
Comment 35 benjamin 2016-07-19 08:59:06 UTC
Hi,

I'm not sure if this is 100% the same issue, but my problems started again when Debian upgraded from pulseaudio 8 to 9 recently.

Even though I still use tsched=0, I hear huge amounts of clicks and pops while playing back (everything sounds like a very old vinyl recording now...). Enabling tsched makes no difference, in fact I think that it is still of even though I tried tsched=1.

I'll attach the verbose log.
Comment 36 benjamin 2016-07-19 08:59:54 UTC
http://pastebin.com/CzQQhvET
Comment 37 Raymond 2016-07-19 14:09:10 UTC
https://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/?id=55a25246ee80aa950bf27f811c0cc176d0821a4e


pulseaudio does not support non-interlaved mode


static void check_access(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, bool use_mmap) {
    if ((use_mmap && !snd_pcm_hw_params_test_access(pcm_handle, hwparams, SND_PCM_ACCESS_MMAP_INTERLEAVED)) ||
        !snd_pcm_hw_params_test_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED))
        pa_log_error("Weird, PCM claims to support interleaved access, but snd_pcm_hw_params_set_access() failed.");
+
Comment 38 benjamin 2016-07-19 19:10:22 UTC
Created attachment 125150 [details]
attachment-5407-0.html

Meaning what exactly?

It worked with previous versions. And even if it doesn't work - what is the recommended step here? Remove pulseaudio?

Thanks & best regards
Benjamin

Am 19. Juli 2016 16:09:10 MESZ, schrieb bugzilla-daemon@freedesktop.org:
>https://bugs.freedesktop.org/show_bug.cgi?id=84804
>
>--- Comment #37 from Raymond <superquad.vortex2@gmail.com> ---
>https://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/?id=55a25246ee80aa950bf27f811c0cc176d0821a4e
>
>
>pulseaudio does not support non-interlaved mode
>
>
>static void check_access(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t
>*hwparams,
>bool use_mmap) {
>  if ((use_mmap && !snd_pcm_hw_params_test_access(pcm_handle, hwparams,
>SND_PCM_ACCESS_MMAP_INTERLEAVED)) ||
>        !snd_pcm_hw_params_test_access(pcm_handle, hwparams,
>SND_PCM_ACCESS_RW_INTERLEAVED))
>     pa_log_error("Weird, PCM claims to support interleaved access, but
>snd_pcm_hw_params_set_access() failed.");
>+
>
>-- 
>You are receiving this mail because:
>You reported the bug.
Comment 39 Tanu Kaskinen 2016-07-20 00:06:56 UTC
The log shows that you're not using module-udev-detect. I don't know if that's why things stopped working, but that would anyway be the first thing to fix. Debian changed the packaging so that "pulseaudio-module-udev" is now a separate package. You have probably disabled automatic installation of recommended packages, because by default that package should get installed automatically.
Comment 40 Raymond 2016-07-20 09:24:38 UTC
https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/tree/sound/pci/rme9652/hdsp.c

static struct snd_pcm_hardware snd_hdsp_capture_subinfo =
{
	.info =			(SNDRV_PCM_INFO_MMAP |
				 SNDRV_PCM_INFO_MMAP_VALID |
				 SNDRV_PCM_INFO_NONINTERLEAVED |
				 SNDRV_PCM_INFO_SYNC_START),
#ifdef SNDRV_BIG_ENDIAN
	.formats =		SNDRV_PCM_FMTBIT_S32_BE,
#else
	.formats =		SNDRV_PCM_FMTBIT_S32_LE,
#endif
	.rates =		(SNDRV_PCM_RATE_32000 |
				 SNDRV_PCM_RATE_44100 |
				 SNDRV_PCM_RATE_48000 |
				 SNDRV_PCM_RATE_64000 |
				 SNDRV_PCM_RATE_88200 |
				 SNDRV_PCM_RATE_96000),
	.rate_min =		32000,
	.rate_max =		96000,
	.channels_min =		5,
	.channels_max =		HDSP_MAX_CHANNELS,
	.buffer_bytes_max =	HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
	.period_bytes_min =	(64 * 4) * 10,
	.period_bytes_max =	(8192 * 4) * HDSP_MAX_CHANNELS,
	.periods_min =		2,
	.periods_max =		2,
	.fifo_size =		0
};


only support 2 periods and non-interleaved access mode

pulseaudio cannot use 4 fragments

this mean one period of channel 1 , follow by one period of channel 2 ,..., one period of channel n

seem has flag to control the precision of hw pointer


static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
{
	int position;

	position = hdsp_read(hdsp, HDSP_statusRegister);

	if (!hdsp->precise_ptr)
		return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;

	position &= HDSP_BufferPositionMask;
	position /= 4;
	position &= (hdsp->period_bytes/2) - 1;
	return position;
}
Comment 41 benjamin 2016-07-22 08:08:28 UTC
(In reply to Tanu Kaskinen from comment #39)
> The log shows that you're not using module-udev-detect. I don't know if
> that's why things stopped working, but that would anyway be the first thing
> to fix. Debian changed the packaging so that "pulseaudio-module-udev" is now
> a separate package. You have probably disabled automatic installation of
> recommended packages, because by default that package should get installed
> automatically.

Thanks a lot! My system really didn't install module-udev-detect (package pulseaudio-module-udev in debian stretch/testing). Now it works again!
Comment 42 GitLab Migration User 2018-07-30 10:29:16 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/457.


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.