Re: afinfo
Re: afinfo
- Subject: Re: afinfo
- From: Jean-Daniel Dupas <email@hidden>
- Date: Fri, 5 Nov 2010 09:36:46 +0100
This is plain C, so you can use it in obj-c file.
Of course, you will have to include the proper header <AudioToolbox/AudioToolbox.h>
And add the AudioToolbox framework to your project.
I wrote this code in Mail, so it may need some adjustments.
And note that querying the exact duration may be slow, as some file have to be fully scan to know it (like mp3 files).
That's why estimated duration exists. It returns exact duration if it can query it fast, and an estimation if it would block.
Le 5 nov. 2010 à 08:34, email@hidden a écrit :
> Hi Jean,
>
> thank you.
> The reason is that I don't have knowledge about core audio and wanted to go the easy way.
> But I will try to use your code. Can I add this to my normal .m class or do I have to use .mm ?
> Is your code ok for an 64bit application ?
>
> Karsten
>
>
> Am 04.11.2010 um 23:40 schrieb Jean-Daniel Dupas:
>
>>
>> Le 4 nov. 2010 à 22:20, email@hidden a écrit :
>>
>>> Hi,
>>>
>>> I have set up a NSTask to log the afinfo output, which works already.
>>> My question is:
>>> Is there an argument that gives me back only the duration of the audiofile ?
>>> In the terminal I can do this with -afinfo filename | grep "estimated duration" ,
>>> but that does not work with NSTask.
>>>
>>
>> What about using CoreAudio API instead ?
>>
>> ExtAudioFileRef file;
>> if (noErr == ExtAudioFileOpenURL(myURL, &file)) {
>> UInt64 frames = 0;
>> AudioStreamBasicDescription desc;
>> UInt32 pfSize = sizeof(UInt64), descSize = sizeof(AudioStreamBasicDescription);
>> if (noErr == ExtAudioFileGetProperty(file, kExtAudioFileProperty_FileDataFormat, &descSize, &desc) &&
>> noErr == ExtAudioFileGetProperty(file, kExtAudioFileProperty_FileLengthFrames, &pfSize, &frames)) {
>> double duration = frames / desc.mSampleRate;
>> }
>> ExtAudioFileDispose(file);
>> }
>>
>>
>> -- Jean-Daniel
>>
>>
>>
>
-- Jean-Daniel
_______________________________________________
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
References: | |
| >afinfo (From: email@hidden <email@hidden>) |
| >Re: afinfo (From: Jean-Daniel Dupas <email@hidden>) |
| >Re: afinfo (From: "email@hidden" <email@hidden>) |