Skip to content

Implement pitch detector class #58

Description

@Joe23232

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.

image

For example if I want to get the loudness (I believe this is the amplitude) here is the sample code:

import processing.sound.*;
Amplitude amp;
AudioIn in;

void setup() {
  size(640, 360);
  background(255);
    
  // Create an Input stream which is routed into the Amplitude analyzer
  amp = new Amplitude(this);
  in = new AudioIn(this, 0);
  in.start();
  amp.input(in);
}      

void draw() {
  println(amp.analyze());
}

Where is the the sound coming in from?

Activity

  1. kevinstadler commented on Jul 30, 2020

    @kevinstadler
    Collaborator

    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

  2. Joe23232 commented on Jul 30, 2020

    @Joe23232
    Author

    THanks for your help :)

  3. Joe23232 commented on Jul 30, 2020

    @Joe23232
    Author

    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?

  4. kevinstadler commented on Sep 18, 2023

    @kevinstadler
    Collaborator

    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) {
        ...
      }
    }
  5. changed the title [-]Is it possible to get various information about an audio file such as current tempo, loudness, key/pitch etc?[/-] [+]Implement pitch detector class[/+] on Sep 18, 2023
  6. added
    enhancementNew feature or request
    and removed
    questionQuestion about setting up or using the library
    on Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions