Skip to content

Commit 1ea1d39

Browse files
committed
Refactored channel count determination to new ChannelFormat channelCount property
1 parent bde8971 commit 1ea1d39

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

Sources/SwiftAudioFileConverter/AudioFileConverter/AudioFileConverter+ExtAudioFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension AudioFileConverter {
4747

4848
// 4. We’ll set a “client format” to read and write in a consistent format (e.g., float32 PCM).
4949
// Even for compressed output like AAC, we often use a PCM client format for reading/writing.
50-
let channels = (settings.channelFormat == .mono) ? UInt32(1) : UInt32(2)
50+
let channels = UInt32(settings.channelFormat.channelCount)
5151

5252
var clientFormat = AudioStreamBasicDescription(
5353
mSampleRate: settings.sampleRate.hzDouble,
@@ -125,7 +125,7 @@ extension AudioFileConverter {
125125
nonisolated private static func audioFormat(
126126
for settings: Settings
127127
) throws -> (AudioStreamBasicDescription, AudioFileTypeID) {
128-
let channels = (settings.channelFormat == .mono) ? UInt32(1) : UInt32(2)
128+
let channels = UInt32(settings.channelFormat.channelCount)
129129

130130
// Base description; we’ll adjust for each format
131131
var asbd = AudioStreamBasicDescription()

Sources/SwiftAudioFileConverter/AudioFileConverter/AudioFileConverter+FLAC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension AudioFileConverter {
2727
defer { ExtAudioFileDispose(inputFile) }
2828

2929
// 2) Decide on channels from settings
30-
let channels: UInt32 = (settings.channelFormat == .mono) ? 1 : 2
30+
let channels = UInt32(settings.channelFormat.channelCount)
3131

3232
// 3) We want 16-bit interleaved PCM from ExtAudioFile
3333
// because FLAC expects integer samples

Sources/SwiftAudioFileConverter/AudioFileConverter/AudioFileConverter+LAME.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension AudioFileConverter {
2727
}
2828

2929
// 2) Determine the number of channels from AudioFileSettings
30-
let channels = (settings.channelFormat == .mono) ? UInt32(1) : UInt32(2)
30+
let channels = UInt32(settings.channelFormat.channelCount)
3131

3232
// 3) We want 32-bit float interleaved PCM for reading from ExtAudioFile
3333
// Build a client format describing float PCM.

Sources/SwiftAudioFileConverter/AudioFileConverter/Settings/ChannelFormat.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ extension AudioFileConverter.ChannelFormat: CustomStringConvertible {
3232
}
3333
}
3434
}
35+
36+
// MARK: - Properties
37+
38+
extension AudioFileConverter.ChannelFormat {
39+
public var channelCount: Int {
40+
switch self {
41+
case .mono:
42+
1
43+
case .stereo:
44+
2
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)