@@ -200,8 +200,10 @@ private void init(int sampleRate, int channel, int bitDepth) {
200200 this .encodeBit = 8 ;
201201 }
202202 Log .e (TAG , "recordMinBufferSize is: " + recordMinBufferSize );
203- recordMinBufferSize = (sampleRate *this .channelCount *this .encodeBit /8 )/1000 *20 ; //20ms数据长度
204- Log .e (TAG , "20ms recordMinBufferSize is: " + recordMinBufferSize );
203+ if (sampleRate != 8000 ) {
204+ recordMinBufferSize = (sampleRate * this .channelCount * this .encodeBit / 8 ) / 1000 * 20 ; //20ms数据长度
205+ Log .e (TAG , "20ms recordMinBufferSize is: " + recordMinBufferSize );
206+ }
205207 Log .e (TAG , "AudioRecordUtil init Pitch is: " + pitch );
206208 GvoiceJNIBridge .init (context );
207209 }
@@ -456,17 +458,7 @@ public void run() {
456458 if (buffer != null && pcmEncoder != null ) {
457459 byte [] playerPcmBytes = onReadPlayerPlayPcm (buffer .length );
458460 if (playerPcmBytes != null && playerPcmBytes .length > 0 ) {
459- byte [] expandBuffer = buffer ;
460- if (buffer .length < AEC_PCM_MIN_FRAME_SIZE ) {
461- expandBuffer = new byte [AEC_PCM_MIN_FRAME_SIZE ];
462- System .arraycopy (buffer , 0 , expandBuffer , 0 , buffer .length );
463- }
464- byte [] expandPlayerPcmBytes = playerPcmBytes ;
465- if (playerPcmBytes .length < AEC_PCM_MIN_FRAME_SIZE ) {
466- expandPlayerPcmBytes = new byte [AEC_PCM_MIN_FRAME_SIZE ];
467- System .arraycopy (playerPcmBytes , 0 , expandPlayerPcmBytes , 0 , playerPcmBytes .length );
468- }
469- byte [] aecPcmBytes = GvoiceJNIBridge .cancellation (expandBuffer , expandPlayerPcmBytes );
461+ byte [] aecPcmBytes = GvoiceJNIBridge .cancellation (buffer , playerPcmBytes );
470462 if (isRecord ) {
471463 writePcmBytesToFile (buffer , playerPcmBytes , aecPcmBytes );
472464 }
0 commit comments