@@ -10,6 +10,8 @@ import FLAC
1010import Foundation
1111
1212extension 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 }
0 commit comments