-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve UX around seeing audio wave forms.
- 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
1 parent
d4ce845
commit 9610339
Showing
9 changed files
with
497 additions
and
337 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
app/src/main/java/org/thoughtcrime/securesms/audio/AudioFileInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
325
app/src/main/java/org/thoughtcrime/securesms/audio/AudioWaveForm.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.