2013-03-06 4 views
0

Pourquoi le tampon audioDatashort[] je crée dans le code ci-dessous rempli de 0 à chaquetampon audiorecord rempli de zéros

samplesIn += mRecordInstance.read(audioData, samplesIn, bufferSize - samplesIn); 

?

La taille du tampon (audioData.length) n'est PAS ZÉRO, ce qui signifie que le tampon n'est PAS VIDE, il est simplement rempli de zéros.

J'ai essayé de changer le FREQUENCY en 8000 -> aucun changement.

J'implémente la bibliothèque Echoprint - veuillez refer to this pour plus d'informations si vous en avez besoin.

Preuve de LogCat que le tampon audioData est rempli de zéros:

// ... 
public final static int LISTENING_PASS_TIME = 20; 
// cap to 30 seconds max, 10 seconds min. 
public final static int MAX_LISTENING_PASS_TIME = 30; 
public final static int MIN_LISTENING_PASS_TIME = 10; 

private final int FREQUENCY = 11025; 
private final int CHANNEL = AudioFormat.CHANNEL_IN_MONO; 
private final int ENCODING = AudioFormat.ENCODING_PCM_16BIT;  

private Thread thread; 
private volatile boolean isRunning = false; 
AudioRecord mRecordInstance = null; 

private short audioData[]; 
private int bufferSize; 
private int secondsToRecord; 
private volatile boolean continuous; 

public void stop() { 
    this.continuous = false; 
    if (mRecordInstance != null) 
     mRecordInstance.stop();  
} 

public void run() { 
    this.isRunning = true; 
    try { 
     // create the audio buffer & get the minimum buffer size 
     int minBufferSize = AudioRecord.getMinBufferSize(FREQUENCY, 
       CHANNEL, ENCODING); 
     Log.d("Fingerprinter", "minBufferSize: " + minBufferSize); 

     // and the actual buffer size for the audio to record frequency * 
     // seconds to record. 
     bufferSize = Math.max(minBufferSize, this.FREQUENCY 
       * this.secondsToRecord); 
     Log.d("Fingerprinter", "bufferSize: " + bufferSize); 

     audioData = new short[bufferSize]; 

     // start recorder 
     mRecordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC, 
       FREQUENCY, CHANNEL, ENCODING, minBufferSize); 

     // start recording 
     willStartListening(); 

     mRecordInstance.startRecording(); 
     boolean firstRun = true; 
     do { 
      try { 
       willStartListeningPass(); 

       long time = System.currentTimeMillis(); 
       // fill audio buffer with mic data. 
       int samplesIn = 0; 
       do { 
        samplesIn += mRecordInstance.read(audioData, samplesIn, 
          bufferSize - samplesIn); 

        if (mRecordInstance.getRecordingState() == AudioRecord.RECORDSTATE_STOPPED) 
         break; 
       } while (samplesIn < bufferSize); 
       Log.d("Fingerprinter", 
         "Audio recorded: " 
           + (System.currentTimeMillis() - time) 
           + " millis"); 

       // see if the process was stopped. 
       if (mRecordInstance.getRecordingState() == AudioRecord.RECORDSTATE_STOPPED 
         || (!firstRun && !this.continuous)) 
        break; 

       // debugging: print audioData short[] 
       Log.d("Fingerprinter", "Audio Data Content:"); 

       // String audioDataContent = ""; 
       for (int i = 100; i < 110; i++) { 
        // audioDataContent = i + ":" + audioData[i]; 
        Log.d("Fingerprinter", i + ":" + audioData[i]); 
       } 

       Log.d("Fingerprinter", "samplesIn: " + samplesIn); 

       firstRun = false; 

       didFinishListeningPass(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
       Log.e("Fingerprinter", e.getLocalizedMessage()); 

       didFailWithException(e); 
      } 
     } while (this.continuous); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     Log.e("Fingerprinter", e.getLocalizedMessage()); 

     didFailWithException(e); 
    } 

    if (mRecordInstance != null) { 
     mRecordInstance.stop(); 
     mRecordInstance.release(); 
     mRecordInstance = null; 
    } 
    this.isRunning = false; 

    didFinishListening(); 
} 

Répondre

0

Je trouve que je l'ai en fait enregistrer certaines données - il était juste la section que j'ai choisi d'afficher que seulement enregistré zeros. Je le prouve en récapitulant toutes les entrées dans le tableau audioData et en le divisant par le nombre d'entrées dans le tableau. Le résultat était -3.455619047619048.

Questions connexes