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-waveform channel parameter bug #55

Closed sonejostudios closed 6 years ago

sonejostudios commented 6 years ago

Hey, as in v. 1.04, the -c parameter doesn't work properly (on stereo file): -c 0 = mixdown to mono = ok -c 1 = waveform for channel 1 = ok -c -1 = invalid channel (should create one .png file with both channels, right?) -c 2 = invalid channel (should create waveform for channel 2)

Hope I can help, all the best

vince

erikd commented 6 years ago

@x42 Looking at the code, it looks like a render->channel value of less than 0 is supposed to do something but I can't figure out what. Any clues?

x42 commented 6 years ago

35540ef46 is wrong render->channel == -1 means "render all channels, each in its own graph, vertically separated.

>=0 only display one graph; with 0: sum all channels (mono downmix), >0: render channel 1 (left), 2(right) etc. up to (and including) info->channels

PS. Line 959 (35540ef46) should read if (render->channel < -1 || render->channel > info.channels)

sonejostudios commented 6 years ago

@erikd , @x42 Hey Erik, hey Robin, I compiled it yesterday and made some tests. Now it is possible to render each channel separately, but the "mixing channels" and "render all channels" don't work. Here the results:

sndfile-waveform -b -c 1 file.wav file.png -> okay (renders channel 1) sndfile-waveform -b -c 2 file.wav file.png -> okay (renders channel 2) sndfile-waveform -b -c 0 file.wav file.png -> Error: channel parameter must be in range [-1, 2] sndfile-waveform -b -c -1 file.wav file.png -> Error: channel parameter must be in range [-1, 2]

Hope I can help! All the best, Vince

x42 commented 6 years ago

Yes that is expected. Either git revert 35540ef46, or fix the condition render->channel can be -1, 0 or > 0. I don't know why Erik did make that commit.

x42 commented 6 years ago
diff --git a/src/waveform.c b/src/waveform.c
index 9adfd96..1a339e7 100644
--- a/src/waveform.c
+++ b/src/waveform.c
@@ -956,7 +956,7 @@ render_sndfile (RENDER * render)
                exit (EXIT_FAILURE) ;
                } ;

-       if (render->channel < 1 || render->channel > info.channels)
+       if (render->channel < -1 || render->channel > info.channels)
        {       printf ("Error: channel parameter must be in range [%d, %d]\n", -1, info.channels) ;
                sf_close (infile) ;
                exit (EXIT_FAILURE) ;
sonejostudios commented 6 years ago

now it works as expected, thank you!

erikd commented 6 years ago

Thanks. Closing this.