Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BCCE7C3DA60 for ; Thu, 18 Jul 2024 04:55:44 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id B95A1E82; Thu, 18 Jul 2024 06:55:32 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B95A1E82 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1721278542; bh=bIukJ+kgusr4eFJzCUy8XUr5vqNM6T7KWsQyAJWtl44=; h=Subject:From:To:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=iE8kkUTPhANbvw30OtI9e9p3/v620v2IaOw2T2fuYZ9JBjPyh26u+MD72qYe4EJom 0dXK0+5qK5udm0i0l7lXgaWx/I/P/a0jzrG3LnVcX3whAkgeIzGf3WdBrn2e/5RV4l lEFgv4HSHIjmNUaSyLimrygCqDcn4XcdG+0qgLUw= Received: by alsa1.perex.cz (Postfix, from userid 50401) id CF0A9F805B0; Thu, 18 Jul 2024 06:55:10 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 0AFF8F805AF; Thu, 18 Jul 2024 06:55:10 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 16608F80508; Thu, 18 Jul 2024 06:52:36 +0200 (CEST) Received: from mailman-web.alsa-project.org (mailman-web.alsa-project.org [10.254.200.11]) by alsa1.perex.cz (Postfix) with ESMTP id 0AB21F8007E for ; Thu, 18 Jul 2024 06:52:36 +0200 (CEST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Inconsistent order of channels on C-Media 7.1 channel device From: victor@allumeenergy.com.au To: alsa-devel@alsa-project.org Date: Thu, 18 Jul 2024 04:52:36 -0000 Message-ID: <172127835604.6185.4671370925729472425@mailman-web.alsa-project.org> User-Agent: HyperKitty on https://mailman.alsa-project.org/ Message-ID-Hash: UFSZOETYKLOBOOYNKXVVUTY46BTLSF63 X-Message-ID-Hash: UFSZOETYKLOBOOYNKXVVUTY46BTLSF63 X-MailFrom: victor@allumeenergy.com.au X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: I have a USB sound device (Startech ICUSBAUDIO7D, which comes up as `ID 0d8c:0102 C-Media Electronics, Inc. CM106 Like Sound Device` through lsusb) which I'm trying to program the output of for 8 channels. The python code (outputs a 50Hz sine wave) I'm using is below (each channel gets a different amplitude so I can identify them with an oscilloscope). The sound card has 4 stereo jacks, to which I have a scope connected. The problem is that on different runs of the program, the output mappings are not consistent - each run of the program might have the order of the channels different to the previous. So running it one time might have amplitudes (0, 0.125) on the first jack, but the next run it might have those (0.75, 0.25) on the first jack (it doesn't appear to be 'paired' per jack) I initially discovered this when using portaudio, and decided to try using alsa-only and the issue persists. Is this likely to be a problem with the driver, alsa-lib, or is there something else going on here? ``` import numpy as np import alsaaudio def sine_wave(amplitude=1, freq=50, sample_rate=48000): wave_len = sample_rate/freq samples = (amplitude * 32767 * np.sin(2 * np.pi * np.arange(wave_len) * freq / sample_rate)).astype(np.int16) return samples def eightchan(freq=50, sample_rate=48000): wave_len = sample_rate//freq frames = np.zeros((wave_len, 8), dtype=np.int16) samples = sine_wave() for c in range(8): frames[:wave_len,c] = samples[:wave_len]*(c/8) return frames.tobytes() if __name__ == '__main__': pcm = alsaaudio.PCM(device='surround71:CARD=ICUSBAUDIO7D,DEV=0', format=alsaaudio.PCM_FORMAT_S16_LE, channels=8, rate=48000, type=alsaaudio.PCM_PLAYBACK, periodsize=960, periods=1) frames = eightchan() while True: pcm.write(frames) ``` alsa-info output is attached [alsa-info.txt](https://github.com/user-attachments/files/16277691/alsa-info.txt)