I have a strange problem: I want to generate a new sound file out of two soundfiles and silence.
sound1: 2 seconds long + silence: 2 seconds silence + sound2: 2 seconds long
When I try the code below, I get a 6 seconds long soundfile with all the parts, but in a different order! The order is: sound1, sound2, silence
I am not able to put this silence in the middle of this composition (also not at the beginning). Is this a typical behavior or do I something wrong?
Here is the code for putting the segments together:
[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];
Perhaps someone has an idea? Thank you in advance!
By the way: following code without the insertEmptyTimeRange-line doesn't work either, 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 there is "nothing" between segments!?
Still don't know what this "insertEmptyTimeRange" means. I made a work around with a "silence"-audio file which has nothing in it. I put this empty audio file between the two sound files and this does it for me. Question closed ;) (But if someone could explain this "insertEmptyTimeRange" this would be still interesting...)
I got it working as follows:
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeMake(2,1))
ofTrack:audioTrack
atTime:kCMTimeZero
error:nil];
[compositionAudioTrack insertEmptyTimeRange:CMTimeRangeMake(CMTimeMake(2, 1), CMTimeMake(4, 1))];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeMake(2,1))
ofTrack:audioTrack
atTime:CMTimeMake(4, 1)
error:nil];
The "empty time range" needs to be (2,4) if your sounds are from (0,2) and (4,6).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With