I
I
ivangt2017-03-22 10:20:09
Swift
ivangt, 2017-03-22 10:20:09

How to mix left and right channel in Swift3?

I am writing a mobile application. How to do this in Xcode Swift3?
Track-A(stereo) -> Track-A(mono) -> Left channel of Track-C
Track-B(stereo) -> Track-B(mono) -> Right channel of Track-C
And finally save Track-C as separate mix. There is a code that adds Stereo tracks to the composition, but how can I change it for my case?

let composition = AVMutableComposition()
let composition.addAudioTrack1 = composition.addMutableTrack(withMediaType: AVMediaTypeAudio, preferredTrackID: kCMPersistentTrackID_Invalid)
let avAsset1 = AVURLAsset.init(url: url1, options: nil)
let audioTrack1 = avAsset1.tracks(withMediaType: AVMediaTypeAudio)[0]
do {
try compositionAudioTrack1.insertTimeRange(CMTimeRangeMake(kCMTimeZero, avAsset1.duration), of: audioTrack1, at: kCMTimeZero)
} catch {
}

You can set the volume
audioTrack1.preferredVolume = 1

How about doing something like:
audioTrack1.pan=-1

I would appreciate any help, thanks!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question