Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:56:01+00:00 2026-05-30T09:56:01+00:00

I have been scratching my head since long now but not getting around to

  • 0

I have been scratching my head since long now but not getting around to this. I haven’t found a single example for Audio editing! I want to insert new Audio file in between somewhere in original Audio file, save it as new converted audio files.

For this I have written following code. I got this idea from here.

NSString *file1 = [[NSBundle mainBundle] pathForResource:@"file1" ofType:@"caf"]; // Using PCM format
NSString *file2 = [[NSBundle mainBundle] pathForResource:@"file2" ofType:@"caf"];

NSData *file1Data = [[NSData alloc] initWithContentsOfFile:file1];
NSData *file2Data = [[NSData alloc] initWithContentsOfFile:file2];

NSMutableData *mergedData =[[NSMutableData alloc] initWithCapacity:([file1Data length] + [file2Data length])];

// First chunk from original sound file 
NSRange firstChunk;
firstChunk.length = startingPosition;
firstChunk.location = 0;
[mergedData appendData:[file1Data subdataWithRange:firstChunk]];

// Add new sound
[mergedData appendData:file2Data];

// First chunk from original sound file 
NSRange secondChunk;
secondChunk.length = [file1Data length] - startingPosition;
secondChunk.location = startingPosition;
[mergedData appendData:[file1Data subdataWithRange:secondChunk]];

NSLog(@"File1: %d, File2: %d, Merged: %d", [file2Data length], [file2Data length],   [mergedData length]);

// Convert mergedData to Audio file
[mergedData writeToFile:[self filePath:@"converted.caf"] atomically:YES];

[file1Data release];
[file2Data release];
[mergedData release];

Using following code to play converted sound file:

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] 
                          initWithContentsOfURL:[NSURL URLWithString:[self filePath:@"converted.caf"]]  error:nil];
[audioPlayer prepareToPlay];
[audioPlayerr play];

The converted file doesn’t play. Further researching on this I found that converting sound to NSData truncates sound header/footer. Is that right? Could anyone please help me to get this sorted out please.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:56:02+00:00Added an answer on May 30, 2026 at 9:56 am

    I think your best bet would be to use an ExtAudioFileRef to extract the audio samples of each file into buffers.

    Then you can freely mix the samples together to and from whatever position you like and save the new mixed file to disk using ExtAudioFileWriteAsync.

    For example:
    Extract sound 1 into buffer A.
    Extract sound 2 into buffer B.

    Create buffer C whose size is A’s length plus B’s length.
    Then write that buffer to disk in whatever format you want using ExtAudioFileWriteAsync.

    That file should then be playable by AVAudioPlayer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been scratching my head all morning behind this but still haven't been
I have been scratching my head since long now to get rid of following
I have been scratching my head on this for a while now but still
I have been scratching my head on this for quite a while now. Guess
Been scratching my head at this one for way too long now... $dom =
I've been scratching my head over this for over a week now and haven't
Well, I have been scratching my head for some time now. But failed to
I've been scratching my head over this for a long time now and searched
I have been scratching my head on this one for some time now and
I have been scratching my head for a while on this one. I dont

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.