v1.6.0 release: soundfile format expansion (WAV int depths + RF64 >4GB, AIFF/CAF, AAC/ALAC compressed, 4GB guard, unified AudioFileFormat)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -122,6 +122,7 @@ let jobs: [NRTJob] = mixes.enumerated().map { i, mix in
|
||||
NRTJob(
|
||||
outputURL: outDir.appendingPathComponent("mix_\(i).caf"),
|
||||
duration: 4.0,
|
||||
format: .cafFloat32, // default; use .wavFloat32 / .aiffFloat32 / .wavInt16 / .wavInt24 for interchange
|
||||
blockSize: 512,
|
||||
sampleRate: 48000,
|
||||
numOutputChannels: 2
|
||||
|
||||
@@ -2052,13 +2052,21 @@ let writer = try DiskOut.Audio(
|
||||
channelCount: 2,
|
||||
url: url,
|
||||
sampleRate: engine.sampleRate,
|
||||
format: .wavFloat32, // .aiff / .wavFloat32 / .wavInt16 / .wavInt24 / .aiffFloat32
|
||||
format: .wavFloat32, // .wavFloat32 / .wavInt16 / .wavInt24 / .aiffFloat32 / .cafFloat32 / .rf64Float32 / .rf64Int24
|
||||
bufferFrames: 8192
|
||||
)
|
||||
```
|
||||
|
||||
- Format encoded by `DiskOutFormat` enum (file extension + sample format).
|
||||
- Writes from a background thread; RT pushes to a lock-free SPSC queue.
|
||||
- Format encoded by the `AudioFileFormat` enum (`DiskOutFormat` is an alias) — file extension + sample format.
|
||||
- **PCM / RF64 only**: the compressed codecs (`.aacHigh` / `.aacMedium` / `.alac`) throw `DiskOutError.compressedFormatNotSupported` — real-time streaming of a compressed encoder is out of scope. Render AAC/ALAC offline via `LyrebirdBuffer.write` or `NRTDriver`.
|
||||
- Writes from a background thread; the RT thread publishes into a lock-free ring buffer via atomic frame counters (not an `SPSCQueue`).
|
||||
- **4 GB cap on WAV/AIFF**: a long streaming recording to a WAV or AIFF-C target stops
|
||||
growing once the file reaches the 4 GB container limit (`lyrebirdMaxRIFFBytes`) — a
|
||||
recording already in flight can't retroactively throw, so frames past the cap are
|
||||
**silently dropped** and the audio already written stays valid. Poll `writer.fileTooLarge`
|
||||
after `close()` to detect it. For long sessions record to a 64-bit container:
|
||||
`.cafFloat32`, or `.rf64Float32` / `.rf64Int24` (RF64/BW64 — keeps the `.wav` extension,
|
||||
streamed via `RF64Writer` with the `ds64` sizes patched on `close()`).
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -329,18 +329,36 @@ afconvert -f WAVE -d LEF32 output.caf output.wav
|
||||
### `LyrebirdBuffer.write()` — AIFF, WAV, or CAF
|
||||
|
||||
```swift
|
||||
try buf.write(to: url, format: .caf, sampleRate: 44100) // default
|
||||
try buf.write(to: url, format: .aiff, sampleRate: 44100) // AIFF-C, Float32
|
||||
try buf.write(to: url, format: .wav, sampleRate: 44100) // WAV, Float32
|
||||
try buf.write(to: url, format: .cafFloat32, sampleRate: 44100) // default
|
||||
try buf.write(to: url, format: .aiffFloat32, sampleRate: 44100) // AIFF-C, Float32
|
||||
try buf.write(to: url, format: .wavFloat32, sampleRate: 44100) // WAV, Float32
|
||||
|
||||
// Integer WAV encodings, for smaller files / DAW interchange:
|
||||
try buf.write(to: url, format: .wavInt16, sampleRate: 44100) // WAV, 16-bit PCM
|
||||
try buf.write(to: url, format: .wavInt24, sampleRate: 44100) // WAV, 24-bit PCM
|
||||
```
|
||||
|
||||
| Format | Extension | Endian | Channels | Notes |
|
||||
|---|---|---|---|---|
|
||||
| `.caf` | `.caf` | little-endian | up to 8 | Best for macOS; default |
|
||||
| `.aiff` | `.aiff` | big-endian | ≤ 2 recommended | Broad DAW compatibility |
|
||||
| `.wav` | `.wav` | little-endian | up to 8 | Cross-platform standard |
|
||||
| Format | Extension | Endian | Encoding | Channels | Notes |
|
||||
|---|---|---|---|---|---|
|
||||
| `.cafFloat32` | `.caf` | little-endian | 32-bit float | up to 8 | Best for macOS; default |
|
||||
| `.aiffFloat32` | `.aiff` | big-endian | 32-bit float | ≤ 2 recommended | Broad DAW compatibility |
|
||||
| `.wavFloat32` | `.wav` | little-endian | 32-bit float | up to 8 | Cross-platform standard |
|
||||
| `.wavInt16` | `.wav` | little-endian | 16-bit PCM | up to 8 | Smaller files; lossy quantise |
|
||||
| `.wavInt24` | `.wav` | little-endian | 24-bit PCM | up to 8 | Common DAW interchange depth |
|
||||
| `.rf64Float32` | `.wav` | little-endian | 32-bit float | up to 8 | RF64/BW64 — 64-bit sizes, **no 4 GB cap** |
|
||||
| `.rf64Int24` | `.wav` | little-endian | 24-bit PCM | up to 8 | RF64/BW64 — 64-bit sizes, **no 4 GB cap** |
|
||||
| `.aacHigh` / `.aacMedium` | `.m4a` | — | AAC (lossy) ~256 / ~128 kbps | up to 8 | Compressed. **Offline writers only.** Not sample-accurate. |
|
||||
| `.alac` | `.m4a` | — | Apple Lossless (24-bit source) | up to 8 | Compressed lossless. **Offline writers only.** |
|
||||
|
||||
All formats write 32-bit float samples (Float32). The `Double` (Double) values in the buffer are converted to Float32 on the way out.
|
||||
The buffer's `Double` samples are handed to `ExtAudioFile` as native Float32; the
|
||||
container's on-disk encoding drives the conversion — the Float32 cases are lossless,
|
||||
the integer cases quantise to signed 16/24-bit PCM. (`.caf` / `.aiff` / `.wav` remain
|
||||
as Float32 shorthands for the corresponding `…Float32` cases.)
|
||||
|
||||
The `.rf64*` cases keep the `.wav` extension but use RF64/BW64 (EBU Tech 3306) — 64-bit
|
||||
sizes in a `ds64` chunk — so they are exempt from the 4 GB limit that makes plain
|
||||
`.wav`/`.aiff` throw `fileTooLargeForContainer`. Lyrebird emits RF64 with its own
|
||||
`RF64Writer` (`ExtAudioFile` has no RF64 writer); CoreAudio reads it back.
|
||||
|
||||
---
|
||||
|
||||
@@ -423,6 +441,9 @@ if task.terminationStatus == 0 {
|
||||
| `NRTDriverError.cannotCreateFile` | Bad URL, permissions, or full disk | Check the path and disk space |
|
||||
| `NRTDriverError.writeFailed` | Disk I/O error during render | Check disk space and path permissions |
|
||||
| `LyrebirdBufferIOError.cannotCreateOutputFile` | Same as above for `write()` | |
|
||||
| `NRTDriverError.invalidDuration` | `duration` is negative, NaN, or infinite | Pass a finite, non-negative duration |
|
||||
| `NRTDriverError.fileTooLargeForContainer` | WAV/AIFF render projected past the 4 GB RIFF cap | Use `format: .cafFloat32`, or shorten `duration` |
|
||||
| `LyrebirdBufferIOError.fileTooLargeForContainer` | `LyrebirdBuffer.write` to WAV/AIFF projected past 4 GB | Use `.cafFloat32`, or split/shorten the buffer |
|
||||
| Silent output / all-zeros file | Synthesizers added after `start()` | Move all `engine.add()` calls before `start()` |
|
||||
| File truncated short | `duration` too short for the patch | Increase `NRTDriver` duration |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user