Re: Audio trimming with Audio File API
Re: Audio trimming with Audio File API
- Subject: Re: Audio trimming with Audio File API
- From: William Stewart <email@hidden>
- Date: Tue, 24 Aug 2010 18:10:43 -0700
On Aug 24, 2010, at 5:09 PM, Brian Willoughby wrote:
>
> On Aug 24, 2010, at 16:14, Fernando Valente wrote:
>> Hi, I'm new to Core Audio. How may I trim a MP3/AAC file using Audio File API?
>
> You can't. Not without decoding and re-encoding, which constitutes generational loss of quality.
Actually this is wrong.
Trimming is quite an easy operation, but you probably have to create a new file (rather than do this in place).
By trimming, I mean that you are taking off packets at the end. It is more difficult (but not impossible) to take packets off at the start - but you have some quantisation issues to deal with.
So, if we take the trim off the end case:
Open the file to be trimmed - f1
Create a new file (same format as f1) - f2
Call AudioFileReadPacket on f1 for as many packets as you want to move over to f2. Write those packets (AudioFileWritePackets) to f2
Make sure you get the magic cookie and the priming data from f1 and copy that over as well. For the priming, you may want to change the remainder frames to what you want trimmed off the last packet (if any), otherwise set that field to 0.
The ConvertFile example might help you to get familiar with the basics of audio file (see developer.apple.com)
That's it.
afconvert allows you to do something similar to this if you use the -d 0 option - it just copies all of the data from the src to the dest file without changing it. Trimming off the end is just leaving off the packets at the end you don't want to play.
If you get this up and running, then you can ask me about trimming from the start (but only then) :-)
Bill
>
> There are MP3-specific API which can do this, but I am not aware of a solution for AAC.
>
> Brian Willoughby
> Sound Consulting
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden