Skip to content

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

wangtz
Copy link
Member

@wangtz wangtz commented Mar 17, 2021

No description provided.

@google-ml-butler google-ml-butler bot added the size:L CL Change Size: Large label Mar 17, 2021
@google-cla google-cla bot added the cla: yes CLA has been signed label Mar 17, 2021
@wangtz wangtz changed the title Demo Update sound classification JAVA reference app DO NOT SUBMIT Mar 17, 2021

import java.nio.FloatBuffer;

public class AudioBuffer {
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load

}
}

public float[] getArray() {
Copy link
Member

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) {
Copy link
Member

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;
Copy link
Member

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() {
Copy link
Member

@lu-wang-g lu-wang-g Mar 18, 2021

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]);
Copy link
Member

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 {
Copy link
Member

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]));
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes CLA has been signed size:L CL Change Size: Large
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants