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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-05-2010, 02:16 PM   #11 (permalink)
boxorox
Registered Member
 
Join Date: Apr 2010
Posts: 1
boxorox is on a distinguished road
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 02:33 PM.
boxorox is offline   Reply With Quote
 

» Advertisements
» Online Users: 323
12 members and 311 guests
acegames, baja_yu, chemistry, dylanreich, fredbmm, garticle, greeneye82, jimmyon122, mobilaga, NSString, wfarun2012, zhijianhi
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,556
Threads: 94,078
Posts: 402,737
Top Poster: BrianSlick (7,990)
Welcome to our newest member, wfarun2012
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:13 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.