On 23/01/10 09:36, Alexandre Ratchov wrote:
> On Mon, Jan 09, 2023 at 01:10:09PM -0700, Ashlen wrote:
> > 
> > Although I need to finalize the Perl script I was using to do this (life 
> > gets
> > busy), in practice I was able to distinguish between samples created by
> > audio/sox and aucat(1) in informal AB/X testing on my 7th generation X1 
> > Carbon
> > with HiFiMan Sundara headphones plugged in. To describe the circumstances +
> > outcome briefly: 9 out of 10 correct in 10 trials; randomly sampling from an
> > array containing the givens A and B to get an unknown X; comparing 15 
> > seconds of
> > audio; audio/sox as the playback software. In the future, I would do >=16
> > trials, and perhaps conduct the tests from my desktop instead since it has a
> > discrete amp and DAC.
> > 
> > In offline resampling from 48kHz to 44.1kHz, the highs were most affected 
> > and
> > that's what I was able to use to distinguish between samples. The 
> > percussion,
> > especially the cymbals, sounded different in particular because the clip
> > resampled by aucat had cymbal crashes that seemed to 'shimmer' much less 
> > (the
> > decay was more rapid). The spectrograms seemed to confirm that the highs 
> > were
> > most affected. 
> > 
> > Whether that means "low quality resampling" or merely that the results of 
> > the
> > two commands can be differentiated is something I'm uncertain of. Either 
> > way, I
> > don't know enough about C or sndio internals to be useful in that domain 
> > yet. As
> > an aside, I did find this to be a useful resource for learning about digital
> > audio resampling, and they recommend audio/sox there.
> > 
> > https://ccrma.stanford.edu/~jos/resample/
> > 
> > I hadn't said anything about this earlier because I wanted to take the time 
> > to
> > finish + document the script, reproduce my results with a royalty free 
> > sample at
> > a greater trial count, and then post. Given that I haven't done so yet, I 
> > can at
> > least post the commands used to resample the audio for those that are
> > interested.
> > 
> > 
> > # This was originally an opus file downloaded with www/yt-dlp.
> > # Converting to WAV so both SoX and aucat can work with it.
> > $ opusdec input.{opus,wav}
> > 
> > # Resample 16-bit 48kHz WAV file to 44.1kHz using both SoX and aucat(1).
> > #
> > # If I recall correctly, I converted to FLAC here because the WAV headers
> > # generated by aucat and SoX differed, and so SoX would refuse to play WAV 
> > files
> > # created by aucat.
> > $ sox -G input.wav -t wav - rate -v 44100 | flac - -o output-sox.flac
> > $ aucat -i input.wav -h wav -r 44100 -e s16 -o - | flac - -o 
> > output-aucat.flac
> > 
> > # Generate spectrograms for later inspection/comparison.
> > $ sox output-sox.flac -n spectrogram -o spectrogram-sox.png
> > $ sox output-aucat.flac -n spectrogram -o spectrogram-aucat.png
> > 
> 
> Thank you for all the details. Do you mind sharing the youtube link
> (or the input.wav file) so I can experiment with the same file and
> examine the data

I don't mind. :) I provided the way I downloaded it in the last reply, although
I'll add the link here as well for convenience.

https://www.youtube.com/watch?v=ei8hPkyJ0bU

> > I'd certainly be interested in the ability to play audio in a way that 
> > avoids
> > resampling altogether, similar to what a user can do on FreeBSD with the
> > following sysctl tweaks:
> > 
> > # sysctl hw.snd.maxautovchans=0 dev.pcm.0.bitperfect=1
> > 
> 
> This is equivalent to bypassing sndiod. The OpenBSD equivalent is as
> follows:
> 
> chown <your_user_id> /dev/audio*
> rcctl stop sndiod

Interesting, I'll try that later to see how it works. I suppose this does give
up the advantage of a privilege separated audio daemon, however, and the
ownership modification means that a regular user can change things they
otherwise couldn't [ mixerctl(8), audioctl(8) ]. Hard to have that cake and eat
it too. Though it does leave me feeling impressed with the way OpenBSD's sound
infrastructure is designed. Lots of other systems would ship with a regular user
having raw access to the device itself, and it's a plus in my book that OpenBSD
doesn't (instead it's _sndiop).

> Note that bit-perfect audio and avoiding resampling are not the same
> thing. The latter is more complicated but it would keep current
> features working (mixing, routing, device switching) by making sndiod
> dynamically set device sample rates to match the sample rate of a
> particular client (for instance an audio player), other programs (if
> any) would resample.

This would be a very cool thing to have, and this improvement actually has the
opportunity to keep the ownership of `/dev/audio*` intact as well. Though I
guess sndiod(8) would also have to keep track of what rates the device is
capable of while it does this, so that whenever a client declares a rate that
doesn't match the device's capabilities it would resample instead of trying and
failing to dynamically set the device's sample rate.

Reply via email to