Resampler

expect class Resampler(input: AudioSpec, output: AudioSpec) : AutoCloseable

Converts audio frames between sample rates, channel counts and sample formats with FFmpeg's libswresample.

Resampler(AudioSpec(48_000, 2, SampleFormat.FltP), AudioSpec(44_100, 2, SampleFormat.S16)).use { resampler ->
decoded.forEach { frame -> frame.use { resampler.convert(it)?.use(::write) } }
generateSequence { resampler.flush() }.forEach { it.use(::write) }
}

A channel layout is FFmpeg's default for the channel count unless AudioSpec.channelLayoutMask names one, so two channels are stereo and six are 5.1 with back surrounds. A layout change at the same count is converted too, such as side surrounds to back surrounds. A rate change holds some samples back to filter them, so a converted frame can be shorter than the one that went in, and flush returns the samples still held once the input ends. Output frames carry microsecond timestamps: the first one starts at the first input frame's timestamp (or zero when it had none), and every later one follows from the samples before it.

Not thread safe: use one resampler from one thread at a time. Available on the JVM, Android and the native targets; on the web the constructor throws FFmpegError.Unsupported.

Throws

when a rate or channel count is not positive, or a sample format is not one FFmpeg knows.

actual class Resampler(val input: AudioSpec, val output: AudioSpec) : AutoCloseable

Converts audio frames between sample rates, channel counts and sample formats with FFmpeg's libswresample.

Resampler(AudioSpec(48_000, 2, SampleFormat.FltP), AudioSpec(44_100, 2, SampleFormat.S16)).use { resampler ->
decoded.forEach { frame -> frame.use { resampler.convert(it)?.use(::write) } }
generateSequence { resampler.flush() }.forEach { it.use(::write) }
}

A channel layout is FFmpeg's default for the channel count unless AudioSpec.channelLayoutMask names one, so two channels are stereo and six are 5.1 with back surrounds. A layout change at the same count is converted too, such as side surrounds to back surrounds. A rate change holds some samples back to filter them, so a converted frame can be shorter than the one that went in, and flush returns the samples still held once the input ends. Output frames carry microsecond timestamps: the first one starts at the first input frame's timestamp (or zero when it had none), and every later one follows from the samples before it.

Not thread safe: use one resampler from one thread at a time. Available on the JVM, Android and the native targets; on the web the constructor throws FFmpegError.Unsupported.

Throws

when a rate or channel count is not positive, or a sample format is not one FFmpeg knows.

actual class Resampler(val input: AudioSpec, val output: AudioSpec) : AutoCloseable

Converts audio frames between sample rates, channel counts and sample formats with FFmpeg's libswresample.

Resampler(AudioSpec(48_000, 2, SampleFormat.FltP), AudioSpec(44_100, 2, SampleFormat.S16)).use { resampler ->
decoded.forEach { frame -> frame.use { resampler.convert(it)?.use(::write) } }
generateSequence { resampler.flush() }.forEach { it.use(::write) }
}

A channel layout is FFmpeg's default for the channel count unless AudioSpec.channelLayoutMask names one, so two channels are stereo and six are 5.1 with back surrounds. A layout change at the same count is converted too, such as side surrounds to back surrounds. A rate change holds some samples back to filter them, so a converted frame can be shorter than the one that went in, and flush returns the samples still held once the input ends. Output frames carry microsecond timestamps: the first one starts at the first input frame's timestamp (or zero when it had none), and every later one follows from the samples before it.

Not thread safe: use one resampler from one thread at a time. Available on the JVM, Android and the native targets; on the web the constructor throws FFmpegError.Unsupported.

Throws

when a rate or channel count is not positive, or a sample format is not one FFmpeg knows.

actual class Resampler(val input: AudioSpec, val output: AudioSpec) : AutoCloseable

Converts audio frames between sample rates, channel counts and sample formats with FFmpeg's libswresample.

Resampler(AudioSpec(48_000, 2, SampleFormat.FltP), AudioSpec(44_100, 2, SampleFormat.S16)).use { resampler ->
decoded.forEach { frame -> frame.use { resampler.convert(it)?.use(::write) } }
generateSequence { resampler.flush() }.forEach { it.use(::write) }
}

A channel layout is FFmpeg's default for the channel count unless AudioSpec.channelLayoutMask names one, so two channels are stereo and six are 5.1 with back surrounds. A layout change at the same count is converted too, such as side surrounds to back surrounds. A rate change holds some samples back to filter them, so a converted frame can be shorter than the one that went in, and flush returns the samples still held once the input ends. Output frames carry microsecond timestamps: the first one starts at the first input frame's timestamp (or zero when it had none), and every later one follows from the samples before it.

Not thread safe: use one resampler from one thread at a time. Available on the JVM, Android and the native targets; on the web the constructor throws FFmpegError.Unsupported.

Throws

when a rate or channel count is not positive, or a sample format is not one FFmpeg knows.

Constructors

Link copied to clipboard
expect constructor(input: AudioSpec, output: AudioSpec)
actual constructor(input: AudioSpec, output: AudioSpec)
actual constructor(input: AudioSpec, output: AudioSpec)
actual constructor(input: AudioSpec, output: AudioSpec)

Properties

Link copied to clipboard
expect val input: AudioSpec

What every frame handed to convert must be.

actual val input: AudioSpec

What every frame handed to convert must be.

actual val input: AudioSpec

What every frame handed to convert must be.

actual val input: AudioSpec

What every frame handed to convert must be.

Link copied to clipboard
expect val output: AudioSpec

What every frame this returns is.

actual val output: AudioSpec

What every frame this returns is.

actual val output: AudioSpec

What every frame this returns is.

actual val output: AudioSpec

What every frame this returns is.

Functions

Link copied to clipboard
expect open override fun close()
actual open override fun close()
actual open override fun close()
actual open override fun close()
Link copied to clipboard
expect fun convert(frame: Frame): Frame?

Converts frame, which stays the caller's to close. The caller owns the frame this returns, and gets null when the resampler held every sample back.

actual fun convert(frame: Frame): Frame?

Converts frame, which stays the caller's to close. The caller owns the frame this returns, and gets null when the resampler held every sample back.

actual fun convert(frame: Frame): Frame?

Converts frame, which stays the caller's to close. The caller owns the frame this returns, and gets null when the resampler held every sample back.

actual fun convert(frame: Frame): Frame?

Converts frame, which stays the caller's to close. The caller owns the frame this returns, and gets null when the resampler held every sample back.

Link copied to clipboard
expect fun flush(): Frame?

The samples the resampler still holds, as one frame the caller owns, or null when it holds none. Call it until it returns null once the input has ended.

actual fun flush(): Frame?

The samples the resampler still holds, as one frame the caller owns, or null when it holds none. Call it until it returns null once the input has ended.

actual fun flush(): Frame?

The samples the resampler still holds, as one frame the caller owns, or null when it holds none. Call it until it returns null once the input has ended.

actual fun flush(): Frame?

The samples the resampler still holds, as one frame the caller owns, or null when it holds none. Call it until it returns null once the input has ended.