Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.1.0 (#unreleased)

- Feature [#468](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/pull/468) - Add macOS support
- Fixed [#491](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/491) - Update totalSamples calculation to account for bytes per sample

## 2.0.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class AudioRecorder : PluginRegistry.RequestPermissionsResultListener {
AudioFormat.CHANNEL_IN_STEREO -> 2
else -> 1
}
private val bytesPerSample: Int
get() = when (audioFormat) {
AudioFormat.ENCODING_PCM_8BIT -> 1
AudioFormat.ENCODING_PCM_16BIT -> 2
AudioFormat.ENCODING_PCM_FLOAT -> 4
else -> 2
}

override fun onRequestPermissionsResult(
requestCode: Int, permissions: Array<out String>, grantResults: IntArray
Expand Down Expand Up @@ -153,7 +160,7 @@ class AudioRecorder : PluginRegistry.RequestPermissionsResultListener {
commonEncoder.queueInputBuffer(audioData)
}
val rms = calculateRms(audioData, read)
totalSamples += read / channelCount
totalSamples += read / (channelCount * bytesPerSample)
val durationSec =
totalSamples.toDouble() / (recorderSettings?.sampleRate
?: Constants.DEFAULT_SAMPLE_RATE)
Expand Down