Putting this together with ratchov@'s recent patch, mostly to clarify for myself.
On Feb 09 10:24:47, com...@daknet.org wrote: > I'm trying to record audio with 24-bits precision with sox > and it seems to be impossible: > > rec -t flac -c 2 -r 48000 -b 24 test.flac > > Input File : 'default' (sndio) > Channels : 2 > Sample Rate : 48000 > Precision : 32-bit > Sample Encoding: 32-bit Signed Integer PCM > > In:0.00% 00:00:16.90 [00:00:00.00] Out:807k [ | ] Clip:0 > > It is always encoded with 32-bits precision That's a slight missunderstanding. SoX does whatever the underlying audio system enables it to do. Here, you asked for 24bit samples, but the underlying audio (presumably) cannot record 24bit samples, so SoX records 32bit samples instead AND re-encodes them to 24bit for you. What you see above are the parameters of the input; the output is what you wanted - a 24bit file. > Is it a known bug with sox generally (however i didn't find anything on this) > or a bug with sox only on openbsd ? Or maybe a problem with my configuration ? It is a general problem: if you want to record 24 bit samples, but the audio hardware can only record 16b or 32b, what is SoX gonna do? Record 32b and reencode for you. > For information, i use this sndiod configuration : > sndiod_flags="-r 48000 -e s24le -s default" With a running sndiod, audio applications are layered away from the physical audio hardware, and sndiod will reencode and resample on the fly to and from just about anything. For example, if you ask SoX to record 24bit samples, the the running sndiod will provide 24bit samples, whatever the underlying device really does. BTW, I don't think your '-e s24le' succeeds in configuring the device to using 24bits, as the device probably cannot really do that. On Feb 09 23:30:41, a...@caoua.org wrote: > This should fix the problem. If bits_per_sample is set, then use > it to configure sndiod; otherwise, pick a value close to precision > or the default sox precision. Yes, this makes SoX ask for the right parameters, and if the underlying audio system supports them, they will be used (tested on amd64, i386, macppc). Thank you! A running sndiod does support e.g. 24bits; Morgan's audio device (and mine too) does not. In that case, SoX _will_ directly play/record the 24bit samples without reencoding - it will be sndiod doing the conversion. (Right, Alex?) On Sep 14 08:24:45, a...@caoua.org wrote: > the diff was forgotten, it's discussed here: [...] > It's about playing 24-bit files with full precision (assuming audio > sub-system supports it), i.e. without converting samples to 16-bit > first and loosing 8-bits of precision. I dont think that's exactly what the original problem was, but the patch is definitely an improvement. I took the liberty of sending it upstream (I maintain audio/sox). On Sep 14 13:46:59, a...@smagin.com wrote: > Both playback and recording with 24bit precision appear to work for me. > (Recording turntable->phono preamp->line-in on the on-board sound card.) > > One thing I noticed: > when recording with sndiod running, sox prints > "Precision : 24-bit" > but when sndiod is disabled, it prints > "Precision : 32-bit" > when using the same command. The resulting files are in the same format > though. Yes, see above: with sndiod running, it's sndiod doing the conversion transparently, so SoX thinks it's getting 24bit. Without sndiod running, SoX records directly from the device, which cannot do 24bit, so SoX records 32bit and reencodes for you. > Input File : 'default' (sndio) > Channels : 2 > Sample Rate : 48000 > Precision : 24-bit > Sample Encoding: 24-bit Signed Integer PCM vs > Input File : 'default' (sndio) > Channels : 2 > Sample Rate : 48000 > Precision : 32-bit > Sample Encoding: 32-bit Signed Integer PCM But: > HAMLET: /tmp/0 $ ffmpeg -i test1.wav 2>&1 | grep Stream > > Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, > s32 (24 bit), 2304 kb/s > > HAMLET: /tmp/0 $ ffmpeg -i test2.wav 2>&1 | grep Stream > Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, > s32 (24 bit), 2304 kb/s You might like soxi(1) better for these inspections. Jan