Skip to content

Commit

Permalink
configuration refactoring
Browse files Browse the repository at this point in the history
- indent fix
- comment to english
  • Loading branch information
huiping192 committed Sep 12, 2023
1 parent 0bb282d commit d58ce5c
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 248 deletions.
138 changes: 69 additions & 69 deletions Sources/HPLiveKit/Configuration/LiveAudioConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,84 @@

import Foundation

// 音频码率
// Audio Bitrate
public enum LiveAudioBitRate: Int {
/// 32Kbps 音频码率
case a32Kbps = 32000
/// 64Kbps 音频码率
case a64Kbps = 64000
/// 96Kbps 音频码率
case a96Kbps = 96000
/// 128Kbps 音频码率
case a128Kbps = 128000
/// 32Kbps audio bitrate
case a32Kbps = 32000
/// 64Kbps audio bitrate
case a64Kbps = 64000
/// 96Kbps audio bitrate
case a96Kbps = 96000
/// 128Kbps audio bitrate
case a128Kbps = 128000
}

///// 音频采样率
// Audio Sample Rate
public enum LiveAudioSampleRate: Int {
/// 16KHz 采样率
case s16000Hz = 16000
/// 44.1KHz 采样率
case s44100Hz = 44100
/// 48KHz 采样率
case s48000Hz = 48000

var sampleRateIndex: UInt8 {
var sampleRateIndex: UInt8 = 0
switch self.rawValue {
case 96000:
sampleRateIndex = 0
case 88200:
sampleRateIndex = 1
case 64000:
sampleRateIndex = 2
case 48000:
sampleRateIndex = 3
case 44100:
sampleRateIndex = 4
case 32000:
sampleRateIndex = 5
case 24000:
sampleRateIndex = 6
case 22050:
sampleRateIndex = 7
case 16000:
sampleRateIndex = 8
case 12000:
sampleRateIndex = 9
case 11025:
sampleRateIndex = 10
case 8000:
sampleRateIndex = 11
case 7350:
sampleRateIndex = 12
default:
sampleRateIndex = 15
}

return sampleRateIndex
/// 16KHz sample rate
case s16000Hz = 16000
/// 44.1KHz sample rate
case s44100Hz = 44100
/// 48KHz sample rate
case s48000Hz = 48000

var sampleRateIndex: UInt8 {
var sampleRateIndex: UInt8 = 0
switch self.rawValue {
case 96000:
sampleRateIndex = 0
case 88200:
sampleRateIndex = 1
case 64000:
sampleRateIndex = 2
case 48000:
sampleRateIndex = 3
case 44100:
sampleRateIndex = 4
case 32000:
sampleRateIndex = 5
case 24000:
sampleRateIndex = 6
case 22050:
sampleRateIndex = 7
case 16000:
sampleRateIndex = 8
case 12000:
sampleRateIndex = 9
case 11025:
sampleRateIndex = 10
case 8000:
sampleRateIndex = 11
case 7350:
sampleRateIndex = 12
default:
sampleRateIndex = 15
}

return sampleRateIndex
}
}

public enum LiveAudioQuality {
/// 低音频质量 audio sample rate: 16KHz audio bitrate: numberOfChannels 1 : 32Kbps 2 : 64Kbps
case low
/// 中音频质量 audio sample rate: 44.1KHz audio bitrate: 96Kbps
case medium
/// 高音频质量 audio sample rate: 44.1MHz audio bitrate: 128Kbps
case high
/// 超高音频质量 audio sample rate: 48KHz, audio bitrate: 128Kbps
case veryHigh
/// Low audio quality: audio sample rate 16KHz, audio bitrate: numberOfChannels 1 : 32Kbps 2 : 64Kbps
case low
/// Medium audio quality: audio sample rate 44.1KHz, audio bitrate 96Kbps
case medium
/// High audio quality: audio sample rate 44.1MHz, audio bitrate 128Kbps
case high
/// Very high audio quality: audio sample rate 48KHz, audio bitrate 128Kbps
case veryHigh
}

public struct LiveAudioConfiguration {
/// 声道数目
let numberOfChannels: UInt32
/// 采样率
let audioSampleRate: LiveAudioSampleRate
/// 码率
let audioBitRate: LiveAudioBitRate
/// 缓存区长度
var bufferLength: Int {
1024 * 1 * Int(self.numberOfChannels)
}
/// Number of channels
let numberOfChannels: UInt32
/// Sample rate
let audioSampleRate: LiveAudioSampleRate
/// Bitrate
let audioBitRate: LiveAudioBitRate
/// Buffer length
var bufferLength: Int {
return 1024 * 1 * Int(self.numberOfChannels)
}
}
38 changes: 19 additions & 19 deletions Sources/HPLiveKit/Configuration/LiveAudioConfigurationFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
import Foundation

public struct LiveAudioConfigurationFactory {
public static var defaultAudioConfiguration: LiveAudioConfiguration {
return createHigh()
}

public static func createLow() -> LiveAudioConfiguration {
return LiveAudioConfiguration(numberOfChannels: 2, audioSampleRate: .s16000Hz, audioBitRate: .a64Kbps)
}

public static func createMedium() -> LiveAudioConfiguration {
return LiveAudioConfiguration(numberOfChannels: 2, audioSampleRate: .s44100Hz, audioBitRate: .a96Kbps)
}

public static func createHigh() -> LiveAudioConfiguration {
return LiveAudioConfiguration(numberOfChannels: 2, audioSampleRate: .s44100Hz, audioBitRate: .a128Kbps)
}

public static func createVeryHigh() -> LiveAudioConfiguration {
return LiveAudioConfiguration(numberOfChannels: 2, audioSampleRate: .s48000Hz, audioBitRate: .a128Kbps)
}
public static var defaultAudioConfiguration: LiveAudioConfiguration {
return createHigh()
}
public static func createLow() -> LiveAudioConfiguration {
return LiveAudioConfiguration(numberOfChannels: 2, audioSampleRate: .s16000Hz, audioBitRate: .a64Kbps)
}
public static func createMedium() -> LiveAudioConfiguration {
return LiveAudioConfiguration(numberOfChannels: 2, audioSampleRate: .s44100Hz, audioBitRate: .a96Kbps)
}
public static func createHigh() -> LiveAudioConfiguration {
return LiveAudioConfiguration(numberOfChannels: 2, audioSampleRate: .s44100Hz, audioBitRate: .a128Kbps)
}
public static func createVeryHigh() -> LiveAudioConfiguration {
return LiveAudioConfiguration(numberOfChannels: 2, audioSampleRate: .s48000Hz, audioBitRate: .a128Kbps)
}
}
Loading

0 comments on commit d58ce5c

Please sign in to comment.