Skip to content
Merged
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
4 changes: 2 additions & 2 deletions App/DemoAudioDevice.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AudioIO
import Foundation
import Recording

/// A synthetic multichannel signal for the simulator and UI work. Not real-time: blocks are
/// generated on a background task, roughly every 10 ms.
Expand Down Expand Up @@ -46,8 +47,7 @@ final class DemoAudioDevice: AudioIODevice, @unchecked Sendable {
blocks += 1
if overflows, blocks % 1_500 == 0 { fake.deliver(Array(repeating: Array(repeating: 0, count: 250_000), count: count)) }
let channels = (0..<count).map { channel -> [Float] in
// The last channel stays silent, so the meters show an unused USB Channel.
let level = Float(0.02 + 0.3 * (1 + sin(phase + Double(channel) * 0.6))) * (channel == count - 1 ? 0 : 1)
let level = DemoSignalLevel.peak(channel: channel, of: count, phase: phase)
return (0..<480).map { _ in Float.random(in: -level...level) }
}
var delivered = channels
Expand Down
13 changes: 13 additions & 0 deletions Packages/ShowRecorderKit/Sources/Recording/DemoSignalLevel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

/// How loud each channel of the Demo signal is (Debug and TestFlight builds, screenshots and Page videos): a level
/// that drifts slowly per channel, its average mostly in the meters' green target band and its peaks never red, so
/// it looks like a well-set show (Eric, 2026-11-15). The last channel stays silent, to show an unused USB Channel.
public enum DemoSignalLevel {
/// The peak level, linear 0...1, of `channel` (0-based) of `count` at this `phase`. The signal is uniform noise of
/// this peak, so its average is `peak / √3`.
public static func peak(channel: Int, of count: Int, phase: Double) -> Float {
guard channel != count - 1 else { return 0 }
return Float(0.25 + 0.05 * sin(phase + Double(channel) * 0.6))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Foundation
import Testing
@testable import Recording

/// The Demo signal's meters look like a healthy show (Eric, 2026-11-15): averages mostly in the green target band,
/// peaks never red. Draft 1 of the Facebook Page walkthrough clip ran most peak bars into red, which reads as clipping.
/// The signal is uniform noise of peak `level`, so its average (RMS) is `level / √3`.
struct DemoSignalLevelTests {
private let phases = stride(from: 0.0, to: 2 * Double.pi * 4, by: 0.05).map { $0 }

private func readings() -> [Float] {
phases.flatMap { phase in (0..<17).map { DemoSignalLevel.peak(channel: $0, of: 18, phase: phase) } }
}

@Test("Peaks never reach the red zone (above -6 dBFS) on any channel")
func neverRed() {
for level in readings() { #expect(20 * log10(Double(level)) < -6) }
}

@Test("Averages sit in the green target band (-18 to -15 dBFS) at least 60% of the time")
func mostlyOnTarget() {
let zones = readings().map { MeterZone(averageDbfs: 20 * log10(Double($0) / 3.0.squareRoot())) }
let onTarget = zones.filter { $0 == .onTarget }.count
#expect(Double(onTarget) / Double(zones.count) >= 0.6)
#expect(!zones.contains(.hot))
}

@Test("The last channel stays silent, so the meters show an unused USB Channel")
func lastChannelSilent() {
#expect(DemoSignalLevel.peak(channel: 17, of: 18, phase: 1) == 0)
#expect(DemoSignalLevel.peak(channel: 31, of: 32, phase: 1) == 0)
}
}
Loading