-
Notifications
You must be signed in to change notification settings - Fork 33
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
Set sampling rate (compress output) #15
Comments
Hi @ThomasArtProcessors, yes, you're right! I'll start working on it and keep you posted. |
Thanks for the quick reply. |
Hi @ThomasArtProcessors, now you can use New version: For example: You can also increase param value. Here is an example screenshot with custom waveform and different samplesPerSecond: Doc: https://github.com/lincollincol/Amplituda#-compress-output-data |
Hi again @lincollincol ! |
@ThomasArtProcessors Hello! Amplituda provides only extracted audio data and compress(custom number of samples)/cache features. Here are some instructions, which help you draw a flexible waveform:
val amplitudesList: List<Int> = Amplituda(context).process(...).amplitudesAsList()
val desiredSpikeWidth: Float = 4.px
val desiredSpikePadding: Float = 2.px
val canvas: Canvas = /* init canvas */
val singleSpikeWidth: Float = desiredSpikeWidth + desiredSpikePadding
val spikesPerCanvas: Int = canvas.width / singleSpikeWidth
val amplitudePerSpikeList: List<Float> = amplitudesList
.chunked(amplitudesList.count() / spikesPerCanvas)
.map { it.average() }
amplitudePerSpikeList.forEachIndexed { spikeIndex, spikeHeight ->
drawRoundRect(
brush = waveformBrush,
topLeft = Offset(
x = spikeIndex * singleSpikeWidth,
y = canvas.height / 2F - spikeHeight / 2F // Center spikes
),
size = Size(
width = singleSpikeWidth,
height = spikeHeight
)
)
}
|
@ThomasArtProcessors If you have any questions, I'll be glad to answer :) |
Hi! Sorry I think I explained it wrongly. I was thinking of using the combination of
|
Though the issue comes in when you have something like this:
|
@ThomasArtProcessors I have created a custom Test cases: Case 1: Remainder > 0
Case 2: Remainder > 0 AND samples.size / remainder = float value
So, If we can't average these internal fun <T> Iterable<T>.chunkedToSize(size: Int, transform: (List<T>) -> T): List<T> {
val chunkSize = count() / size
val remainder = count() % size
val remainderIndex = ceil(count().safeDiv(remainder)).roundToInt()
val chunkedIteration = filterIndexed { index, _ ->
remainderIndex == 0 || index % remainderIndex != 0
}.chunked(chunkSize, transform)
return when (chunkedIteration.count()) {
size -> chunkedIteration
else -> chunkedIteration.chunkedToSize(size, transform)
}
}
internal fun Int.safeDiv(value: Int): Float {
return if(value == 0) return 0F else this / value.toFloat()
} val samples = List(100) { it }
val spikes = 80
samples.map(Int::toFloat).chunkedToSize(spikes) { it.average().toFloat() } |
Thanks!
|
Hi there.
Would it be possible to have the sampling rate as a parameter we can set?
We might not need that many values. We can then do a sampling of the result but that's extra work twice: Extra sampling calculation of the audio, then the averaging of slices of the results.
Thanks.
The text was updated successfully, but these errors were encountered: