Closed Joe23232 closed 1 year ago
Currently there are only two built-in types of analysis available in the Sound library: Amplitude
for 'loudness', and FFT
for frequency spectrum analysis. You can derive more complex audio features like 'tempo' or 'key/pitch' from amplitude and FFT, but that's actually quite a complex task.
All analysis classes in the Sound library work in the same way: you choose which sound you want to analyse by calling:
analysisObject.input(soundObject);
So the example above analyses the amplitude of the sound coming out of an AudioIn
object, i.e. the microphone or line-in. If you want to analyse the amplitude of a file that's being played back instead just use the following lines during setup()
:
SoundFile file = new SoundFile(this, .....);
file.play();
Amplitude amp = new Amplitude(this);
amp.input(file);
There's not a lot of user traffic over here on Github normally, if you have more questions or need coding help it's probably best to ask them over here at the Processing Discourse board: https://discourse.processing.org/c/processing/processing-libraries/19
THanks for your help :)
I did ask the community this but they didn't know the answer.
So in regards to tempo, how would I specifically get it if you happen to know?
395a5dc added a BeatDetector
class which allows you to detect beats, which is not quite the 'tempo' of a track, but as close as you might get in a non-specialized piece of audio software. The other existing Analyzers are now more well-documented and presented in the new website reference, which means the only thing missing from the picture is a built-in pitch/frequency detection class. This should be pretty straightforward to implement by simply wrapping the JSyn PitchDetector
class. It might look something like this:
public class PitchDetector extends Analyzer {
private final com.jsyn.unitgen.PitchDetector detector;
private float minimumConfidence = 0.5;
public PitchDetector(PApplet parent) {
super(parent);
}
public PitchDetector(PApplet parent, float minimumConfidence) {
super(parent);
this.minimumConfidence = minimumConfidence;
}
// return the current frequency of the input signal if the confidence is at least as high
// as this detector's minimumConfidence, 0 otherwise
float analyze() {
...
}
// return the current frequency of the input signal if the confidence is at least as high
// as the given minimumConfidence, 0 otherwise
float analyze(float minimumConfidence) {
...
}
}
Is it possible to get various information about an audio file such as current tempo, loudness, key/pitch etc?
I am going through the sound library and I am finding some difficulties finding how to do this.
For example if I want to get the loudness (I believe this is the amplitude) here is the sample code:
Where is the the sound coming in from?