I have a strange problem: I want to create a new sound file from two sound files and silence.
sound1: 2 seconds + silence: silence in 2 seconds + sound2: 2 seconds
When I try the code below, I get a sound file lasting 6 seconds with all parts, but in a different order! Order: sound1, sound2, silence
I can’t put this silence in the middle of this composition (also not at the beginning). Is this typical behavior or am I doing something wrong?
Here is the code for merging segments:
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [audio1 duration]) ofTrack:clipAudioTrack1 atTime:kCMTimeZero error:nil];
[compositionAudioTrack insertEmptyTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeMake(2, 1))];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [audio2 duration]) ofTrack:clipAudioTrack2 atTime:CMTimeMake(4, 1) error:nil];
Maybe someone has an idea? Thank you in advance!
By the way: the following code without insertEmptyTimeRange-line also does not work, it just generates 4 seconds of sound and sound2 slides to the end of sound1:
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [audio1 duration]) ofTrack:clipAudioTrack1 atTime:kCMTimeZero error:nil];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [audio2 duration]) ofTrack:clipAudioTrack2 atTime:CMTimeMake(4, 1) error:nil];
It seems that it is not allowed that between the segments there is “nothing” ??