Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

537 wiersze
18KB

  1. package offline
  2. import (
  3. "context"
  4. "encoding/binary"
  5. "fmt"
  6. "log"
  7. "math"
  8. "path/filepath"
  9. "sync/atomic"
  10. "time"
  11. "github.com/jan/fm-rds-tx/internal/audio"
  12. cfgpkg "github.com/jan/fm-rds-tx/internal/config"
  13. "github.com/jan/fm-rds-tx/internal/license"
  14. "github.com/jan/fm-rds-tx/internal/watermark"
  15. "github.com/jan/fm-rds-tx/internal/dsp"
  16. "github.com/jan/fm-rds-tx/internal/mpx"
  17. "github.com/jan/fm-rds-tx/internal/output"
  18. "github.com/jan/fm-rds-tx/internal/rds"
  19. "github.com/jan/fm-rds-tx/internal/stereo"
  20. )
  21. type frameSource interface {
  22. NextFrame() audio.Frame
  23. }
  24. // LiveParams carries DSP parameters that can be hot-swapped at runtime.
  25. // Loaded once per chunk via atomic pointer — zero per-sample overhead.
  26. type LiveParams struct {
  27. OutputDrive float64
  28. StereoEnabled bool
  29. PilotLevel float64
  30. RDSInjection float64
  31. RDSEnabled bool
  32. LimiterEnabled bool
  33. LimiterCeiling float64
  34. MpxGain float64 // hardware calibration factor for composite output
  35. // Tone + gain: live-patchable without DSP chain reinit.
  36. ToneLeftHz float64
  37. ToneRightHz float64
  38. ToneAmplitude float64
  39. AudioGain float64
  40. // Composite clipper: live-toggleable without DSP chain reinit.
  41. CompositeClipperEnabled bool
  42. }
  43. // PreEmphasizedSource wraps an audio source and applies pre-emphasis.
  44. // The source is expected to already output at composite rate (resampled
  45. // upstream). Pre-emphasis is applied per-sample at that rate.
  46. type PreEmphasizedSource struct {
  47. src frameSource
  48. preL *dsp.PreEmphasis
  49. preR *dsp.PreEmphasis
  50. gain float64
  51. }
  52. func NewPreEmphasizedSource(src frameSource, tauUS, sampleRate, gain float64) *PreEmphasizedSource {
  53. p := &PreEmphasizedSource{src: src, gain: gain}
  54. if tauUS > 0 {
  55. p.preL = dsp.NewPreEmphasis(tauUS, sampleRate)
  56. p.preR = dsp.NewPreEmphasis(tauUS, sampleRate)
  57. }
  58. return p
  59. }
  60. func (p *PreEmphasizedSource) NextFrame() audio.Frame {
  61. f := p.src.NextFrame()
  62. l := float64(f.L) * p.gain
  63. r := float64(f.R) * p.gain
  64. if p.preL != nil {
  65. l = p.preL.Process(l)
  66. r = p.preR.Process(r)
  67. }
  68. return audio.NewFrame(audio.Sample(l), audio.Sample(r))
  69. }
  70. type SourceInfo struct {
  71. Kind string
  72. SampleRate float64
  73. Detail string
  74. }
  75. type Generator struct {
  76. cfg cfgpkg.Config
  77. // Persistent DSP state across GenerateFrame calls
  78. source *PreEmphasizedSource
  79. stereoEncoder stereo.StereoEncoder
  80. rdsEnc *rds.Encoder
  81. combiner mpx.DefaultCombiner
  82. fmMod *dsp.FMModulator
  83. sampleRate float64
  84. initialized bool
  85. frameSeq uint64
  86. // Broadcast-standard clip-filter-clip chain (per channel L/R):
  87. //
  88. // PreEmph → LPF₁(14kHz) → Notch(19kHz) → ×Drive
  89. // → StereoLimiter (slow AGC: raises average level)
  90. // → Clip₁ → LPF₂(14kHz) [cleanup] → Clip₂ [catches LPF overshoots]
  91. // → Stereo Encode → Composite Clip → Notch₁₉ → Notch₅₇
  92. // → + Pilot → + RDS → FM
  93. //
  94. audioLPF_L *dsp.FilterChain // 14kHz 8th-order (pre-clip)
  95. audioLPF_R *dsp.FilterChain
  96. pilotNotchL *dsp.FilterChain // 19kHz double-notch (guard band)
  97. pilotNotchR *dsp.FilterChain
  98. limiter *dsp.StereoLimiter // slow compressor (raises average, clips catch peaks)
  99. cleanupLPF_L *dsp.FilterChain // 14kHz 8th-order (post-clip cleanup)
  100. cleanupLPF_R *dsp.FilterChain
  101. mpxNotch19 *dsp.FilterChain // composite clipper protection
  102. mpxNotch57 *dsp.FilterChain
  103. bs412 *dsp.BS412Limiter // ITU-R BS.412 MPX power limiter (optional)
  104. compositeClip *dsp.CompositeClipper // ITU-R SM.1268 iterative composite clipper (optional)
  105. // Pre-allocated frame buffer — reused every GenerateFrame call.
  106. frameBuf *output.CompositeFrame
  107. bufCap int
  108. // Live-updatable DSP parameters — written by control API, read per chunk.
  109. liveParams atomic.Pointer[LiveParams]
  110. // Optional external audio source (e.g. StreamResampler for live audio).
  111. // When set, takes priority over WAV/tones in sourceFor().
  112. externalSource frameSource
  113. // Tone source reference — non-nil when a ToneSource is the active audio input.
  114. // Allows live-updating tone parameters via LiveParams each chunk.
  115. toneSource *audio.ToneSource
  116. // License: jingle injection when unlicensed.
  117. licenseState *license.State
  118. jingleFrames []license.JingleFrame
  119. // Watermark: spread-spectrum key fingerprint, always active.
  120. watermark *watermark.Embedder
  121. }
  122. func NewGenerator(cfg cfgpkg.Config) *Generator {
  123. return &Generator{cfg: cfg}
  124. }
  125. // SetLicense configures license state (jingle) and creates the watermark
  126. // embedder. Must be called before the first GenerateFrame.
  127. func (g *Generator) SetLicense(state *license.State, key string) {
  128. g.licenseState = state
  129. g.watermark = watermark.NewEmbedder(key)
  130. // Gate threshold: -40 dBFS ≈ 0.01 linear amplitude.
  131. // Watermark is muted during silence to prevent audibility.
  132. // Composite rate will be set in init(); use 228000 as default.
  133. g.watermark.EnableGate(0.01, 228000)
  134. }
  135. // SetExternalSource sets a live audio source (e.g. StreamResampler) that
  136. // takes priority over WAV/tone sources. Must be called before the first
  137. // GenerateFrame() call; calling it after init() has no effect because
  138. // g.source is already wired to the old source.
  139. func (g *Generator) SetExternalSource(src frameSource) error {
  140. if g.initialized {
  141. return fmt.Errorf("generator: SetExternalSource called after GenerateFrame; call it before the engine starts")
  142. }
  143. g.externalSource = src
  144. return nil
  145. }
  146. // UpdateLive hot-swaps DSP parameters. Thread-safe — called from control API,
  147. // applied at the next chunk boundary by the DSP goroutine.
  148. func (g *Generator) UpdateLive(p LiveParams) {
  149. g.liveParams.Store(&p)
  150. }
  151. // CurrentLiveParams returns the current live parameter snapshot.
  152. // Used by Engine.UpdateConfig to do read-modify-write on the params.
  153. func (g *Generator) CurrentLiveParams() LiveParams {
  154. if lp := g.liveParams.Load(); lp != nil {
  155. return *lp
  156. }
  157. return LiveParams{OutputDrive: 1.0, LimiterCeiling: 1.0, MpxGain: 1.0}
  158. }
  159. // RDSEncoder returns the live RDS encoder, or nil if RDS is disabled.
  160. // Used by the Engine to forward text updates.
  161. func (g *Generator) RDSEncoder() *rds.Encoder {
  162. return g.rdsEnc
  163. }
  164. func (g *Generator) init() {
  165. if g.initialized {
  166. return
  167. }
  168. g.sampleRate = float64(g.cfg.FM.CompositeRateHz)
  169. if g.sampleRate <= 0 {
  170. g.sampleRate = 228000
  171. }
  172. rawSource, _ := g.sourceFor(g.sampleRate)
  173. g.source = NewPreEmphasizedSource(rawSource, g.cfg.FM.PreEmphasisTauUS, g.sampleRate, g.cfg.Audio.Gain)
  174. g.stereoEncoder = stereo.NewStereoEncoder(g.sampleRate)
  175. g.combiner = mpx.DefaultCombiner{
  176. MonoGain: 1.0, StereoGain: 1.0,
  177. PilotGain: g.cfg.FM.PilotLevel, RDSGain: g.cfg.FM.RDSInjection,
  178. }
  179. if g.cfg.RDS.Enabled {
  180. piCode, _ := cfgpkg.ParsePI(g.cfg.RDS.PI)
  181. g.rdsEnc, _ = rds.NewEncoder(rds.RDSConfig{
  182. PI: piCode, PS: g.cfg.RDS.PS, RT: g.cfg.RDS.RadioText,
  183. PTY: uint8(g.cfg.RDS.PTY), SampleRate: g.sampleRate,
  184. })
  185. }
  186. ceiling := g.cfg.FM.LimiterCeiling
  187. if ceiling <= 0 { ceiling = 1.0 }
  188. // Broadcast clip-filter-clip chain:
  189. // Pre-clip: 14kHz LPF (8th-order) + 19kHz double-notch (per channel)
  190. g.audioLPF_L = dsp.NewAudioLPF(g.sampleRate)
  191. g.audioLPF_R = dsp.NewAudioLPF(g.sampleRate)
  192. g.pilotNotchL = dsp.NewPilotNotch(g.sampleRate)
  193. g.pilotNotchR = dsp.NewPilotNotch(g.sampleRate)
  194. // Slow compressor: 5ms attack / 200ms release. Brings average level UP.
  195. // The clips after it catch the peaks the limiter's attack time misses.
  196. // This is the "slow-to-fast progression" from broadcast processing:
  197. // slow limiter → fast clips.
  198. g.limiter = dsp.NewStereoLimiter(ceiling, 5, 200, g.sampleRate)
  199. // Post-clip cleanup: second 14kHz LPF pass (removes clip harmonics)
  200. g.cleanupLPF_L = dsp.NewAudioLPF(g.sampleRate)
  201. g.cleanupLPF_R = dsp.NewAudioLPF(g.sampleRate)
  202. // Composite clipper protection: double-notch at 19kHz + 57kHz
  203. g.mpxNotch19, g.mpxNotch57 = dsp.NewCompositeProtection(g.sampleRate)
  204. // ITU-R SM.1268 iterative composite clipper (optional, replaces simple clip+notch)
  205. // Always created so it can be live-toggled via CompositeClipperEnabled.
  206. g.compositeClip = dsp.NewCompositeClipper(dsp.CompositeClipperConfig{
  207. Ceiling: ceiling,
  208. Iterations: g.cfg.FM.CompositeClipper.Iterations,
  209. SoftKnee: g.cfg.FM.CompositeClipper.SoftKnee,
  210. LookaheadMs: g.cfg.FM.CompositeClipper.LookaheadMs,
  211. SampleRate: g.sampleRate,
  212. })
  213. // BS.412 MPX power limiter (EU/CH requirement for licensed FM)
  214. if g.cfg.FM.BS412Enabled {
  215. // chunkSec is not known at init time (Engine.chunkDuration may differ).
  216. // Pass 0 here; GenerateFrame computes the actual chunk duration from
  217. // the real sample count and updates BS.412 accordingly.
  218. g.bs412 = dsp.NewBS412Limiter(
  219. g.cfg.FM.BS412ThresholdDBr,
  220. g.cfg.FM.PilotLevel,
  221. g.cfg.FM.RDSInjection,
  222. 0,
  223. )
  224. }
  225. if g.cfg.FM.FMModulationEnabled {
  226. g.fmMod = dsp.NewFMModulator(g.sampleRate)
  227. maxDev := g.cfg.FM.MaxDeviationHz
  228. if maxDev > 0 {
  229. if g.cfg.FM.MpxGain > 0 && g.cfg.FM.MpxGain != 1.0 {
  230. maxDev *= g.cfg.FM.MpxGain
  231. }
  232. g.fmMod.MaxDeviation = maxDev
  233. }
  234. }
  235. // Seed initial live params from config
  236. g.liveParams.Store(&LiveParams{
  237. OutputDrive: g.cfg.FM.OutputDrive,
  238. StereoEnabled: g.cfg.FM.StereoEnabled,
  239. PilotLevel: g.cfg.FM.PilotLevel,
  240. RDSInjection: g.cfg.FM.RDSInjection,
  241. RDSEnabled: g.cfg.RDS.Enabled,
  242. LimiterEnabled: g.cfg.FM.LimiterEnabled,
  243. LimiterCeiling: ceiling,
  244. MpxGain: g.cfg.FM.MpxGain,
  245. ToneLeftHz: g.cfg.Audio.ToneLeftHz,
  246. ToneRightHz: g.cfg.Audio.ToneRightHz,
  247. ToneAmplitude: g.cfg.Audio.ToneAmplitude,
  248. AudioGain: g.cfg.Audio.Gain,
  249. CompositeClipperEnabled: g.cfg.FM.CompositeClipper.Enabled,
  250. })
  251. if g.licenseState != nil {
  252. frames, err := license.LoadJingleFrames(license.JingleWAV(), g.sampleRate)
  253. if err != nil {
  254. log.Printf("license: jingle load failed: %v", err)
  255. } else {
  256. g.jingleFrames = frames
  257. }
  258. }
  259. // Update watermark gate ramp rate with actual composite rate (may differ
  260. // from the 228000 default used in SetLicense).
  261. if g.watermark != nil {
  262. g.watermark.EnableGate(0.01, g.sampleRate)
  263. }
  264. g.initialized = true
  265. }
  266. func (g *Generator) sourceFor(sampleRate float64) (frameSource, SourceInfo) {
  267. if g.externalSource != nil {
  268. return g.externalSource, SourceInfo{Kind: "stream", SampleRate: sampleRate, Detail: "live audio"}
  269. }
  270. if g.cfg.Audio.InputPath != "" {
  271. if src, err := audio.LoadWAVSource(g.cfg.Audio.InputPath); err == nil {
  272. return audio.NewResampledSource(src, sampleRate), SourceInfo{Kind: "wav", SampleRate: float64(src.SampleRate), Detail: g.cfg.Audio.InputPath}
  273. }
  274. ts := audio.NewConfiguredToneSource(sampleRate, g.cfg.Audio.ToneLeftHz, g.cfg.Audio.ToneRightHz, g.cfg.Audio.ToneAmplitude)
  275. g.toneSource = ts
  276. return ts, SourceInfo{Kind: "tone-fallback", SampleRate: sampleRate, Detail: g.cfg.Audio.InputPath}
  277. }
  278. ts := audio.NewConfiguredToneSource(sampleRate, g.cfg.Audio.ToneLeftHz, g.cfg.Audio.ToneRightHz, g.cfg.Audio.ToneAmplitude)
  279. g.toneSource = ts
  280. return ts, SourceInfo{Kind: "tones", SampleRate: sampleRate, Detail: "generated"}
  281. }
  282. func (g *Generator) GenerateFrame(duration time.Duration) *output.CompositeFrame {
  283. g.init()
  284. samples := int(duration.Seconds() * g.sampleRate)
  285. if samples <= 0 { samples = int(g.sampleRate / 10) }
  286. // Reuse buffer — grow only if needed, never shrink
  287. if g.frameBuf == nil || g.bufCap < samples {
  288. g.frameBuf = &output.CompositeFrame{
  289. Samples: make([]output.IQSample, samples),
  290. }
  291. g.bufCap = samples
  292. }
  293. frame := g.frameBuf
  294. frame.Samples = frame.Samples[:samples]
  295. frame.SampleRateHz = g.sampleRate
  296. frame.Timestamp = time.Now().UTC()
  297. g.frameSeq++
  298. frame.Sequence = g.frameSeq
  299. // Load live params once per chunk — single atomic read, zero per-sample cost
  300. lp := g.liveParams.Load()
  301. if lp == nil {
  302. // Fallback: should never happen after init(), but be safe
  303. lp = &LiveParams{OutputDrive: 1.0, LimiterCeiling: 1.0, MpxGain: 1.0}
  304. }
  305. // Apply live tone and gain updates each chunk. GenerateFrame runs on a
  306. // single goroutine so these field writes are safe without additional locking.
  307. if g.toneSource != nil {
  308. g.toneSource.LeftFreq = lp.ToneLeftHz
  309. g.toneSource.RightFreq = lp.ToneRightHz
  310. g.toneSource.Amplitude = lp.ToneAmplitude
  311. }
  312. if g.source != nil {
  313. g.source.gain = lp.AudioGain
  314. }
  315. // Broadcast clip-filter-clip FM MPX signal chain:
  316. //
  317. // Audio L/R → PreEmphasis
  318. // → LPF₁ (14kHz, 8th-order) → 19kHz Notch (double)
  319. // → × OutputDrive → HardClip₁ (ceiling)
  320. // → LPF₂ (14kHz, 8th-order) [removes clip₁ harmonics]
  321. // → HardClip₂ (ceiling) [catches LPF₂ overshoots]
  322. // → Stereo Encode
  323. // Audio MPX (mono + stereo sub)
  324. // → HardClip₃ (ceiling) [composite deviation control]
  325. // → 19kHz Notch (double) [protect pilot band]
  326. // → 57kHz Notch (double) [protect RDS band]
  327. // + Pilot 19kHz (fixed, NEVER clipped)
  328. // + RDS 57kHz (fixed, NEVER clipped)
  329. // → FM Modulator
  330. //
  331. // Guard band depth at 19kHz: LPF₁(-21dB) + Notch(-60dB) + LPF₂(-21dB)
  332. // + CompNotch(-60dB) → broadband floor -42dB, exact 19kHz >-90dB
  333. ceiling := lp.LimiterCeiling
  334. if ceiling <= 0 { ceiling = 1.0 }
  335. // Pilot and RDS are FIXED injection levels, independent of OutputDrive.
  336. // Config values directly represent percentage of ±75kHz deviation:
  337. // pilotLevel: 0.09 = 9% = ±6.75kHz (ITU standard)
  338. // rdsInjection: 0.04 = 4% = ±3.0kHz (typical)
  339. pilotAmp := lp.PilotLevel
  340. rdsAmp := lp.RDSInjection
  341. // BS.412 MPX power limiter: uses previous chunk's measurement to set gain.
  342. // Power is measured during this chunk and fed back at the end.
  343. bs412Gain := 1.0
  344. var bs412PowerAccum float64
  345. if g.bs412 != nil {
  346. bs412Gain = g.bs412.CurrentGain()
  347. }
  348. if g.licenseState != nil {
  349. g.licenseState.Tick()
  350. }
  351. for i := 0; i < samples; i++ {
  352. in := g.source.NextFrame()
  353. // --- Stage 1: Band-limit pre-emphasized audio ---
  354. l := g.audioLPF_L.Process(float64(in.L))
  355. l = g.pilotNotchL.Process(l)
  356. r := g.audioLPF_R.Process(float64(in.R))
  357. r = g.pilotNotchR.Process(r)
  358. // Watermark injection — AFTER 14kHz LPF, before Drive/Clip.
  359. // Audio-level gate: measure level and smooth-ramp watermark to
  360. // prevent audibility during silence/fades.
  361. if g.watermark != nil {
  362. audioLevel := (math.Abs(l) + math.Abs(r)) / 2.0
  363. g.watermark.SetAudioLevel(audioLevel)
  364. wm := g.watermark.NextSample()
  365. l += wm
  366. r += wm
  367. }
  368. // --- Stage 2: Drive + Compress + Clip₁ ---
  369. l *= lp.OutputDrive
  370. r *= lp.OutputDrive
  371. if g.limiter != nil {
  372. l, r = g.limiter.Process(l, r)
  373. }
  374. l = dsp.HardClip(l, ceiling)
  375. r = dsp.HardClip(r, ceiling)
  376. // --- Stage 3: Cleanup LPF + Clip₂ (overshoot compensator) ---
  377. l = g.cleanupLPF_L.Process(l)
  378. r = g.cleanupLPF_R.Process(r)
  379. l = dsp.HardClip(l, ceiling)
  380. r = dsp.HardClip(r, ceiling)
  381. // --- Stage 4: Stereo encode ---
  382. limited := audio.NewFrame(audio.Sample(l), audio.Sample(r))
  383. comps := g.stereoEncoder.Encode(limited)
  384. // --- Stage 5: Composite clip + protection ---
  385. audioMPX := float64(comps.Mono)
  386. if lp.StereoEnabled {
  387. audioMPX += float64(comps.Stereo)
  388. }
  389. if lp.CompositeClipperEnabled && g.compositeClip != nil {
  390. // ITU-R SM.1268 iterative clipper: look-ahead + N×(clip→notch→notch) + final clip
  391. audioMPX = g.compositeClip.Process(audioMPX)
  392. } else {
  393. // Legacy single-pass: one clip, then notch, no final safety clip
  394. audioMPX = dsp.HardClip(audioMPX, ceiling)
  395. audioMPX = g.mpxNotch19.Process(audioMPX)
  396. audioMPX = g.mpxNotch57.Process(audioMPX)
  397. }
  398. // BS.412: apply gain and measure power
  399. if bs412Gain < 1.0 {
  400. audioMPX *= bs412Gain
  401. }
  402. bs412PowerAccum += audioMPX * audioMPX
  403. // --- Stage 6: Add protected components ---
  404. composite := audioMPX
  405. if lp.StereoEnabled {
  406. composite += pilotAmp * comps.Pilot
  407. }
  408. if g.rdsEnc != nil && lp.RDSEnabled {
  409. rdsCarrier := g.stereoEncoder.RDSCarrier()
  410. rdsValue := g.rdsEnc.NextSampleWithCarrier(rdsCarrier)
  411. composite += rdsAmp * rdsValue
  412. }
  413. // Jingle: injected when unlicensed, bypasses drive/gain controls.
  414. if g.licenseState != nil && len(g.jingleFrames) > 0 {
  415. composite += g.licenseState.NextSample(g.jingleFrames)
  416. }
  417. if g.fmMod != nil {
  418. iq_i, iq_q := g.fmMod.Modulate(composite)
  419. frame.Samples[i] = output.IQSample{I: float32(iq_i), Q: float32(iq_q)}
  420. } else {
  421. frame.Samples[i] = output.IQSample{I: float32(composite), Q: 0}
  422. }
  423. }
  424. // BS.412: feed this chunk's actual duration and average audio power for
  425. // the next chunk's gain calculation. Using the real sample count avoids
  426. // the error that occurred when chunkSec was hardcoded to 0.05 — any
  427. // SetChunkDuration() call from the engine would silently miscalibrate
  428. // the ITU-R BS.412 power measurement window.
  429. if g.bs412 != nil && samples > 0 {
  430. chunkSec := float64(samples) / g.sampleRate
  431. g.bs412.UpdateChunkDuration(chunkSec)
  432. g.bs412.ProcessChunk(bs412PowerAccum / float64(samples))
  433. }
  434. return frame
  435. }
  436. func (g *Generator) WriteFile(path string, duration time.Duration) error {
  437. if path == "" {
  438. path = g.cfg.Backend.OutputPath
  439. }
  440. if path == "" {
  441. path = filepath.Join("build", "offline", "composite.iqf32")
  442. }
  443. backend, err := output.NewFileBackend(path, binary.LittleEndian, output.BackendInfo{
  444. Name: "offline-file",
  445. Description: "offline composite file backend",
  446. })
  447. if err != nil {
  448. return err
  449. }
  450. defer backend.Close(context.Background())
  451. if err := backend.Configure(context.Background(), output.BackendConfig{
  452. SampleRateHz: float64(g.cfg.FM.CompositeRateHz),
  453. Channels: 2,
  454. IQLevel: float32(g.cfg.FM.OutputDrive),
  455. }); err != nil {
  456. return err
  457. }
  458. frame := g.GenerateFrame(duration)
  459. if _, err := backend.Write(context.Background(), frame); err != nil {
  460. return err
  461. }
  462. return backend.Flush(context.Background())
  463. }
  464. func (g *Generator) Summary(duration time.Duration) string {
  465. sampleRate := float64(g.cfg.FM.CompositeRateHz)
  466. if sampleRate <= 0 {
  467. sampleRate = 228000
  468. }
  469. _, info := g.sourceFor(sampleRate)
  470. preemph := "off"
  471. if g.cfg.FM.PreEmphasisTauUS > 0 {
  472. preemph = fmt.Sprintf("%.0fµs", g.cfg.FM.PreEmphasisTauUS)
  473. }
  474. modMode := "composite"
  475. if g.cfg.FM.FMModulationEnabled {
  476. modMode = fmt.Sprintf("FM-IQ(±%.0fHz)", g.cfg.FM.MaxDeviationHz)
  477. }
  478. return fmt.Sprintf("offline frame: freq=%.1fMHz rate=%d duration=%s drive=%.2f stereo=%t rds=%t preemph=%s limiter=%t output=%s source=%s detail=%s",
  479. g.cfg.FM.FrequencyMHz, g.cfg.FM.CompositeRateHz, duration.String(),
  480. g.cfg.FM.OutputDrive, g.cfg.FM.StereoEnabled, g.cfg.RDS.Enabled,
  481. preemph, g.cfg.FM.LimiterEnabled, modMode, info.Kind, info.Detail)
  482. }