libsndfile / sndfile-tools

A collection of tools (written in C) to do interesting things with sound files
http://libsndfile.github.io/sndfile-tools/
GNU General Public License v2.0
80 stars 36 forks source link

sndfile-mix-to-mono doesn't produce an output file #87

Open markk opened 1 year ago

markk commented 1 year ago

strace shows the output file being unlinked after being opened.

$ sox -n noise.wav synth 1 whitenoise channels 2
$ soxi noise.wav

Input File     : 'noise.wav'
Channels       : 2
Sample Rate    : 48000
Precision      : 32-bit
Duration       : 00:00:01.00 = 48000 samples ~ 75 CDDA sectors
File Size      : 384k
Bit Rate       : 3.07M
Sample Encoding: 32-bit Signed Integer PCM

$ strace sndfile-mix-to-mono noise.wav noise-mono.wav &> test.txt

test.txt

markk commented 1 year ago

Note that writing to stdout works:

sndfile-mix-to-mono noise.wav - > noise-mono.wav

... but that is not what --help describes as the correct usage.

evpobr commented 1 year ago

Hi @markk . Thanks for report.

janstary commented 3 months ago

This is the culprit:

 /* Delete the output file length to zero if already exists. */
 remove (argv [argc - 1]);

Note the confusing comment: perhaps it used to truncate the file to zero if it existed; now it unlinks the file from the filesystem, which means it will get removed once the program terminates.

Apparently, there is no reason to do that: if it exists, it will get overwritten. Even if the one that exists is longer, it will get (correctly) overwritten by a new shorter one, i.e. it is not like the rest of the old long one remains.

So a trivial fix is to just not do this.