From 9c1439a76cea33d2cec65a42d499230d2f9a5205 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 9 Jan 2019 12:02:56 +0100 Subject: [PATCH 1/7] pcm: Preserve period_event in snd_pcm_hw_sw_params() call snd_pcm_hw_sw_params() in pcm_hw.c tries to abuse the reserved bits for passing period_Event flag. In this hackish way, we clear the reserved bits at beginning, and restore before returning. However, the code paths that return earlier don't restore the value, hence when user calls this function twice, it may pass an unexpected value. This patch fixes the failure, restoring the value always before returning from the function. Reported-by: Jamey Sharp Signed-off-by: Takashi Iwai --- src/pcm/pcm_hw.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 59a24200..91370a88 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -496,7 +496,7 @@ static int snd_pcm_hw_hw_free(snd_pcm_t *pcm) static int snd_pcm_hw_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params) { snd_pcm_hw_t *hw = pcm->private_data; - int fd = hw->fd, err; + int fd = hw->fd, err = 0; int old_period_event = sw_get_period_event(params); sw_set_period_event(params, 0); if ((snd_pcm_tstamp_t) params->tstamp_mode == pcm->tstamp_mode && @@ -508,22 +508,25 @@ static int snd_pcm_hw_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params) params->silence_size == pcm->silence_size && old_period_event == hw->period_event) { hw->mmap_control->avail_min = params->avail_min; - return issue_avail_min(hw); + err = issue_avail_min(hw); + goto out; } if (params->tstamp_type == SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW && hw->version < SNDRV_PROTOCOL_VERSION(2, 0, 12)) { SYSMSG("Kernel doesn't support SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW"); - return -EINVAL; + err = -EINVAL; + goto out; } if (params->tstamp_type == SND_PCM_TSTAMP_TYPE_MONOTONIC && hw->version < SNDRV_PROTOCOL_VERSION(2, 0, 5)) { SYSMSG("Kernel doesn't support SND_PCM_TSTAMP_TYPE_MONOTONIC"); - return -EINVAL; + err = -EINVAL; + goto out; } if (ioctl(fd, SNDRV_PCM_IOCTL_SW_PARAMS, params) < 0) { err = -errno; SYSMSG("SNDRV_PCM_IOCTL_SW_PARAMS failed (%i)", err); - return err; + goto out; } if ((snd_pcm_tstamp_type_t) params->tstamp_type != pcm->tstamp_type) { if (hw->version < SNDRV_PROTOCOL_VERSION(2, 0, 12)) { @@ -532,20 +535,21 @@ static int snd_pcm_hw_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params) if (ioctl(fd, SNDRV_PCM_IOCTL_TSTAMP, &on) < 0) { err = -errno; SNDMSG("TSTAMP failed\n"); - return err; + goto out; } } pcm->tstamp_type = params->tstamp_type; } - sw_set_period_event(params, old_period_event); hw->mmap_control->avail_min = params->avail_min; if (hw->period_event != old_period_event) { err = snd_pcm_hw_change_timer(pcm, old_period_event); if (err < 0) - return err; + goto out; hw->period_event = old_period_event; } - return 0; + out: + sw_set_period_event(params, old_period_event); + return err; } static int snd_pcm_hw_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t * info) -- 2.20.1 From d8013619c942dd996c32337a9ade429bfaf455ee Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Tue, 27 Nov 2018 09:36:28 +0800 Subject: [PATCH 2/7] conf/ucm: Add a UCM profile for Dell WD19 Dock USB-audio USB-audio device on Dell WD19 docking station provides two individual output PCM streams, one for headphone Jack and another for speaker out Jack. A UCM profile gives the proper roles for these. Signed-off-by: Hui Wang Signed-off-by: Jaroslav Kysela --- .../ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf | 5 ++++ src/conf/ucm/Dell-WD19-Dock/HiFi.conf | 26 +++++++++++++++++++ src/conf/ucm/Dell-WD19-Dock/Makefile.am | 4 +++ 3 files changed, 35 insertions(+) create mode 100644 src/conf/ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf create mode 100644 src/conf/ucm/Dell-WD19-Dock/HiFi.conf create mode 100644 src/conf/ucm/Dell-WD19-Dock/Makefile.am diff --git a/src/conf/ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf b/src/conf/ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf new file mode 100644 index 00000000..465ff550 --- /dev/null +++ b/src/conf/ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf @@ -0,0 +1,5 @@ +Comment "USB-audio on Dell WD19 docking station" +SectionUseCase."HiFi" { + File "HiFi.conf" + Comment "Default" +} diff --git a/src/conf/ucm/Dell-WD19-Dock/HiFi.conf b/src/conf/ucm/Dell-WD19-Dock/HiFi.conf new file mode 100644 index 00000000..e1427a79 --- /dev/null +++ b/src/conf/ucm/Dell-WD19-Dock/HiFi.conf @@ -0,0 +1,26 @@ +SectionDevice."Headphone" { + Comment "Headphone" + + Value { + PlaybackChannels "2" + PlaybackPCM "hw:Dock,0" + } +} + +SectionDevice."Speaker" { + Comment "Speaker" + + Value { + PlaybackChannels "2" + PlaybackPCM "hw:Dock,1" + } +} + +SectionDevice."Mic" { + Comment "Microphone" + + Value { + CaptureChannels "2" + CapturePCM "hw:Dock,0" + } +} diff --git a/src/conf/ucm/Dell-WD19-Dock/Makefile.am b/src/conf/ucm/Dell-WD19-Dock/Makefile.am new file mode 100644 index 00000000..6549ae1b --- /dev/null +++ b/src/conf/ucm/Dell-WD19-Dock/Makefile.am @@ -0,0 +1,4 @@ +alsaconfigdir = @ALSA_CONFIG_DIR@ +ucmdir = $(alsaconfigdir)/ucm/Dell-WD19-Dock +ucm_DATA = Dell-WD19-Dock.conf HiFi.conf +EXTRA_DIST = $(ucm_DATA) -- 2.20.1 From 0862458c1339eec025330b39d5199481c335673c Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 25 Jan 2019 12:09:31 +0100 Subject: [PATCH 3/7] Revert "conf/ucm: Add a UCM profile for Dell WD19 Dock USB-audio" This reverts commit d8013619c942dd996c32337a9ade429bfaf455ee. The USB driver defines identical profile as for WD15. Signed-off-by: Jaroslav Kysela --- .../ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf | 5 ---- src/conf/ucm/Dell-WD19-Dock/HiFi.conf | 26 ------------------- src/conf/ucm/Dell-WD19-Dock/Makefile.am | 4 --- 3 files changed, 35 deletions(-) delete mode 100644 src/conf/ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf delete mode 100644 src/conf/ucm/Dell-WD19-Dock/HiFi.conf delete mode 100644 src/conf/ucm/Dell-WD19-Dock/Makefile.am diff --git a/src/conf/ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf b/src/conf/ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf deleted file mode 100644 index 465ff550..00000000 --- a/src/conf/ucm/Dell-WD19-Dock/Dell-WD19-Dock.conf +++ /dev/null @@ -1,5 +0,0 @@ -Comment "USB-audio on Dell WD19 docking station" -SectionUseCase."HiFi" { - File "HiFi.conf" - Comment "Default" -} diff --git a/src/conf/ucm/Dell-WD19-Dock/HiFi.conf b/src/conf/ucm/Dell-WD19-Dock/HiFi.conf deleted file mode 100644 index e1427a79..00000000 --- a/src/conf/ucm/Dell-WD19-Dock/HiFi.conf +++ /dev/null @@ -1,26 +0,0 @@ -SectionDevice."Headphone" { - Comment "Headphone" - - Value { - PlaybackChannels "2" - PlaybackPCM "hw:Dock,0" - } -} - -SectionDevice."Speaker" { - Comment "Speaker" - - Value { - PlaybackChannels "2" - PlaybackPCM "hw:Dock,1" - } -} - -SectionDevice."Mic" { - Comment "Microphone" - - Value { - CaptureChannels "2" - CapturePCM "hw:Dock,0" - } -} diff --git a/src/conf/ucm/Dell-WD19-Dock/Makefile.am b/src/conf/ucm/Dell-WD19-Dock/Makefile.am deleted file mode 100644 index 6549ae1b..00000000 --- a/src/conf/ucm/Dell-WD19-Dock/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -alsaconfigdir = @ALSA_CONFIG_DIR@ -ucmdir = $(alsaconfigdir)/ucm/Dell-WD19-Dock -ucm_DATA = Dell-WD19-Dock.conf HiFi.conf -EXTRA_DIST = $(ucm_DATA) -- 2.20.1 From 7442c8b9be91ef576871eed5efce9499fcdeab4a Mon Sep 17 00:00:00 2001 From: Srinivas Kandagatla Date: Tue, 29 Jan 2019 10:48:28 +0000 Subject: [PATCH 4/7] ucm: Add ucm files for DB820c board DB820c board is based of MSM8996 Qualcomm SoC, which has support for both Digital and Analog audio. Digital audio is over HDMI and analog is over WCD9335 codec via SLIMbus. Board itself has HDMI port, a 3.5mm audio Jack and an Audio expansion connector. This patch adds support for HDMI port and 3.5mm jack. Signed-off-by: Srinivas Kandagatla Signed-off-by: Takashi Iwai --- configure.ac | 1 + src/conf/ucm/DB820c/DB820c.conf | 9 +++ src/conf/ucm/DB820c/HDMI | 37 +++++++++++ src/conf/ucm/DB820c/HiFi | 110 ++++++++++++++++++++++++++++++++ src/conf/ucm/DB820c/Makefile.am | 4 ++ src/conf/ucm/Makefile.am | 1 + 6 files changed, 162 insertions(+) create mode 100644 src/conf/ucm/DB820c/DB820c.conf create mode 100644 src/conf/ucm/DB820c/HDMI create mode 100644 src/conf/ucm/DB820c/HiFi create mode 100644 src/conf/ucm/DB820c/Makefile.am diff --git a/configure.ac b/configure.ac index a0c346ef..e9e1a369 100644 --- a/configure.ac +++ b/configure.ac @@ -747,6 +747,7 @@ AC_OUTPUT(Makefile doc/Makefile doc/pictures/Makefile doc/doxygen.cfg \ src/conf/ucm/cube-i1_TF-Defaultstring-CherryTrailCR/Makefile \ src/conf/ucm/DAISY-I2S/Makefile \ src/conf/ucm/DB410c/Makefile \ + src/conf/ucm/DB820c/Makefile \ src/conf/ucm/Dell-WD15-Dock/Makefile \ src/conf/ucm/GoogleNyan/Makefile \ src/conf/ucm/gpd-win-pocket-rt5645/Makefile \ diff --git a/src/conf/ucm/DB820c/DB820c.conf b/src/conf/ucm/DB820c/DB820c.conf new file mode 100644 index 00000000..58b7ff4e --- /dev/null +++ b/src/conf/ucm/DB820c/DB820c.conf @@ -0,0 +1,9 @@ +SectionUseCase."HiFi" { + File "HiFi" + Comment "HiFi quality Music." +} + +SectionUseCase."HDMI" { + File "HDMI" + Comment "HDMI output." +} diff --git a/src/conf/ucm/DB820c/HDMI b/src/conf/ucm/DB820c/HDMI new file mode 100644 index 00000000..39b28692 --- /dev/null +++ b/src/conf/ucm/DB820c/HDMI @@ -0,0 +1,37 @@ +# Use case configuration for DB820c board. +# Author: Srinivas Kandagatla + +SectionVerb { + EnableSequence [ + cdev "hw:0" + cset "name='HDMI Mixer MultiMedia1' 1" + ] + + DisableSequence [ + cdev "hw:0" + cset "name='HDMI Mixer MultiMedia1' 0" + ] + Value { + TQ "HiFi" + PlaybackPCM "plughw:0,0" + } +} + +SectionDevice."HDMI-stereo" { + #Name "HDMI-stereo" + Comment "HDMI Digital Stereo Output" + + EnableSequence [ + cdev "hw:0" + cset "name='HDMI Mixer MultiMedia1' 1" + ] + + DisableSequence [ + cdev "hw:0" + cset "name='HDMI Mixer MultiMedia1' 0" + ] + + Value { + PlaybackChannels "2" + } +} diff --git a/src/conf/ucm/DB820c/HiFi b/src/conf/ucm/DB820c/HiFi new file mode 100644 index 00000000..4457329f --- /dev/null +++ b/src/conf/ucm/DB820c/HiFi @@ -0,0 +1,110 @@ +# Use case configuration for DB820c board. +# Author: Srinivas Kandagatla + +SectionVerb { + + EnableSequence [ + cdev "hw:0" + cset "name='SLIM RX0 MUX' ZERO" + cset "name='SLIM RX1 MUX' ZERO" + cset "name='SLIM RX2 MUX' ZERO" + cset "name='SLIM RX3 MUX' ZERO" + cset "name='SLIM RX4 MUX' ZERO" + cset "name='SLIM RX5 MUX' AIF4_PB" + cset "name='SLIM RX6 MUX' AIF4_PB" + cset "name='SLIM RX7 MUX' ZERO" + cset "name='RX INT1_2 MUX' RX5" + cset "name='RX INT2_2 MUX' RX6" + ## gain to 0dB + cset "name='RX5 Digital Volume' 68" + ## gain to 0dB + cset "name='RX6 Digital Volume' 68" + cset "name='SLIMBUS_6_RX Audio Mixer MultiMedia2' 1" + cset "name='MultiMedia3 Mixer SLIMBUS_0_TX' 1" + cset "name='RX INT1 DEM MUX' CLSH_DSM_OUT" + cset "name='RX INT2 DEM MUX' CLSH_DSM_OUT" + cset "name='AIF1_CAP Mixer SLIM TX0' 1" + cset "name='SLIM TX0 MUX' DEC0" + cset "name='ADC2 Volume' 12" + cset "name='ADC MUX0' AMIC" + cset "name='AMIC MUX0' ADC2" + ] + + DisableSequence [ + cdev "hw:0" + cset "name='SLIMBUS_6_RX Audio Mixer MultiMedia2' 0" + cset "name='MultiMedia3 Mixer SLIMBUS_0_TX' 0" + ] + + # ALSA PCM + Value { + # ALSA PCM device for HiFi + PlaybackPCM "plughw:0,1" + CapturePCM "plughw:0,2" + } +} + +SectionDevice."Headphones" { + Comment "Headphones playback" + + EnableSequence [ + cdev "hw:0" + cset "name='SLIM RX0 MUX' ZERO" + cset "name='SLIM RX1 MUX' ZERO" + cset "name='SLIM RX2 MUX' ZERO" + cset "name='SLIM RX3 MUX' ZERO" + cset "name='SLIM RX4 MUX' ZERO" + cset "name='SLIM RX5 MUX' AIF4_PB" + cset "name='SLIM RX6 MUX' AIF4_PB" + cset "name='SLIM RX7 MUX' ZERO" + cset "name='RX INT1_2 MUX' RX5" + cset "name='RX INT2_2 MUX' RX6" + ## gain to 0dB + cset "name='RX5 Digital Volume' 68" + ## gain to 0dB + cset "name='RX6 Digital Volume' 68" + cset "name='SLIMBUS_6_RX Audio Mixer MultiMedia2' 1" + cset "name='RX INT1 DEM MUX' CLSH_DSM_OUT" + cset "name='RX INT2 DEM MUX' CLSH_DSM_OUT" + ] + + DisableSequence [ + cdev "hw:0" + cset "name='RX5 Digital Volume' 0" + cset "name='RX6 Digital Volume' 0" + cset "name='SLIM RX5 MUX' ZERO" + cset "name='SLIM RX6 MUX' ZERO" + cset "name='SLIMBUS_6_RX Audio Mixer MultiMedia2' 0" + ] + + Value { + PlaybackChannels "2" + } +} + +SectionDevice."Handset" { + Comment "Headset Microphone" + + EnableSequence [ + cdev "hw:0" + cset "name='MultiMedia3 Mixer SLIMBUS_0_TX' 1" + cset "name='AIF1_CAP Mixer SLIM TX0' 1" + cset "name='SLIM TX0 MUX' DEC0" + cset "name='ADC2 Volume' 12" + cset "name='ADC MUX0' AMIC" + cset "name='AMIC MUX0' ADC2" + ] + + DisableSequence [ + cdev "hw:0" + cset "name='MultiMedia3 Mixer SLIMBUS_0_TX' 0" + cset "name='AIF1_CAP Mixer SLIM TX0' 0" + cset "name='AMIC MUX0' ZERO" + cset "name='SLIM TX0 MUX' ZERO" + cset "name='ADC2 Volume' 0" + ] + + Value { + CaptureChannels "1" + } +} diff --git a/src/conf/ucm/DB820c/Makefile.am b/src/conf/ucm/DB820c/Makefile.am new file mode 100644 index 00000000..16e985e5 --- /dev/null +++ b/src/conf/ucm/DB820c/Makefile.am @@ -0,0 +1,4 @@ +alsaconfigdir = @ALSA_CONFIG_DIR@ +ucmdir = $(alsaconfigdir)/ucm/DB820c +ucm_DATA = DB820c.conf HDMI HiFi +EXTRA_DIST = $(ucm_DATA) diff --git a/src/conf/ucm/Makefile.am b/src/conf/ucm/Makefile.am index ee850ee6..e9f88ed6 100644 --- a/src/conf/ucm/Makefile.am +++ b/src/conf/ucm/Makefile.am @@ -31,6 +31,7 @@ chtrt5650 \ cube-i1_TF-Defaultstring-CherryTrailCR \ DAISY-I2S \ DB410c \ +DB820c \ Dell-WD15-Dock \ GoogleNyan \ gpd-win-pocket-rt5645 \ -- 2.20.1 From 4d9374e61d23a5fc219ec172fe9613017f9ae79c Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sun, 3 Feb 2019 12:37:41 +0100 Subject: [PATCH 5/7] ucm: bytcr/PlatformEnableSeq.conf update some comments Commit f91cc3c7d6b7 ("Update chtrt5645 ucm variants to use bytcr/PlatformEnableSeq.conf component") updated the following 2 comments: # codec0_out settings (used if SSP2 is connected to aif1) # modem_out settings (used if SSP0 is connected to aif2) Specifically it added the " to aif1" resp. " to aif2" part of the comments. This is not correct, AIF1 / AIF2 are something which is present on Realtek codecs only, and either one can be used indepedent of SSP0 or SSP2 being used (the comments in the chtrt5645 UCM profile before this change were wrong / outdated). Besides there not being any relationship between SSP0 or SSP2 being used, bytcr/PlatformEnableSeq.conf is also used with other codecs, e.g. the ESS8316 codec where this is not applicable at all. Therefor this commit removes the " to aif?" part of the comments again to avoid confusing people reading this in the future. Cc: Russell Parker Signed-off-by: Hans de Goede Signed-off-by: Takashi Iwai --- src/conf/ucm/platforms/bytcr/PlatformEnableSeq.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conf/ucm/platforms/bytcr/PlatformEnableSeq.conf b/src/conf/ucm/platforms/bytcr/PlatformEnableSeq.conf index 6f5e899c..b5ee2b41 100644 --- a/src/conf/ucm/platforms/bytcr/PlatformEnableSeq.conf +++ b/src/conf/ucm/platforms/bytcr/PlatformEnableSeq.conf @@ -29,7 +29,7 @@ cset "name='pcm0_in Gain 0 Volume' 0" cset "name='pcm1_in Gain 0 Switch' off" cset "name='pcm1_in Gain 0 Volume' 0%" -# codec0_out settings (used if SSP2 is connected to aif1) +# codec0_out settings (used if SSP2 is connected) cset "name='codec_out0 mix 0 codec_in0 Switch' off" cset "name='codec_out0 mix 0 codec_in1 Switch' off" cset "name='codec_out0 mix 0 media_loop1_in Switch' off" @@ -40,7 +40,7 @@ cset "name='codec_out0 mix 0 sprot_loop_in Switch' off" cset "name='codec_out0 Gain 0 Switch' on" cset "name='codec_out0 Gain 0 Volume' 0" -# modem_out settings (used if SSP0 is connected to aif2) +# modem_out settings (used if SSP0 is connected) cset "name='modem_out mix 0 codec_in0 Switch' off" cset "name='modem_out mix 0 codec_in1 Switch' off" cset "name='modem_out mix 0 media_loop1_in Switch' off" -- 2.20.1 From 7cea8c156204ebae7c0dc60801dde5ddfa5bb7d0 Mon Sep 17 00:00:00 2001 From: Brendan Shanks Date: Mon, 11 Feb 2019 11:51:26 -0800 Subject: [PATCH 6/7] pcm: dshare: Fix overflow when slave_hw_ptr rolls over boundary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In snd_pcm_dshare_sync_area() when 'slave_hw_ptr' rolls over 'slave_boundary', the wrong variable is checked ('dshare->slave_hw_ptr' vs the local 'slave_hw_ptr'). In some cases, this results in 'slave_hw_ptr' not rolling over correctly. 'slave_size' and 'size' are then much too large, and the for loop blocks for several minutes copying samples. This was likely only triggered on 32-bit systems, since the PCM boundary is computed based on LONG_MAX and is much larger on 64-bit systems. This same change was made to pcm_dmix in commit 6c7f60f7a982fdba828e4530a9d7aa0aa2b704ae ("Fix boundary overlap”) from June 2005. Signed-off-by: Brendan Shanks Signed-off-by: Takashi Iwai --- src/pcm/pcm_dshare.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c index 2bb735fe..f135b5df 100644 --- a/src/pcm/pcm_dshare.c +++ b/src/pcm/pcm_dshare.c @@ -121,7 +121,7 @@ static void snd_pcm_dshare_sync_area(snd_pcm_t *pcm) */ slave_hw_ptr -= slave_hw_ptr % dshare->slave_period_size; slave_hw_ptr += dshare->slave_buffer_size; - if (dshare->slave_hw_ptr > dshare->slave_boundary) + if (slave_hw_ptr >= dshare->slave_boundary) slave_hw_ptr -= dshare->slave_boundary; if (slave_hw_ptr < dshare->slave_appl_ptr) slave_size = slave_hw_ptr + (dshare->slave_boundary - dshare->slave_appl_ptr); -- 2.20.1 From deb07a0b208225393efc6347556310f3d8adb54d Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 1 Mar 2019 12:43:19 +0100 Subject: [PATCH 7/7] test/latency: use frame bytes correctly in writebuf() Reported-by: Alessandro Lapini Signed-off-by: Jaroslav Kysela --- test/latency.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/latency.c b/test/latency.c index e926856b..ddd5a7af 100644 --- a/test/latency.c +++ b/test/latency.c @@ -374,6 +374,7 @@ long readbuf(snd_pcm_t *handle, char *buf, long len, size_t *frames, size_t *max long writebuf(snd_pcm_t *handle, char *buf, long len, size_t *frames) { long r; + int frame_bytes = (snd_pcm_format_width(format) / 8) * channels; while (len > 0) { r = snd_pcm_writei(handle, buf, len); @@ -383,7 +384,7 @@ long writebuf(snd_pcm_t *handle, char *buf, long len, size_t *frames) if (r < 0) return r; // showstat(handle, 0); - buf += r * 4; + buf += r * frame_bytes; len -= r; *frames += r; } -- 2.20.1