You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add methods for suppressing all Sound library info/warning messages to Sound() class #65
I was trying to read the amplitude of a .wav file at a given sample, n, so I used the processing.sound.AudioSample#read(n)
function which gave me what I wanted, so I was happy, but then I noticed that the terminal was completely swamped with messages about how this was a stereo wave file and it was only giving the amplitude for the left channel. Messages which were completely inconsequential for me as I didn't care which channel the amplitude came from. This was annoying because I was monitoring certain params with the terminal output and it was impossible to find the figures amongst the spam. I thought it was using some kind of logging system which I could turn off but I looked into the source code and found that it was just using System.out.println(). I read into this more and realised that this is not good coding practice.
The example I gave is actually common throughout the codebase and many of the System.out.println() usages link back to this method:
processing.core.PApplet#println(java.lang.String)
I suggest that we use a more sophisticated logging package in place of this method to avoid the problems like the one I described
Good call, looking back at that method in particular it's strange that I put a warning message instead of simply providing better documentation of what the method actually does. I'll remove that particular warning message (and add a separate read method where the channel number can be specified) to the next version. Thanks for reporting!
As for the occasional logging of other errors/warnings to the Processing console, those only occur when a sketch performs malformed/redundant operations on Sound objects, so they are really there to flag up potential coding problems to beginner users instead of them just sitting there wondering why no sound comes out. There's actually only one place where System.out.println() is called and that is the library's central Engine.printMessage() method which all those messages are funneled through. I'll add a library config option for suppressing all messages (and optionally also warnings) at runtime!
@besketh just to clarify the behaviour of the read(int) method you've been using (which was actually incorrectly described by the warning message as well as documentation): say you have a 1 second stereo sample at a framerate of 44100, then sample.frames() will return 44100, but read(int) will actually access all 88200 data point of the stereo sample, in interleaved order:
sample.read(0) returns the left channel sample at the first frame
sample.read(1) returns the right channel sample at the first frame
sample.read(44100) returns the left channel sample half a second into the file
sample.read(88199) is the right channel sample at the very last frame
changed the title [-]Annoying use of System.out.println() spams the terminal.[/-][+]Add methods for suppressing all Sound library info/warning messages to Sound() class[/+]on Mar 18, 2021
Hi, I still have these warning when setting the amplitude to 0 with version 2.4.0 - but this is intentional as I need to dynamically change volumes and at times assign 0 to certain channels.
In Engine.java line 606:
// static helper methods that do stuff like checking argument values or
// printing library messages
protected static boolean checkAmp(float amp) {
if (amp < -1 || amp > 1) {
Engine.printError("amplitude has to be in [-1,1]");
return false;
} else if (amp == 0.0) {
Engine.printWarning("an amplitude of 0 means this sound is not audible now");
}
return true;
}
Activity
kevinstadler commentedon Mar 17, 2021
Good call, looking back at that method in particular it's strange that I put a warning message instead of simply providing better documentation of what the method actually does. I'll remove that particular warning message (and add a separate read method where the channel number can be specified) to the next version. Thanks for reporting!
As for the occasional logging of other errors/warnings to the Processing console, those only occur when a sketch performs malformed/redundant operations on Sound objects, so they are really there to flag up potential coding problems to beginner users instead of them just sitting there wondering why no sound comes out. There's actually only one place where
System.out.println()is called and that is the library's centralEngine.printMessage()method which all those messages are funneled through. I'll add a library config option for suppressing all messages (and optionally also warnings) at runtime!besketh commentedon Mar 17, 2021
Thanks for the quick reply, and explanation :) your proposed improvements seem like a good resolution.
Remove AudioSample.read(int) stereo warning (addresses #65) and add A…
kevinstadler commentedon Mar 18, 2021
No more warning redtext in the console with
v2.3.1, which should become available from the Contribution Manager in the next couple of days (or for manual installation right now, from https://github.com/processing/processing-sound/releases/tag/v2.3.1).@besketh just to clarify the behaviour of the
read(int)method you've been using (which was actually incorrectly described by the warning message as well as documentation): say you have a 1 second stereo sample at a framerate of 44100, thensample.frames()will return 44100, butread(int)will actually access all 88200 data point of the stereo sample, in interleaved order:sample.read(0)returns the left channel sample at the first framesample.read(1)returns the right channel sample at the first framesample.read(44100)returns the left channel sample half a second into the filesample.read(88199)is the right channel sample at the very last frameThe release also contains a new example sketch which demonstrates the difference between
read(index)and the newly addedread(index, channel)method, in case you do want easy access to frames from both channels: https://github.com/processing/processing-sound/blob/8bc3339fd2a43431b22e82c4b38fa164bf57e3e0/examples/Soundfile/StereoSample/StereoSample.pdeThanks again for reporting!
[-]Annoying use of System.out.println() spams the terminal.[/-][+]Add methods for suppressing all Sound library info/warning messages to Sound() class[/+]besketh commentedon Mar 18, 2021
Nicely done! Cheers :)
trackme518 commentedon Dec 13, 2023
Hi, I still have these warning when setting the amplitude to 0 with version 2.4.0 - but this is intentional as I need to dynamically change volumes and at times assign 0 to certain channels.
In Engine.java line 606:
What is the method to supress warnings?