Skip to content

Commit

Permalink
Improve UX around seeing audio wave forms.
Browse files Browse the repository at this point in the history
- Attempts to generate the wave form on download instead on display
- Allows multi-threaded generation of wave forms instead of serial
  executor
  • Loading branch information
cody-signal committed Feb 15, 2023
1 parent d4ce845 commit 9610339
Show file tree
Hide file tree
Showing 9 changed files with 497 additions and 337 deletions.
5 changes: 5 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.thoughtcrime.securesms.audio;

import androidx.annotation.NonNull;

import com.google.protobuf.ByteString;

import org.thoughtcrime.securesms.database.model.databaseprotos.AudioWaveFormData;

import java.util.concurrent.TimeUnit;

public class AudioFileInfo {
private final long durationUs;
private final byte[] waveFormBytes;
private final float[] waveForm;

public static @NonNull AudioFileInfo fromDatabaseProtobuf(@NonNull AudioWaveFormData audioWaveForm) {
return new AudioFileInfo(audioWaveForm.getDurationUs(), audioWaveForm.getWaveForm().toByteArray());
}

AudioFileInfo(long durationUs, byte[] waveFormBytes) {
this.durationUs = durationUs;
this.waveFormBytes = waveFormBytes;
this.waveForm = new float[waveFormBytes.length];

for (int i = 0; i < waveFormBytes.length; i++) {
int unsigned = waveFormBytes[i] & 0xff;
this.waveForm[i] = unsigned / 255f;
}
}

public long getDuration(@NonNull TimeUnit timeUnit) {
return timeUnit.convert(durationUs, TimeUnit.MICROSECONDS);
}

public float[] getWaveForm() {
return waveForm;
}

public @NonNull AudioWaveFormData toDatabaseProtobuf() {
return AudioWaveFormData.newBuilder()
.setDurationUs(durationUs)
.setWaveForm(ByteString.copyFrom(waveFormBytes))
.build();
}
}
325 changes: 0 additions & 325 deletions app/src/main/java/org/thoughtcrime/securesms/audio/AudioWaveForm.java

This file was deleted.

0 comments on commit 9610339

Please sign in to comment.