Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you find supported audio formats for the mic?



Aaron Roberts <email@hidden> wrote:

>I am working with audio and discovered that the supported audio format
>changes quite a bit between OSes (Mac, Win, Lin)  and hardware.
>...
>How can I find out what formats are supported?

By asking AudioSystem or its sub-elements for supported AudioFormats.  Most
things in javax.sound.sampled have methods that return arrays of
sub-elements or supported facilities.

AudioSystem itself has static methods that scan all available Mixers for
common contingencies.  For uncommon ones, you can get the full list of
Mixer.Info objects, then iterate and examine each Mixer for what it
provides.

Here's an UNCOMPILED UNTESTED code fragment that shows the basic idea.  If
this doesn't work verbatim, you'll have to tweak it.
 - - - -
Vector results = new Vector();

Line.Info desired = new Line.Info( TargetDataLine.class );
Line.Info[] info = AudioSystem.getTargetLineInfo( desired );

for ( int i = 0;  i < info.length; ++i )
{
  if ( info[ i ] instanceof DataLine.Info )
  {
    AudoFormat[] forms = ((DataLine.Info) info[i]).getFormats();
    for ( int n = 0;  n < forms.length;  ++n )
    {  results.add( forms[ n ] );  }
  }
}
 - - - -

The results Vector contains all supported AudioFormats for all available
target-lines in all mixers.  The Vector may contain repeats, if more than
one Mixer supports the same formats.

You can search the Vector for a specific format, or rank them by some
criterion, or create an AudioFormat with AudioSystem.NOT_SPECIFIED for some
parameters and find all the matches() for it.

NOT_SPECIFIED is an under-used part of AudioSystem.  It appears to work in
AudioFormat for sample-rate and frame-rate when matches() is evaluated, but
not for other parameters.


You can get zillions of FAQs and examples available here:
  <http://www.jsresources.org/faq_audio.html>

  -- GG


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.