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:
@@ -250,12 +250,44 @@ 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)
|
||||
try buf.write(to: url, format: .aiff, sampleRate: 44100)
|
||||
try buf.write(to: url, format: .wav, sampleRate: 44100)
|
||||
try buf.write(to: url, format: .cafFloat32, sampleRate: 44100)
|
||||
try buf.write(to: url, format: .aiffFloat32, sampleRate: 44100)
|
||||
try buf.write(to: url, format: .wavFloat32, sampleRate: 44100)
|
||||
|
||||
// Integer WAV encodings, for smaller files / DAW interchange:
|
||||
try buf.write(to: url, format: .wavInt16, sampleRate: 44100)
|
||||
try buf.write(to: url, format: .wavInt24, sampleRate: 44100)
|
||||
|
||||
// RF64 / BW64 — WAV extension, 64-bit sizes, no 4 GB cap:
|
||||
try buf.write(to: url, format: .rf64Float32, sampleRate: 44100)
|
||||
try buf.write(to: url, format: .rf64Int24, sampleRate: 44100)
|
||||
|
||||
// Compressed M4A (offline writers only — LyrebirdBuffer.write / NRTDriver):
|
||||
try buf.write(to: url, format: .aacHigh, sampleRate: 44100) // AAC ~256 kbps (lossy)
|
||||
try buf.write(to: url, format: .aacMedium, sampleRate: 44100) // AAC ~128 kbps (lossy)
|
||||
try buf.write(to: url, format: .alac, sampleRate: 44100) // Apple Lossless
|
||||
```
|
||||
|
||||
All formats write 32-bit float (Float32). `Double` (Double) values are downcast 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 `.cafFloat32` /
|
||||
`.aiffFloat32` / `.wavFloat32` cases are lossless 32-bit float; `.wavInt16` /
|
||||
`.wavInt24` quantise to signed 16/24-bit PCM. (`.caf` / `.aiff` / `.wav` remain
|
||||
as Float32 shorthands.)
|
||||
|
||||
**Files past 4 GB**: plain `.wav`/`.aiff` are limited to 4 GB (32-bit size fields) and
|
||||
throw `fileTooLargeForContainer` past that. For a big file that must keep the `.wav`
|
||||
extension, use `.rf64Float32` / `.rf64Int24` — RF64/BW64 (EBU Tech 3306) carries 64-bit
|
||||
sizes in a `ds64` chunk (written by Lyrebird's own ``RF64Writer``; CoreAudio reads it
|
||||
back). `.cafFloat32` is the other uncapped option.
|
||||
|
||||
**Compressed output** (`.aacHigh` / `.aacMedium` / `.alac`): AAC and Apple Lossless in an
|
||||
`.m4a` container, encoded by `ExtAudioFile`/`AudioConverter`. **Offline writers only** —
|
||||
`LyrebirdBuffer.write` and `NRTDriver`; ``DiskOut/Audio`` throws `compressedFormatNotSupported`
|
||||
(real-time streaming of a compressed encoder is out of scope). AAC is lossy and **not
|
||||
sample-accurate** (encoder priming/padding shifts the signal a few ms), so frame-count
|
||||
round-trips aren't exact; ALAC is lossless of a 24-bit-quantised source. Introspect a
|
||||
format with ``AudioFileFormat/isCompressed`` (true for these three) and, for AAC, its
|
||||
target rate via ``AudioFileFormat/aacBitrate``.
|
||||
|
||||
## Complete Example — NRT Bounce to AIFF
|
||||
|
||||
@@ -316,6 +348,9 @@ do {
|
||||
| `NRTDriverError.cannotOpenInputFile` | `inputURL` not found or unreadable | Verify the file path exists |
|
||||
| `NRTDriverError.cannotSeekInputFile` | `inputStartOffset` beyond file end | Reduce `inputStartOffset` |
|
||||
| `NRTDriverError.inputReadFailed` | Disk I/O error reading input file | Check disk health |
|
||||
| `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()` before `start()` |
|
||||
| File truncated short | `duration` too short | Increase `NRTDriver` duration |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user