Files
playdate-kit/Sources/PlaydateKit/Sound/Effect/Classes/Overdrive.swift
T
javier c5037dd716 Swift 6.4 migration and exhancements (#1)
This PR contains the work done to update the library and the attached example project to use the Swift 6.4 computer as a minimum supported version and also, to use the latest features introduced in it.

Reviewed-on: #1
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
2026-09-18 13:15:08 +00:00

57 lines
2.0 KiB
Swift

internal import CPlaydate
extension Sound {
/// An overdrive/distortion effect. Wraps `Overdrive`.
public final class Overdrive: Effect {
private static var api: UnsafePointer<playdate_sound_effect_overdrive> { Playdate.overdriveAPI.unsafelyUnwrapped }
private var retainedModulators: [SignalValue] = []
public init() {
super.init(pointer: Overdrive.api.pointee.newOverdrive.unsafelyUnwrapped().unsafelyUnwrapped,
isOwned: true)
}
deinit {
if isOwned {
Overdrive.api.pointee.freeOverdrive.unsafelyUnwrapped(pointer)
}
}
/// Input gain, applied before clipping.
public func setGain(_ gain: Float) {
Overdrive.api.pointee.setGain.unsafelyUnwrapped(pointer, gain)
}
/// The level where the amplified input clips.
public func setLimit(_ limit: Float) {
Overdrive.api.pointee.setLimit.unsafelyUnwrapped(pointer, limit)
}
public var limitModulator: SignalValue? {
get { SignalValue.wrap(Overdrive.api.pointee.getLimitModulator.unsafelyUnwrapped(pointer)) }
set {
retain(newValue)
Overdrive.api.pointee.setLimitModulator.unsafelyUnwrapped(pointer, newValue?.pointer)
}
}
/// Added to the upper and lower limits, making clipping asymmetric.
public func setOffset(_ offset: Float) {
Overdrive.api.pointee.setOffset.unsafelyUnwrapped(pointer, offset)
}
public var offsetModulator: SignalValue? {
get { SignalValue.wrap(Overdrive.api.pointee.getOffsetModulator.unsafelyUnwrapped(pointer)) }
set {
retain(newValue)
Overdrive.api.pointee.setOffsetModulator.unsafelyUnwrapped(pointer, newValue?.pointer)
}
}
private func retain(_ modulator: SignalValue?) {
if let modulator { retainedModulators.append(modulator) }
}
}
}