Skip to content

Commit

Permalink
all: reformat with swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ydnar committed Jun 15, 2024
1 parent 3d4d1b2 commit 5c21ef4
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ let package = Package(

.define("OPUS_BUILD"),
.define("VAR_ARRAYS", to: "1"),
.define("FLOATING_POINT"), // Enable Opus floating-point mode
.define("FLOATING_POINT"), // Enable Opus floating-point mode

.define("HAVE_DLFCN_H", to: "1"),
.define("HAVE_INTTYPES_H", to: "1"),
Expand Down
8 changes: 4 additions & 4 deletions Sources/Opus/AVAudioFormat+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import AVFoundation

public extension AVAudioFormat {
enum OpusPCMFormat {
extension AVAudioFormat {
public enum OpusPCMFormat {
case int16
case float32
}

convenience init?(opusPCMFormat: OpusPCMFormat, sampleRate: Double, channels: AVAudioChannelCount) {
public convenience init?(opusPCMFormat: OpusPCMFormat, sampleRate: Double, channels: AVAudioChannelCount) {
switch opusPCMFormat {
case .int16:
self.init(commonFormat: .pcmFormatInt16, sampleRate: sampleRate, channels: channels, interleaved: channels != 1)
Expand All @@ -18,7 +18,7 @@ public extension AVAudioFormat {
}
}

var isValidOpusPCMFormat: Bool {
public var isValidOpusPCMFormat: Bool {
switch sampleRate {
case .opus8khz, .opus12khz, .opus16khz, .opus24khz, .opus48khz:
break
Expand Down
6 changes: 3 additions & 3 deletions Sources/Opus/AVAudioFrameCount+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import AVFoundation

public extension AVAudioFrameCount {
extension AVAudioFrameCount {
// Opus can encode packets as small as 2.5ms at 8khz (20 samples)
static let opusMin: Self = 20
public static let opusMin: Self = 20

// Opus can encode packets as large as to 120ms at 48khz (5760 samples)
static let opusMax: Self = 5760
public static let opusMax: Self = 5760
}
12 changes: 6 additions & 6 deletions Sources/Opus/Double+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public extension Double {
static let opus8khz: Self = 8000
static let opus12khz: Self = 12000
static let opus16khz: Self = 16000
static let opus24khz: Self = 24000
static let opus48khz: Self = 48000
extension Double {
public static let opus8khz: Self = 8000
public static let opus12khz: Self = 12000
public static let opus16khz: Self = 16000
public static let opus24khz: Self = 24000
public static let opus48khz: Self = 48000
}
4 changes: 2 additions & 2 deletions Sources/Opus/Opus.Application.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public extension Opus {
struct Application: Equatable, RawRepresentable, ExpressibleByIntegerLiteral {
extension Opus {
public struct Application: Equatable, RawRepresentable, ExpressibleByIntegerLiteral {
public typealias IntegerLiteralType = Int32
public var rawValue: IntegerLiteralType

Expand Down
10 changes: 5 additions & 5 deletions Sources/Opus/Opus.Decoder.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import AVFoundation
import Copus

public extension Opus {
class Decoder {
extension Opus {
public class Decoder {
let format: AVAudioFormat
let decoder: OpaquePointer

Expand Down Expand Up @@ -37,8 +37,8 @@ public extension Opus {

// MARK: Public decode methods

public extension Opus.Decoder {
func decode(_ input: Data) throws -> AVAudioPCMBuffer {
extension Opus.Decoder {
public func decode(_ input: Data) throws -> AVAudioPCMBuffer {
try input.withUnsafeBytes {
let input = $0.bindMemory(to: UInt8.self)
let sampleCount = opus_decoder_get_nb_samples(decoder, input.baseAddress!, Int32($0.count))
Expand All @@ -51,7 +51,7 @@ public extension Opus.Decoder {
}
}

func decode(_ input: UnsafeBufferPointer<UInt8>, to output: AVAudioPCMBuffer) throws {
public func decode(_ input: UnsafeBufferPointer<UInt8>, to output: AVAudioPCMBuffer) throws {
let decodedCount: Int
switch output.format.commonFormat {
case .pcmFormatInt16:
Expand Down
14 changes: 7 additions & 7 deletions Sources/Opus/Opus.Encoder.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import AVFoundation
import Copus

public extension Opus {
class Encoder {
extension Opus {
public class Encoder {
let format: AVAudioFormat
let application: Application
let encoder: OpaquePointer
Expand Down Expand Up @@ -39,26 +39,26 @@ public extension Opus {

// MARK: Public encode methods

public extension Opus.Encoder {
func encode(_ input: AVAudioPCMBuffer, to output: inout Data) throws -> Int {
extension Opus.Encoder {
public func encode(_ input: AVAudioPCMBuffer, to output: inout Data) throws -> Int {
output.count = try output.withUnsafeMutableBytes {
try encode(input, to: $0)
}
return output.count
}

func encode(_ input: AVAudioPCMBuffer, to output: inout [UInt8]) throws -> Int {
public func encode(_ input: AVAudioPCMBuffer, to output: inout [UInt8]) throws -> Int {
try output.withUnsafeMutableBufferPointer {
try encode(input, to: $0)
}
}

func encode(_ input: AVAudioPCMBuffer, to output: UnsafeMutableRawBufferPointer) throws -> Int {
public func encode(_ input: AVAudioPCMBuffer, to output: UnsafeMutableRawBufferPointer) throws -> Int {
let output = UnsafeMutableBufferPointer(start: output.baseAddress!.bindMemory(to: UInt8.self, capacity: output.count), count: output.count)
return try encode(input, to: output)
}

func encode(_ input: AVAudioPCMBuffer, to output: UnsafeMutableBufferPointer<UInt8>) throws -> Int {
public func encode(_ input: AVAudioPCMBuffer, to output: UnsafeMutableBufferPointer<UInt8>) throws -> Int {
guard input.format.sampleRate == format.sampleRate, input.format.channelCount == format.channelCount else {
throw Opus.Error.badArgument
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Opus/Opus.Error.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public extension Opus {
struct Error: Swift.Error, Equatable, RawRepresentable, ExpressibleByIntegerLiteral {
extension Opus {
public struct Error: Swift.Error, Equatable, RawRepresentable, ExpressibleByIntegerLiteral {
public typealias IntegerLiteralType = Int32
public var rawValue: IntegerLiteralType

Expand Down
3 changes: 1 addition & 2 deletions Sources/Opus/Opus.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import AVFoundation
import CoreAudio

@_exported import Copus
import CoreAudio

public enum Opus: CaseIterable {}
2 changes: 1 addition & 1 deletion Tests/OpusTests/OpusRoundTripTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class OpusRoundTripTests: XCTestCase {
func testSilence() throws {
let format = AVAudioFormat(opusPCMFormat: .float32, sampleRate: .opus48khz, channels: 1)!
let input = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: .opusMax)!
input.frameLength = input.frameCapacity // Silence
input.frameLength = input.frameCapacity // Silence
_ = try encodeAndDecode(input)
}

Expand Down

0 comments on commit 5c21ef4

Please sign in to comment.