Skip to content

fix: 🐛️ Waveform extraction stuck at 99% #408

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 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.0.0 (Unreleased)

- Fixed [#350](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/350) - Left most visible wave is clipped in half when recording.
- Fixed [#390](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/390) - Setting continuousWaveform to false not working
- **BREAKING:** Fixed [#412](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/412) - Calling preparePlayer again does not cancel old waveform extraction.
- Feature [#415](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/pull/415) - Add stop extraction method and asynchronous extraction of waveform in ios
- **BREAKING:** Feature [#416](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/pull/416) - Add waveform extraction controller.
Expand All @@ -11,12 +12,12 @@
## 1.3.0

- Fixed [#386](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/pull/386) - On permission denied isRecording flag changed
- Fixed [#384](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/384) - Provide a callback of drag,tap,start and end details on user gesture
- Fixed [#309](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/309) - Added support for Liner PCM codec in iOS
- Feat [#384](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/384) - Provide a callback of drag,tap,start and end details on user gesture
- Feat [#309](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/309) - Added support for Liner PCM codec in iOS
- Fixed [#291](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/291) - Codec issue while recording audio on android
- Fixed [#391](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/pull/391) - Wrong codec selection on the platform side on Android
- Fixed [#389](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/pull/389) - Wrong codec selection on the platform side on iOS
- Fixed [#325](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/325) - Added feature to pause all player controller at once.
- Feat [#325](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/325) - Added feature to pause all player controller at once.
- Fixed [#373](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/373) - Getting error on dispose
- Fixed [#395](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/395) - Live wave gradient not getting applied

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class WaveformExtractor(
}

if (info.isEof()) {
updateProgress()
val rms = sqrt(sampleSum / perSamplePoints).toFloat()
sendProgress(rms)
stop()
}
}
Expand All @@ -160,31 +163,17 @@ class WaveformExtractor(
private var sampleCount = 0L
private var sampleSum = 0.0

private fun rms(value: Float) {
private fun handleBufferDivision(value: Float) {
if (sampleCount == perSamplePoints) {
currentProgress++
progress = currentProgress / expectedPoints
updateProgress()

// Discard redundant values and release resources
if (progress > 1.0F) {
stop()
return
}

val rms = sqrt(sampleSum / perSamplePoints)
sampleData.add(rms.toFloat())
extractorCallBack.onProgress(progress)
sampleCount = 0
sampleSum = 0.0

val args: MutableMap<String, Any?> = HashMap()
args[Constants.waveformData] = sampleData
args[Constants.progress] = progress
args[Constants.playerKey] = key
methodChannel.invokeMethod(
Constants.onCurrentExtractedWaveformData,
args
)
val rms = sqrt(sampleSum / perSamplePoints).toFloat()
sendProgress(rms)
}

sampleCount++
Expand All @@ -197,7 +186,7 @@ class WaveformExtractor(
if (channels == 2) {
buf.get()
}
rms(result)
handleBufferDivision(result)
}
}

Expand All @@ -210,7 +199,7 @@ class WaveformExtractor(
buf.get()
buf.get()
}
rms(value)
handleBufferDivision(value)
}
}

Expand All @@ -220,17 +209,38 @@ class WaveformExtractor(
val second = buf.get().toLong() shl 8
val third = buf.get().toLong() shl 16
val forth = buf.get().toLong() shl 24
val value = (first or second or third or forth) / 2147483648f
val value = (first or second or third or forth) / 2.14748365E9f
if (channels == 2) {
buf.get()
buf.get()
buf.get()
buf.get()
}
rms(value)
handleBufferDivision(value)
}
}

private fun updateProgress() {
currentProgress++
progress = currentProgress / expectedPoints
}

private fun sendProgress(rms: Float) {
sampleData.add(rms)
extractorCallBack.onProgress(progress)
sampleCount = 0
sampleSum = 0.0

val args: MutableMap<String, Any?> = HashMap()
args[Constants.waveformData] = sampleData
args[Constants.progress] = progress
args[Constants.playerKey] = key
methodChannel.invokeMethod(
Constants.onCurrentExtractedWaveformData,
args
)
}

fun stop() {
decoder?.stop()
decoder?.release()
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: audio_waveforms
description: A Flutter package that allow you to generate waveform while recording audio or from audio file.
version: 1.3.0
version: 1.4.0
homepage: https://github.com/SimformSolutionsPvtLtd/audio_waveforms
issue_tracker: https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues

Expand Down