Skip to content

Commit bde8971

Browse files
committed
Cleanup, comments
1 parent 2062983 commit bde8971

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

Sources/SwiftAudioFileConverter/AudioFileConverter/AudioFileConverter+ExtAudioFile.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ extension AudioFileConverter {
190190
nonisolated private static func bitDepthBits(_ bitDepth: BitDepth) -> UInt32 {
191191
switch bitDepth {
192192
case .int16:
193-
return 16
193+
16
194194
case .int24:
195195
// 24-bit is often stored in a 32-bit container, but here we use 24 directly
196-
return 24
196+
24
197197
case .float32:
198-
return 32
198+
32
199199
}
200200
}
201201

Sources/SwiftAudioFileConverter/AudioFileConverter/AudioFileConverter+FLAC.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import FLAC
1010
import Foundation
1111

1212
extension AudioFileConverter {
13+
// TODO: bit-depth is hard-coded at 16-bit
14+
// TODO: add compression level parameter (0 ... 8 where higher numbers are greater compression resulting in smaller file sizes, with 5 as default)
1315
@concurrent nonisolated static func performFlacConversion(
1416
from inputURL: URL,
1517
to outputURL: URL,
@@ -25,7 +27,7 @@ extension AudioFileConverter {
2527
defer { ExtAudioFileDispose(inputFile) }
2628

2729
// 2) Decide on channels from settings
28-
let channels = (settings.channelFormat == .mono) ? UInt32(1) : UInt32(2)
30+
let channels: UInt32 = (settings.channelFormat == .mono) ? 1 : 2
2931

3032
// 3) We want 16-bit interleaved PCM from ExtAudioFile
3133
// because FLAC expects integer samples
@@ -108,7 +110,7 @@ extension AudioFileConverter {
108110
// 6c) Convert frames to FLAC. Because we used interleaved 16-bit PCM,
109111
// we can directly pass the pointer to FLAC’s process_interleaved.
110112

111-
let ok = withUnsafePointer(to: pcmBuffer) { ptr in
113+
let isOK: FLAC__bool = withUnsafePointer(to: pcmBuffer) { ptr in
112114
// FLAC__stream_encoder_process_interleaved expects a pointer to Int32 buffers
113115
// but actually we can pass 16-bit if we cast. We'll do a little trick:
114116
// We'll cast our Int16 pointer to int[] in FLAC's perspective.
@@ -120,25 +122,25 @@ extension AudioFileConverter {
120122
// size_t samples
121123
// );
122124
//
123-
// So we must convert from Int16 to Int32 or pass upcasted data.
125+
// So we must convert from Int16 to Int32 or pass upcast data.
124126
// A quick approach: convert each frame to 32-bit on the fly.
125127
// We'll do that to avoid confusion:
126128

127129
var int32Buffer = [Int32](repeating: 0, count: Int(framesRead * channels))
128130
for i in 0 ..< (Int(framesRead * channels)) {
129-
int32Buffer[i] = Int32(pcmBuffer[i])
131+
int32Buffer[i] = Int32(ptr.pointee[i])
130132
}
131-
133+
132134
return int32Buffer.withUnsafeBufferPointer { bp -> FLAC__bool in
133135
FLAC__stream_encoder_process_interleaved(
134136
flacEncoder,
135-
bp.baseAddress, // pointer to the 32-bit array
137+
bp.baseAddress, // pointer to the 32-bit array
136138
FLAC__uint32(framesRead)
137139
)
138140
}
139141
}
140142

141-
if ok == 0 {
143+
if isOK == 0 {
142144
throw ConverterError.flacConversionUnknownError
143145
}
144146
}

Sources/SwiftAudioFileConverter/AudioFileConverter/AudioFileConverter.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public enum AudioFileConverter {
4040

4141
// Dispatch the conversion based on the requested format
4242
switch settings.fileFormat {
43-
4443
case .wav, .aiff, .aac, .alac:
4544
// ExtAudioFile supports these.
4645
try await performExtAudioFileConversion(from: inputURL, to: outputURL, settings: settings)

0 commit comments

Comments
 (0)