forked from AudioKit/AudioKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'AudioKit:main' into main
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Tests/AudioKitTests/Extension Tests/AVAudioPCMBufferMixToMonoTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import AudioKit | ||
import AVFoundation | ||
import Foundation | ||
import XCTest | ||
|
||
class AVAudioPCMBufferMixToMonoTests: XCTestCase { | ||
let sampleRate: Double = 44100 | ||
lazy var capacity = 10 * UInt32(sampleRate) | ||
lazy var format = AVAudioFormat(standardFormatWithSampleRate: sampleRate, channels: 2)! | ||
lazy var buffer = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: capacity)! | ||
lazy var data = buffer.floatChannelData! | ||
|
||
func testMixToMonoCancellation() { | ||
for index in 0..<capacity { | ||
data[0][Int(index)] = -1 | ||
data[1][Int(index)] = 1 | ||
} | ||
buffer.frameLength = capacity | ||
|
||
let mono = buffer.mixToMono() | ||
|
||
XCTAssertEqual(mono.format.channelCount, 1) | ||
XCTAssertEqual(mono.frameCapacity, capacity) | ||
XCTAssertEqual(mono.frameLength, capacity) | ||
|
||
XCTAssertTrue(mono.toFloatChannelData()![0].allSatisfy { $0 == 0 }) | ||
} | ||
|
||
func testMixToMonoDouble() { | ||
for index in 0..<capacity { | ||
data[0][Int(index)] = 1 | ||
data[1][Int(index)] = 1 | ||
} | ||
buffer.frameLength = capacity | ||
|
||
let mono = buffer.mixToMono() | ||
|
||
XCTAssertEqual(mono.format.channelCount, 1) | ||
XCTAssertEqual(mono.frameCapacity, capacity) | ||
XCTAssertEqual(mono.frameLength, capacity) | ||
|
||
XCTAssertTrue(mono.toFloatChannelData()![0].allSatisfy { $0 == 2 }) | ||
} | ||
} |