ios - How to reverse an AAC audio file? -


i able record , playback in reverse (thanks couple examples), give user ability select recorded .aac file table view , reverse it. have tried changing input file url url of user's file, either static or audio file 0.0 duration. type of reversal possible aac files? if so, how correct settings accept it?

recordedaudiourl = [nsurl urlwithstring:[savedurl stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]]; nslog( @"url %@", [recordedaudiourl absolutestring]);  flippedaudiourl = [nsurl urlwithstring:[reverseurl stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]]; nslog( @"url %@", [flippedaudiourl absolutestring]);  audiofileid outputaudiofile;  audiostreambasicdescription mypcmformat; mypcmformat.msamplerate = 16000.00; mypcmformat.mformatid = kaudioformatlinearpcm ; mypcmformat.mformatflags =  kaudioformatflagscanonical; mypcmformat.mchannelsperframe = 1; mypcmformat.mframesperpacket = 1; mypcmformat.mbitsperchannel = 16; mypcmformat.mbytesperpacket = 2; mypcmformat.mbytesperframe = 2;  audiofilecreatewithurl((__bridge cfurlref)flippedaudiourl,                        kaudiofilecaftype,                        &mypcmformat,                        kaudiofileflags_erasefile,                        &outputaudiofile);  audiofileid inputaudiofile; osstatus theerr = noerr; uint64 filedatasize = 0;  audiostreambasicdescription thefileformat; uint32 thepropertysize = sizeof(thefileformat);  theerr = audiofileopenurl((__bridge cfurlref)recordedaudiourl, kaudiofilereadpermission, 0, &inputaudiofile);  thepropertysize = sizeof(filedatasize); theerr = audiofilegetproperty(inputaudiofile, kaudiofilepropertyaudiodatabytecount, &thepropertysize, &filedatasize);  uint32 datasize = filedatasize; void* thedata = malloc(datasize);  //read data buffer sint64 readpoint  = datasize; uint32 writepoint = 0; while( readpoint > 0 ) {     uint32 bytestoread = 2;     audiofilereadbytes( inputaudiofile, false, readpoint, &bytestoread, thedata );     audiofilewritebytes( outputaudiofile, false, writepoint, &bytestoread, thedata );      writepoint += 2;     readpoint -= 2; }  free(thedata); audiofileclose(inputaudiofile); audiofileclose(outputaudiofile);  } 

your code reading raw aac data backwards (audiofilereadbytes doesn't respect packet boundaries, unlike audiofilereadpacketdata), , writing forwards lpcm. no wonder you're hearing static. reverse aac file have decode lpcm first. suggest switch reading code audiofile to either extendedaudiofile or avaudiofile.

your read-backwards-and-write-forwards approach should still work above change.

the apis mentioned can decode aac (among other things) lpcm, e.g. decoding avaudiofile , decoding extaudiofile

nb examples aren't reading aac, doesn't matter apis hide details code doesn't need care source format is.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -