Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-23-2009, 02:55 PM   #1 (permalink)
New Member
 
Nitrex88's Avatar
 
Join Date: Apr 2008
Location: Long Island, NY
Age: 21
Posts: 84
Send a message via AIM to Nitrex88 Send a message via Skype™ to Nitrex88
Default Combining Audio Files...Possible?

I'm looking for a way to combine separate audio files in one audio file. The starting separate files i can have are WAV or CAF (doesnt matter to me) and I would like to stitch them together into one file such as MIDI or anything other file type thats possible. I'm not sure if this is possible on iPhone but I would be able to make a mac desktop application to export to if needed to do the stitching together there. So pretty much what I'm asking is does anybody know of a not too complex (but share anyway even if insanely complex) way on iPhone OR OS X to combine separate audio files into one file. Thanks!


Nick
Nitrex88 is offline   Reply With Quote
Old 06-23-2009, 04:00 PM   #2 (permalink)
ftm
FasterThanMonkeys.com
 
Join Date: Mar 2009
Location: Southern California
Posts: 523
Send a message via AIM to ftm
Default

There is a great audio editor that is free and is compatible with several platforms (Mac, Windows, Linux). It is called Audacity, and can be found here:

Audacity: Free Audio Editor and Recorder

It can do what you are asking, and a lot more.
__________________


Website: http://fasterthanmonkeys.com

iScore Baseball Scorekeeper Top baseball scorekeeping app for iPhone
Bug Squash Reached #1 kids game in 15+ countries including USA, now with OpenFeint
Jam Packed! Fun puzzle game for all ages
Jam Packed Christmas Holiday puzzle game!
iScore Basketball Scorekeeper Best basketball scorekeeping application
ftm is offline   Reply With Quote
Old 06-23-2009, 04:04 PM   #3 (permalink)
New Member
 
Nitrex88's Avatar
 
Join Date: Apr 2008
Location: Long Island, NY
Age: 21
Posts: 84
Send a message via AIM to Nitrex88 Send a message via Skype™ to Nitrex88
Default

Oh thanks for your help but I guess i didnt convey that I need to do this programmatically in my own app I am creating. I need a framework or some classes that can combine audio files. I need to create my own app that can combine audio files, not use one that already exists.
Nitrex88 is offline   Reply With Quote
Old 06-23-2009, 04:14 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,544
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

Nitrex... havent seen you around here in a while... how's things been?

Anyways, I don't know about combining audio files of different types, but for same type audio files, same compression, same everything:

Could you just read in file1 using NSFileHandle's readData, write it out to another file, do the same for file2, just append it to the end of file 1. The only thing you need to determine is how many bytes are at the front of file2 that you can skip because they have unneeded file information that's not part of the audio.
smithdale87 is offline   Reply With Quote
Old 06-23-2009, 04:18 PM   #5 (permalink)
ftm
FasterThanMonkeys.com
 
Join Date: Mar 2009
Location: Southern California
Posts: 523
Send a message via AIM to ftm
Default

Ah... since you asked about OS X, I assumed you were just looking for a tool, not necessarily code.

I have seen some threads about using ffmpeg on the iphone. ffmpeg is generally used for Video, but works with audio as well. You might try searching on using ffmpeg on the iphone as the source code for that is freely available as well.
__________________


Website: http://fasterthanmonkeys.com

iScore Baseball Scorekeeper Top baseball scorekeeping app for iPhone
Bug Squash Reached #1 kids game in 15+ countries including USA, now with OpenFeint
Jam Packed! Fun puzzle game for all ages
Jam Packed Christmas Holiday puzzle game!
iScore Basketball Scorekeeper Best basketball scorekeeping application
ftm is offline   Reply With Quote
Old 06-23-2009, 04:19 PM   #6 (permalink)
New Member
 
Nitrex88's Avatar
 
Join Date: Apr 2008
Location: Long Island, NY
Age: 21
Posts: 84
Send a message via AIM to Nitrex88 Send a message via Skype™ to Nitrex88
Default

Quote:
Originally Posted by smithdale87 View Post
Nitrex... havent seen you around here in a while... how's things been?

Anyways, I don't know about combining audio files of different types, but for same type audio files, same compression, same everything:

Could you just read in file1 using NSFileHandle's readData, write it out to another file, do the same for file2, just append it to the end of file 1. The only thing you need to determine is how many bytes are at the front of file2 that you can skip because they have unneeded file information that's not part of the audio.
Yea i figured it was something like that except I don't know how to do that. Any advice on how you would go about it such as a class reference to look at or some methods you would be using. By the way all files would be of the same type, i just meant if WAV was not supported I can change all my files to CAF.

Thanks for the help.

Nick
Nitrex88 is offline   Reply With Quote
Old 06-23-2009, 04:22 PM   #7 (permalink)
New Member
 
Nitrex88's Avatar
 
Join Date: Apr 2008
Location: Long Island, NY
Age: 21
Posts: 84
Send a message via AIM to Nitrex88 Send a message via Skype™ to Nitrex88
Default

Quote:
Originally Posted by ftm View Post
Ah... since you asked about OS X, I assumed you were just looking for a tool, not necessarily code.

I have seen some threads about using ffmpeg on the iphone. ffmpeg is generally used for Video, but works with audio as well. You might try searching on using ffmpeg on the iphone as the source code for that is freely available as well.
Thanks for the info ill check that out. By asking about OS X i meant if there was no such technology on the iPhone I could make an OS X desktop application to handle this code and export data from the iPhone app to it.

Nick
Nitrex88 is offline   Reply With Quote
Old 06-23-2009, 04:56 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,544
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

This should get you on the right track. Mix and match pseudo code

Code:
-(void) concatFiles( NSString* path1, NSString* path2, NSString* combinedPath )
{
 NSFileHandle * f1Handle = [NSFileHandle fileHandleForReadingAtPath: path1];
 NSFileHandle *f2Handle = [NSFileHandle fielHandleForReadingAtPath: path2];

//might need to check if file exists first, if not create it using NSFileManager's createFileAtPath

 NSFileHandle * combinedHandle = [NSFileHandle fileHandleForWritingAtPath: combinedPath];



   // read data in small chunks to avoid hogging memory. 
   NSData* read  = [f1Handle readDataOfLength: CHUNK_SIZE] ;
      
    while( length of read != 0 )   

   {
       [combineHandle writeData: read];
       read = [f1Handle readDataOfLength: CHUNK_SIZE] ;
   }


   [f1Handle close];
   

    //now do the same for f2Handle

    //might need to ignore a few bytes in the front of file2 that isnt audio
    [f2Handle readDataOfLength: HEADER_LENGTH];


     NSData* read  = [f2Handle readDataOfLength: CHUNK_SIZE] ;
     while (... )
    {
    }
     [f2Handle close];
     [combineHandle close];
  
}
smithdale87 is offline   Reply With Quote
Old 06-23-2009, 08:14 PM   #9 (permalink)
New Member
 
Nitrex88's Avatar
 
Join Date: Apr 2008
Location: Long Island, NY
Age: 21
Posts: 84
Send a message via AIM to Nitrex88 Send a message via Skype™ to Nitrex88
Default

Quote:
Originally Posted by smithdale87 View Post
This should get you on the right track. Mix and match pseudo code

Code:
-(void) concatFiles( NSString* path1, NSString* path2, NSString* combinedPath )
{
 NSFileHandle * f1Handle = [NSFileHandle fileHandleForReadingAtPath: path1];
 NSFileHandle *f2Handle = [NSFileHandle fielHandleForReadingAtPath: path2];

//might need to check if file exists first, if not create it using NSFileManager's createFileAtPath

 NSFileHandle * combinedHandle = [NSFileHandle fileHandleForWritingAtPath: combinedPath];



   // read data in small chunks to avoid hogging memory. 
   NSData* read  = [f1Handle readDataOfLength: CHUNK_SIZE] ;
      
    while( length of read != 0 )   

   {
       [combineHandle writeData: read];
       read = [f1Handle readDataOfLength: CHUNK_SIZE] ;
   }


   [f1Handle close];
   

    //now do the same for f2Handle

    //might need to ignore a few bytes in the front of file2 that isnt audio
    [f2Handle readDataOfLength: HEADER_LENGTH];


     NSData* read  = [f2Handle readDataOfLength: CHUNK_SIZE] ;
     while (... )
    {
    }
     [f2Handle close];
     [combineHandle close];
  
}
Wow thank you so much that will probably do it. That is so awesome! I haven't done anything with the NSFileHandle yet so I didn't know about it and it's methods. What do you recommend for the values of CHUNK_SIZE and HEADER_LENGTH?

Also in reference to me not being here for a while I have been very busy making tons of apps for the app store with various companies. I am also involved with the creation of highly developed new tutorial website that will be ready soon. Also busy finishing high school =P.

Nick
Nitrex88 is offline   Reply With Quote
Old 08-26-2009, 09:21 PM   #10 (permalink)
Registered Member
 
934texas's Avatar
 
Join Date: Jan 2009
Location: Brooklyn, NY
Posts: 19
Send a message via AIM to 934texas
Default

Very interesting. Hypothetically, if one file were video and one were audio, and both were mp4, do you think this would work?
934texas is offline   Reply With Quote
Old 04-05-2010, 03:16 PM   #11 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 1
Default Help With Pseudo Code

Just wondering if anyone has implemented the code shown above. Below is the code I've got working so far. I'm guessing I got the HEADER_LENGTH right (anything less creates a file Quicktime can't play). My problem with the code below is that the file at combinedPath seems to only have the data for the first file. Is there a footer in audio files that has to be removed from the first file (similar to how we ignore the header of the second)? When debugging it runs through the second while loop several times so I think it's writing to the combined path but for some reason QuickTime thinks the file ends after the duration of the first audio.

[EDIT: After digging around the interwebs some more I think the problem is that the header info for the first file includes a duration property which is telling QuickTime the length of File 1. If anyone has any advice on how to override the header with the length of both files combined I think that would solve my problem]

Code:
#define CHUNK_SIZE 1000
#define HEADER_LENGTH 251

-(void) concatFiles:(NSString*) path1 And: (NSString*) path2 SaveTo:(NSString*) combinedPath
{
	NSFileManager *fm = [[NSFileManager alloc] init];
	NSFileHandle *f1Handle = [NSFileHandle fileHandleForReadingAtPath: path1];
	NSFileHandle *f2Handle = [NSFileHandle fileHandleForReadingAtPath: path2];
	
	//might need to check if file exists first, if not create it using NSFileManager's createFileAtPath
	if(![fm fileExistsAtPath:combinedPath]){
		[fm createFileAtPath:combinedPath contents:nil attributes:nil];
	}
	
	
	NSFileHandle *combinedHandle = [NSFileHandle fileHandleForWritingAtPath: combinedPath];
	
	NSMutableData *read = [[NSMutableData alloc] initWithLength:CHUNK_SIZE];
	
	// read data in small chunks to avoid hogging memory. 
	[read setData:[f1Handle readDataOfLength: CHUNK_SIZE]];
	
    while([read length] != 0)   
	{
		[combinedHandle writeData: read];
		[read setData:[f1Handle readDataOfLength: CHUNK_SIZE]];
	}
    //now do the same for f2Handle
    //might need to ignore a few bytes in the front of file2 that isnt audio
    [f2Handle readDataOfLength: HEADER_LENGTH];
	
	[read  setData:[f2Handle readDataOfLength: CHUNK_SIZE]];
	while([read length] != 0)
    {
		[combinedHandle writeData: read];
		[read setData:[f2Handle readDataOfLength: CHUNK_SIZE]];
    }
	[f1Handle closeFile];
	[f2Handle closeFile];
	[combinedHandle closeFile];
}

Last edited by boxorox; 04-05-2010 at 03:33 PM.
boxorox is offline   Reply With Quote
Old 07-16-2010, 01:15 AM   #12 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: India
Posts: 3
Default Mixing of two sound files from code

Hello All,

I am also looking for the same as I need to do it in iPhone app.
Any help would be highly appreciated...
Kapil is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 922
17 members and 905 guests
Abb4ertW, cacao, Desert Diva, Diegan, fiftysixty, glennrichard113, harsha_0409, ios dev, klbaiju, leahov, mizzytheboy, nguyenhieu129, Ocguy, pinky, qkstrk, Shubhank, Snail
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,298
Threads: 89,032
Posts: 379,810
Top Poster: BrianSlick (7,086)
Welcome to our newest member, glennrichard113
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:18 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0