-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Update sound classification JAVA reference app DO NOT SUBMIT #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
||
import java.nio.FloatBuffer; | ||
|
||
public class AudioBuffer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TensorAudio
return buffer.length; | ||
} | ||
|
||
public void feed(float v) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load
} | ||
} | ||
|
||
public float[] getArray() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getFloatArray()
} | ||
|
||
// TODO: what's the correct name? | ||
public int feed(float[] data, int size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return size here?
} | ||
|
||
private float pcm16ToFloat(short v) { | ||
return (float) v / 32768; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like normalization. So the value of float audio buffer will not exceed 1.0f?
} | ||
|
||
// TODO: ownership | ||
public FloatBuffer GetAudioBufferInFloat() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getFloatBuffer to be consistent with TensorBuffer
|
||
public void feed(float[] data, int size) { | ||
for (int i = 0; i < size; i++) { | ||
feed(data[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be very slow. Need to optimize it in the real implementation.
public class AudioBuffer { | ||
|
||
// TODO: What if the ring buffer is not yet fully filled before invocation? | ||
private class FloatRingBuffer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to double confirm with the ring buffer idea. Does all audio classifier expect the ring buffer input? Are there use cases that only need a single audio clip, i.e. not a ring buffer, but a regular buffer like TensorBuffer?
|
||
public int feed(short[] data, int size) { | ||
for (int i = 0; i < size; i++) { | ||
floatRingBuffer.feed(pcm16ToFloat(data[i])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is using floatRingBuffer determined by the input AudioFormat when creating AudioBuffer? i.e. if the AudioFormat's encoding is ENCODING_PCM_16BIT, will we instantiate a ShortRingBuffer?
No description provided.