-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAudioChunkAggregator.java
67 lines (49 loc) · 1.71 KB
/
AudioChunkAggregator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.example.android_mfcc;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
public class AudioChunkAggregator {
public synchronized void putChunk( short[] chunk ){
mChunksNewToOld.addLast( chunk );
mTotalNumSamples += chunk.length;
}
public synchronized int totalNumSamples() { return mTotalNumSamples; }
public synchronized float[] getConsecutive400SamplesInfloat() {
if (mTotalNumSamples < 400) {
return null;
}
float[] arrayOut = new float[400];
ListIterator<short[]> iter = mChunksNewToOld.listIterator(0);
int writePos = 0;
int numChunksToDelete = 0;
boolean Done = false;
while ( !Done ) {
short[] curChunk = iter.next();
int readPos = mNextReadPosInCurChunk;
while ( readPos < curChunk.length ) {
arrayOut[writePos] = (float)( curChunk[ readPos ] );
readPos++;
writePos++;
mTotalNumSamples--;
if ( writePos == 400 ) {
Done = true;
break;
}
}
if ( readPos == curChunk.length ) {
mNextReadPosInCurChunk = 0;
numChunksToDelete++;
}
else {
mNextReadPosInCurChunk = readPos;
}
}
for ( int i = 0; i < numChunksToDelete; i++ ) {
mChunksNewToOld.removeFirst();
}
return arrayOut;
}
private LinkedList< short[] > mChunksNewToOld = new LinkedList< short[] >();
private int mTotalNumSamples = 0;
private int mNextReadPosInCurChunk = 0;
}