10

ここに画像の説明を入力してください



助けを求める前に、私が何をしたかをお話ししましょう。サンプリングレートが8000Hzサンプルサイズが16ビット(2バイト)であるとすると、1秒の終わりに16000バイトまたは8000ショートが必要になります。
これで、10 fpsの記録速度が得られ、fpsごとに16000/10=1600バイトが必要になります。
だから、これが物語がどのように進行するかです:

宣言された変数:

byte[] eachPass = new byte[1600]; //used to store data from TargetDataLine for each pass
byte[] backingArray = new byte[16000]; //the complete data for one second
ByteBuffer buffer = ByteBuffer.wrap(backingArray); //buffer which stores the complete data
short[] audioSample = new short[16000/2]; //audio samples to be encoded
int passCounter = 0; /* After 10th pass, convert the byte[] to short[]
                      * using ByteBuffer */
int seconds = 0; // used to store the position of the packet

byte[]からshort[]へのループとその後の変換

while(keepCapturing == true){
    -- set up the java.awt.Robot and TargetDataLine before entering the loop --
    -- use java.awt.Robot to record the screen --
    -- do some other stuff, if needed --
    fromMic.read(eachPass,0,eachPass.length); // read data from microphone
    buffer.put(eachPass); //put it in  a bigger buffer

    if(passCounter!=0 && passCounter%10==0){ // is it 10th frame?
        passCounter = 0; //reset counter
        seconds++;
        buffer.asShortBuffer.get(audioSamples); //get short[] in BigEndian format
        -- encode the audio at position (seconds-1) --
        buffer.clear();
    }else{
        passCounter++;
    }  

問題

  • ステートメントでbuffer.position()16000を返しますが、ifBufferUnderflowExceptionbuffer.asShortBuffer.get(audioSamples);

  • 以前は自分の内容と内容java.util.Arrays.toString()を確認していましたが、eachPassで-107、0、32などの数値を取得し、audioSamplesですべてゼロを取得しました。なんで?eachPassaudioSamples
  • ベテラン、このコードを釘付けにするのを手伝ってくれませんか?何が起こっているのか分かりません。

    4

    1 に答える 1

    7

    データを読み取る前にバッファを反転するのを忘れています。これが、 に何も書き込まれない理由ですaudioSamples

    buffer.flip();
    buffer.asShortBuffer.get(audioSamples);
    
    于 2012-12-26T19:18:47.620 に答える