1. Möchtest Du unser Team im Android OS-Bereich unterstützen? Details dazu findest du hier!
  2. Nimm jetzt an unserem 2. ADVENT-Gewinnspiel teil - Alle Informationen findest Du hier!

AudioRecorder Zykluszeit ermitteln/optimieren

Dieses Thema im Forum "Sonstige Apps & Widgets" wurde erstellt von El_Mariachi, 27.05.2011.

  1. El_Mariachi, 27.05.2011 #1
    El_Mariachi

    El_Mariachi Threadstarter Neuer Benutzer

    Beiträge:
    1
    Erhaltene Danke:
    0
    Registriert seit:
    27.05.2011
    Hallo zusammen...

    Ich habe eine kleine Klasse geschrieben, welche kurz das Mikrofon auswerten soll. Das funktioniert auch allerdings benötigt sie knapp 500 Millisekunden... :blink:

    Ich habe versucht verschiedene Parameter zu ändern aber 8Bit-Encoding unterstützt mein HTC Dream scheinbar nicht...
    ob die Samplerate 8000Hz oder 44100Hz beträgt- wirkt sich nicht auf mein Mess-Ergebnis aus... :sneaky:

    Die Mindestpuffergröße habe ich auch ermittelt: 2048

    Wie kann ich die Zykluszeit genau erfassen? oder gar beeinflussen?

    Hier die "Messfunktion".
    Code:
     
    [SIZE=2][COLOR=#7f0055][B][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/B][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] run() {[/SIZE]
    
    [LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]time1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=System.[I]currentTimeMillis[/I]();[/SIZE]
    [LEFT][SIZE=2]auswerten();[/SIZE]
    [SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[U]anzeigen[/U]();[/COLOR][/SIZE][/COLOR][/SIZE]
    [SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]time2[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=System.[I]currentTimeMillis[/I]();[/SIZE]
    [SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]diff[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]time2[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]-[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]time1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]Log.[I]w[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Differenz"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],Long.[I]toString[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]diff[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));[/SIZE][/LEFT]
    
    
    [SIZE=2]}[/SIZE][/LEFT]
    
    In auswerten() wird die Methode getInputData benutzt um den Buffer auszuwerten.​

    Code:
     
    [LEFT][SIZE=2][COLOR=#7f0055][B][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/B][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AudioInputData {[/SIZE][/LEFT]
    
     
    
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AudioRecord [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audioRecord[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE]
    
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mSamplesRead[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE]
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]buffersizebytes[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE]
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]channelConfiguration[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = AudioFormat.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CHANNEL_CONFIGURATION_MONO[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]; [/SIZE]
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audioEncoding[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = AudioFormat.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ENCODING_PCM_16BIT[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]; [/SIZE]
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]short[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][] [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]buffer[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]; [/SIZE]
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]samplefreq[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 8000; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[U]samp[/U] per [U]sec[/U] 8000, 11025, 22050 44100 or 48000[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
    [/LEFT]
    
    
    [/LEFT]
    
      
    
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AudioInputData() {[/SIZE]
    
    [LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]buffersizebytes[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = AudioRecord.[I]getMinBufferSize[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]samplefreq[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]channelConfiguration[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audioEncoding[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//2048[/COLOR][/SIZE][/COLOR][/SIZE]
    [LEFT][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]buffer[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]short[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]buffersizebytes[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]]; [/SIZE]
    [SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audioRecord[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AudioRecord(android.media.MediaRecorder.AudioSource.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MIC[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]samplefreq[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE]
    [SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]channelConfiguration[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audioEncoding[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]buffersizebytes[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE][/LEFT]
    
    [SIZE=2]}[/SIZE][LEFT] [/LEFT]
    [/LEFT]
    
    
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]short[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][] getInputData(){[/SIZE]
    
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] { [/SIZE]
    [LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audioRecord[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].startRecording(); [/SIZE]
    [SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mSamplesRead[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audioRecord[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].read([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]buffer[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], 0,[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]buffersizebytes[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE]
    [SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audioRecord[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].stop(); [/SIZE]
    [SIZE=2]} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Throwable t) { [/SIZE]
    [SIZE=2]System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2].println([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Fehler!"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    [SIZE=2]} [/SIZE]
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return [/COLOR][/SIZE][/COLOR][/SIZE][/B][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]buffer[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2];[/SIZE]
    [SIZE=2]}[/SIZE] [/LEFT]
    [/LEFT]
    
    
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] getSamples(){[/SIZE]
    
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return [/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mSamplesRead[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [LEFT][SIZE=2]}[/SIZE][/LEFT]
    [/LEFT]
    
    
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] getSampleFreq(){[/SIZE]
    
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]samplefreq[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [LEFT][SIZE=2]}[/SIZE][/LEFT]
    [/LEFT]
    
    
    [/LEFT]
    
     
     
    
    [LEFT][SIZE=2]}[/SIZE][/LEFT]
    
    
     
    Zuletzt bearbeitet: 27.05.2011

Diese Seite empfehlen