I am trying to develop an Android App like Shazam. I searched how Shazam worked on Google and I found the best link to follow. Which is https://www.toptal.com/algorithms/shazam-it-music-processing-fingerprinting-and-recognition. As you can see in the link, it records the song first. But I am having the problem with its recording code cause android studio is showing error with red underline for that code. Please have a look at this code.
private AudioFormat getFormat() {
float sampleRate = 44100;
int sampleSizeInBits = 16;
int channels = 1; //mono
boolean signed = true; //Indicates whether the data is signed or unsigned
boolean bigEndian = true; //Indicates whether the audio data is stored in big-endian or little-endian order
return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
}
Edited for Andrew Cheong's Answer
private AudioFormat getFormat() {
float sampleRate = 44100;
int sampleSizeInBits = 16;
int channels = 1; //mono
boolean signed = true; //Indicates whether the data is signed or unsigned
boolean bigEndian = true; //Indicates whether the audio data is stored in big-endian or little-endian order
return new AudioFormat.Builder().setSampleRate(Math.round(sampleRate)).build();
}
If you look at the documentation for AudioFormat, you might notice that it has a "Builder Class."
class AudioFormat.Builder
Builder class for AudioFormat objects.
Builder class for AudioFormat objects. Use this class to configure and create an AudioFormat instance. By setting format characteristics such as audio encoding, channel mask or sample rate, you indicate which of those are to vary from the default behavior on this device wherever this audio format is used. See AudioFormat for a complete description of the different parameters that can be used to configure an AudioFormat instance.
Here's the build()
method.
This is a kind of "pattern" in application design, and it's a little abstract / difficult to understand if you're not a student of design patterns, but here's a relevant article anyway.