Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Misc indentation fixes (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnine committed Mar 27, 2021
1 parent 3de94b0 commit 7ae06d6
Showing 1 changed file with 67 additions and 70 deletions.
137 changes: 67 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,74 +40,72 @@ To install the Swift Package, please follow the steps below:
### Usage

1. Import `SimplyCoreAudio`
```swift
import SimplyCoreAudio
```
```swift
import SimplyCoreAudio
```

2. Instantiate `SimplyCoreAudio`
```swift
let simplyCA = SimplyCoreAudio()
```
```swift
let simplyCA = SimplyCoreAudio()
```

3. Interact with `SimplyCoreAudio`
```swift
// Get the default output device
let device = simplyCA.defaultOutputDevice

// Get preferred output channels
if let stereoPair = device.preferredChannelsForStereo(scope: .output) {
let leftChannel = stereoPair.left
let rightChannel = stereoPair.right
// Use channels...
}

// Get device samplerate
if let sampleRate = device.nominalSampleRate {
// Use samplerate...
}

// Get device virtual master volume
if let outVolume = device.virtualMasterVolume(scope: .output) {
// Use output volume...
}
```
```swift
// Get the default output device
let device = simplyCA.defaultOutputDevice

// Get preferred output channels
if let stereoPair = device.preferredChannelsForStereo(scope: .output) {
let leftChannel = stereoPair.left
let rightChannel = stereoPair.right
// Use channels...
}

// Get device samplerate
if let sampleRate = device.nominalSampleRate {
// Use samplerate...
}

// Get device virtual master volume
if let outVolume = device.virtualMasterVolume(scope: .output) {
// Use output volume...
}
```

4. Subscribe to hardware-related notifications
```swift
// e.g., subscribing to `deviceListChanged` notification.
var observer = NotificationCenter.default.addObserver(
forName: .deviceListChanged,
object: nil,
queue: .main) { (notification) in
// Get added devices.
guard let addedDevices = notification.userInfo?["addedDevices"] as? [AudioDevice] else { return }

// Get removed devices.
guard let removedDevices = notification.userInfo?["removedDevices"] as? [AudioDevice] else { return }
}

// Once done observing, remove observer and nil it.
NotificationCenter.default.removeObserver(observer)
observer = nil
```
```swift
// e.g., subscribing to `deviceListChanged` notification.
var observer = NotificationCenter.default.addObserver(forName: .deviceListChanged,
object: nil,
queue: .main) { (notification) in
// Get added devices.
guard let addedDevices = notification.userInfo?["addedDevices"] as? [AudioDevice] else { return }

// Get removed devices.
guard let removedDevices = notification.userInfo?["removedDevices"] as? [AudioDevice] else { return }
}

// Once done observing, remove observer and nil it.
NotificationCenter.default.removeObserver(observer)
observer = nil
```

5. Subscribe to notifications from a specific audio device
```swift
// Get the default output device
let device = simplyCA.defaultOutputDevice

// e.g., subscribing to `deviceNominalSampleRateDidChange` notification.
var observer = NotificationCenter.default.addObserver(
forName: .deviceNominalSampleRateDidChange,
object: device,
queue: .main) { (notification) in
// Handle notification.
}

// Once done observing, remove observer and nil it.
NotificationCenter.default.removeObserver(observer)
observer = nil
```
```swift
// Get the default output device
let device = simplyCA.defaultOutputDevice

// e.g., subscribing to `deviceNominalSampleRateDidChange` notification.
var observer = NotificationCenter.default.addObserver(forName: .deviceNominalSampleRateDidChange,
object: device,
queue: .main) { (notification) in
// Handle notification.
}

// Once done observing, remove observer and nil it.
NotificationCenter.default.removeObserver(observer)
observer = nil
```

6. Subscribe to notifications from a specific audio stream
```swift
Expand All @@ -119,10 +117,9 @@ To install the Swift Package, please follow the steps below:
guard let stream0 = streams.first else { return }

// e.g., subscribing to `streamPhysicalFormatDidChange` notification.
var observer = NotificationCenter.default.addObserver(
forName: .streamPhysicalFormatDidChange,
object: stream0,
queue: .main) { (notification) in
var observer = NotificationCenter.default.addObserver(forName: .streamPhysicalFormatDidChange,
object: stream0,
queue: .main) { (notification) in
// Handle notification.
}

Expand Down Expand Up @@ -178,14 +175,14 @@ Please make sure to install `NullAudio.driver` before attempting to run tests:
### Installing `NullAudio.driver`

1. Unzip `NullAudio.driver.zip` and install driver into the system HAL Plug-Ins folder
```shell
sudo unzip Tests/Extras/NullAudio.driver.zip -d /Library/Audio/Plug-Ins/HAL
```
```shell
sudo unzip Tests/Extras/NullAudio.driver.zip -d /Library/Audio/Plug-Ins/HAL
```

2. Reload `coreaudiod`
```shell
sudo launchctl kill KILL system/com.apple.audio.coreaudiod
```
```shell
sudo launchctl kill KILL system/com.apple.audio.coreaudiod
```

### Demo Project

Expand Down

0 comments on commit 7ae06d6

Please sign in to comment.