0

I am using musicg library for comparing between two audio sounds. One of them is saved before and the another is detected by recording. musicg library have whistle demo; which I edited it to be works as I want.the problem is when I want to convert the detected sound [ which is a buffer ] to wav and get a fingurprint for it , it return nullpointerexption.

this is in MainAcivity.java

public static Wave w1;

InputStream sw1 = getBaseContext().getResources().openRawResource(R.raw.top_of_the_world_rec);

w1=new Wave(sw1);

and this in a DetectorThread.java

                InputStream obj = new ByteArrayInputStream(buffer);
                Wave woo = new Wave(obj);
                if (woo.toString() == null)
                    Log.i("", "recoded sound  is null");
                if (MainActivity.w1.toString() == null)
                    Log.i("", "the detected sound is null");
                try {
                    similarity = woo.getFingerprintSimilarity(MainActivity.w1);/// this couse null pointer exption
                    Log.i("", "1-" + similarity); // not appear
                    if (similarity == null) {  // not enter this if at all ~!
                        Log.i("", "lolol" + similarity);
                        TheSemilarityISnull = true;
                    }
                }
                catch (NullPointerException n) {
                    Log.i("", "first error");
                    TheSemilarityISnull = true;
                }
                // EnD of addition

                Log.i("", "2-" + similarity); //appear 2-null
                // byte[] io = MainActivity.w1.getFingerprint(); // good no problem
                // Log.i("", "00-"+io); // apear bk09823 like this
                try {

                    Log.i("", "0-");
                    byte[] po = woo.getFingerprint(); // ~> this couse null pointer exption
                    Log.i("", "0-" + po);
                    if (po == null)
                        Log.i("", "fingurprint for detected  sound is null ");//not appear
                    byte[] io = MainActivity.w1.getFingerprint();
                    Log.i("", "00-" + io);
                    if (io == null)
                        Log.i("", "fingurprint for recorded sound is null");//not appear
                    double scoure = new FingerprintSimilarityComputer(po, io).getFingerprintsSimilarity().getSimilarity();

                } catch (Exception e) {
                    Log.i("", "second error ");
                }

so ;

1-how to convert Byte[] to wav ?

2-and can I call class or Mothed inside thread ? Becouse I wonder that every time I call one of them it does not detect anything !

3- I do not edit the record thread at all> is that will couse problem ? please help me.

  • For your first question. [see here](http://stackoverflow.com/questions/731120/convert-byte-array-to-wav-java). – yiabiten Mar 31 '15 at 08:46
  • I do not get my answer ... the problem is when I want to convert the buffer - the varible in class detected thread - to wave it couse nullpointerexption ! – user3495695 Mar 31 '15 at 17:14

1 Answers1

0

The read buffer doesn't contain any wave header. These are just audio bytes. I have started implementing a class which might work. But it isn't final yet

public class WavApi extends DetectionApi {
  Wave waveToMatch;

  public WavApi(Wave wave) {
    super(wave.getWaveHeader());
    this.waveToMatch = wave;
  }

  public boolean matches(byte[] audioBytes) {
    Wave wave = new Wave(waveToMatch.getWaveHeader(), audioBytes);

    FingerprintSimilarityComputer fpc = new FingerprintSimilarityComputer(waveToMatch.getFingerprint(), wave.getFingerprint());
    FingerprintSimilarity similarity = fpc.getFingerprintsSimilarity();

    //--- TODO: find optimal condition to decide whether {audioBytes} matches {waveToMatch} or not
    float sim = similarity.getScore() * 100f;
    int pos   = similarity.getMostSimilarFramePosition();

    if (pos >= 0 && sim > 0)
        return true;
    //----

    return false;
  }
}
black-hawk
  • 151
  • 1
  • 5