Re: Audio File Type Recognition Question
  Home FAQ Contact Sign in
microsoft.public.win32.programmer.directx.audio only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Audio File Type Recognition Question         

Group: microsoft.public.win32.programmer.directx.audio · Group Profile
Author: Alessandro Angeli
Date: Jul 22, 2008 17:56

From: "Yaerek"
> Hi. I'm writing an application that has to load/play
> audio files. It has to run on XP/Vista (and Mac OS X)
> Question is, how to recognize a type of audio file we're
> loading? Basically, I want to know what kind of audio
> file I got in order to properly handel it (mp3, wav, wma,
> aac, au). I understand I can "recognize" a file type
> based on its extension, however that does not guarantee
> what's inside; wav container can store several different
> formats. How to recognize which one I'm facing? Should it
> only be based on file extension?

As Shugo told you, there is no generic way: you need to read
the beginning of the file ad try to make sense of it
comparing its contents to a list of templates of each type
you plan on supporting. This is exactly what e.g. DirectShow
does when asked to find a source filter.

You can perform the check yourself by parsing the beginning
of the file according to the specs of each file type you
want to support. Or you can rely on DirectShow to guess it
for you, but it will only guess the types that are
registered on the machine. Also, DirectShow may require
additional steps to distinguish e.g. MP3 from MP2.

In any case, most file types are containers that can contain
different stream formats. If you also want to discover the
formats of the streams, you need to actually parse the whole
file header according to the file format specs to extract
that info. If you need this, DirectShow is a bit friendlier
and only requires that you write a custom filter that
accepts specifics audio and video major types and that
dynamically spawns infinite input pins.

Every solution has pros and cons and the one that best
suites you depends on what exactly you need to do, which you
didn't elaborate on.

--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm
no comments
diggit! del.icio.us! reddit!