0

I'm trying to create a program that finds the note of a .mp3 file that the user adds. What I have so far is:

public void audioToNotes(String path){
    File f = new File(path);
    AudioInputStream ais = AudioSystem.getAudioInputStream(f);
}

And then I'm stuck. Sorry if this is a noob question, I'm here to learn, and I'm just a beginner.

EDIT: I surfed the web a bit, and found this code:

AudioInputStream din = null;
        final AudioFormat baseFormat = in.getFormat();
        final AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                baseFormat.getSampleRate(),
                16,
                baseFormat.getChannels(),
                baseFormat.getChannels() * 2,
                baseFormat.getSampleRate(),
                false);
ruyili
  • 694
  • 10
  • 25

1 Answers1

2

Frequency detection has nothing directly to do with the MP3 format.

There isn't an API that I know of that will let you do this

notes = analyze(audioSignal)

where notes is a collection of pitches.

For periodic waveforms, you can do a FFT on this audio signal. There are DSP libraries out there. Still not automatic.

N.B. Signal processing is not easy and it involves quite a bit of math.

Gene De Lisa
  • 3,628
  • 1
  • 21
  • 36
  • I've never worked with those before: could you give me an example, or provide me with a link? That would be very helpful :) – ruyili Jan 20 '16 at 22:32
  • 1
    Like this? http://stackoverflow.com/questions/636686/signal-processing-library-in-java – ruyili Jan 20 '16 at 22:33
  • I agree! I'm studying electronics and ICT and find this project extremely difficult, especially for a 12yo. Tone recognition itself should not be that difficult, But I think OP wants to read the mp3 and derive the notes without having to play it. – Didier Lauwerys Jan 20 '16 at 22:33
  • @FloydSomeone Sound can be oberved as sinewaves. These sinewaves have frequencies. In higher mathematics, you can do a fourier transformation which will allow you to observe the frequencies instead of the waves. – Didier Lauwerys Jan 20 '16 at 22:37
  • Thanks for the info! Sadly, Fourier's transformation is not included in my grade's curriculum:( EDIT: nor sinewaves – ruyili Jan 20 '16 at 22:41
  • The good news is that you have a practical use case for learning advanced math; motivation if you will. I remember being distracted when I was learning it because I didn't think I'd ever use that kind of math. – Gene De Lisa Jan 21 '16 at 11:21
  • 1
    BTW. this is a very good interactive tutorial on DSP. https://jackschaedler.github.io/circles-sines-signals/index.html – Gene De Lisa Jan 21 '16 at 12:13