From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 25612 invoked from network); 21 Feb 2021 12:19:48 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 21 Feb 2021 12:19:48 -0000 Received: from mail-pg1-f182.google.com ([209.85.215.182]) by 1ess; Sun Feb 21 07:11:57 -0500 2021 Received: by mail-pg1-f182.google.com with SMTP id t11so8330677pgu.8 for <9front@9front.org>; Sun, 21 Feb 2021 04:11:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mforney-org.20150623.gappssmtp.com; s=20150623; h=date:to:subject:from:references:in-reply-to:message-id:user-agent :mime-version; bh=bMsyJWmjgFRLg4q3VMjXdjnp2qXQw0ulDuZ5wfqg74Q=; b=LXU6yXLMhRsRjG11OmItGZEnxa1Ct9RhcqbRY3QjGKJY0Xt573voJdSPzE2iiZeYcc r01h0qe1UHtHViQD9jNpx1+2aS0aer7/h2rUwn+JHKflLMzxFyBQsRw11FgY1c80KyQt 3WXdJs8jeOfq/JXPVfHcqb+NqzlUXKSxFVFfynnbnCAOM7pT3ssL86IKg4wcP0bjcHLM mI0Iw4fvdbRNFEzKkVNPXLxXNoPR1wERQP7XamB/eq51WWrQHtGPpORe+s8PGD3yKCMf FweEQG2T9gnqZl8LcesH4Gf4LTwnvaOFchKdcdrNcH980XiDwFj7aZG4ijrcxIQblBBK vG2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:to:subject:from:references:in-reply-to :message-id:user-agent:mime-version; bh=bMsyJWmjgFRLg4q3VMjXdjnp2qXQw0ulDuZ5wfqg74Q=; b=dXiY2aT/mjyEKtoZrPgyl/K69w7ZZW+amTARZ1dR9kT6b+60sLzFN4CCfTtkufYjPO Mp907iYh11Pdy/zrHLHxjzV40lAv649UpsLVBk/YYm/zv70ahP8jWgMIi+8eJgKc9KL9 SgeQ3jTsV/HoSBUrl0y4en0LELpL+fLFgMG6HYxvBGSAiDQkVT6u9hoMFM6ZnfeaVYxc iIKdXkg95C2Sqf2zFxra+tZOhSvc1em7pF74R/DBXvcw3oUngH8mL6fWki74hQJ9sPL1 NXAgjyRaZunNlbmWumglTNLsvHmOiIlxOsovfsbVhu34+JzROf9lsLw2jD3LB33Y3P+d itPw== X-Gm-Message-State: AOAM531fh5dWXXEGA6hyx+xYSA+Mu4kSsyDYYWfKLYkjSJJBJp0s+SAZ 7zemMWtzJnxKnvSk6wz++5Jd+yMp7BgAJsAhJNo= X-Google-Smtp-Source: ABdhPJyejStI0IBrIpN8je+l1CDWOWM9M01HN5SrdDtMJM5td3Qo/IMRomf2Cn2sEuNxmOLoqYmjGg== X-Received: by 2002:a17:902:6a88:b029:e3:cd8a:3a92 with SMTP id n8-20020a1709026a88b02900e3cd8a3a92mr8570390plk.22.1613905594384; Sun, 21 Feb 2021 03:06:34 -0800 (PST) Return-Path: Received: from localhost ([2601:647:5180:4570:5605:dbff:fe00:eccc]) by smtp.gmail.com with ESMTPSA id w13sm1876843pfc.98.2021.02.21.03.06.33 for <9front@9front.org> (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Feb 2021 03:06:33 -0800 (PST) Date: Sun, 21 Feb 2021 03:06:32 -0800 To: 9front@9front.org From: Michael Forney References: <71E80890743ACBD0D641DECE5D327028@arrow.hsd1.ca.comcast.net> In-Reply-To: <71E80890743ACBD0D641DECE5D327028@arrow.hsd1.ca.comcast.net> Message-Id: <3TYJK0YCE3OF6.2G7TZ7NP81HEX@mforney.org> User-Agent: mblaze/1.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_17512545338ac9550b1d0c84_=_" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: open CSS scripting frontend Subject: [9front] Re: games/snes audio patches Reply-To: 9front@9front.org Precedence: bulk This is a multipart message in MIME format. ------_=_17512545338ac9550b1d0c84_=_ Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Thanks everyone for the suggestions about resample techniques (and qwx for applying the other patches). I'm quite familiar with the jos resample algorithm used by pcmconv, I implemented it just a couple months ago for another project[0]. While the filter in pcmconv has a lot of coefficients, this is because it is a polyphase filter with 256 phases. Only 12 taps are used for each output sample, so it performs quite well. For anyone interested in the topic, I highly recommend reading through that document[1]. To compare the different approaches for resampling, I made a test file sweeping from 1 to 16 kHz with sox (similar to [2]): sox -n -t raw -e signed -b 16 -r 32000 sweep.pcm synth -n 5 sine 1+16000 ga= in -6 Here are the results: https://mforney.org/misc/snes-resample/ As is suggested by the spectrograms, aliasing is still audible in the higher frequencies in linear and hermite, but it is worse in linear. Nearest-neighbor is *really* bad (in fact, it's not even nearest neighbor, but next neighbor), so anything else is a huge improvement. I do think we should try to reuse the pcmconv code since it's already there and works well, but this is not something I plan on working on in the near future. For now, I think we should just change it to hermite or linear, since they can be implemented in just a few lines of code, and I'm not sure I could tell the difference between them and pcmconv for actual game audio. I attached a patch for hermite interpolation if that is preferred over linear. I'd be happy with either of them for now. [0] https://git.sr.ht/~mcf/resample/tree/master/item/resample.c [1] https://ccrma.stanford.edu/~jos/resample/resample.pdf [2] https://src.infinitewave.ca/ ------_=_17512545338ac9550b1d0c84_=_ Content-Type: multipart/mixed; boundary="upas-dltcruchgfvnoaegdvjdmjjvuu" Content-Disposition: inline This is a multi-part message in MIME format. --upas-dltcruchgfvnoaegdvjdmjjvuu Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit from postmaster@1ess: The following attachment had content that we can't prove to be harmless. To avoid possible automatic execution, we changed the content headers. The original header was: Content-Disposition: attachment; filename*0*=UTF-8''0001-games-snes-use-4-point-hermite-interpolation-to-; filename*1*=resample.patch Content-Type: text/x-diff;charset=us-ascii Content-Transfer-Encoding: quoted-printable --upas-dltcruchgfvnoaegdvjdmjjvuu Content-Type: application/octet-stream Content-Disposition: attachment; filename="file.suspect" Content-Transfer-Encoding: quoted-printable =46rom dd8e5ff3ae64aa752f21b3fd1309c19bb753cd5b =46rom: Michael Forney =44ate: Sun, 21 Feb 2021 10:44:34 +0000 =53ubject: games/snes: use 4-point hermite interpolation to resample =0A =54his is noticeably better than nearest-neighbor. =0Adiff 3937a76b73e983907018cce7e9de9439f3287d21 dd8e5ff3ae64aa752f21b3fd13= =309c19bb753cd5b =2D-- a/sys/src/games/snes/dsp.c Sun Feb 21 01:44:39 2021 =2B++ b/sys/src/games/snes/dsp.c Sun Feb 21 02:44:34 2021 =40@ -49,7 +49,6 @@ =20= =20enum { Freq =3D 44100 }; =20static s16int sbuf[2*2000], *sbufp; =2Dstatic int stime; =20static int fd; =20= =20void =40@ -61,16 +60,36 @@ =20 sbufp =3D sbuf; =20} =20= =2Bstatic int =2Bhermite(int *x, int t) =2B{ =2B int y; =2B =2B y =3D (x[0] - x[6]) / 2 + (x[4] - x[2]) * 3 / 2; =2B y =3D y * t >> 15; =2B y +=3D x[6] - x[4] * 5 / 2 + x[2] * 2 - x[0] / 2; =2B y =3D y * t >> 15; =2B y +=3D (x[2] - x[6]) / 2; =2B y =3D y * t >> 15; =2B y +=3D x[4]; =2B return y; =2B} =2B =20static void =20audiosample(s16int *s) =20{ =2D stime -=3D 1<<16; =2B static int x[8], t; =2B =2B x[0] =3D s[0]; =2B x[1] =3D s[1]; =20 do { =2D sbufp[0] =3D s[0]; =2D sbufp[1] =3D s[1]; =2B sbufp[0] =3D hermite(x, t); =2B sbufp[1] =3D hermite(x + 1, t); =20 sbufp +=3D 2; =2D stime +=3D (32000<<16)/Freq; =2D } while(stime < 0); =2B t +=3D (32000<<15)/Freq; =2B } while(t < 1<<15); =2B t -=3D 1<<15; =2B memmove(x + 2, x, sizeof(x) - 2 * sizeof(x[0])); =20} =20= =20int --upas-dltcruchgfvnoaegdvjdmjjvuu-- ------_=_17512545338ac9550b1d0c84_=_--