JavaTM Platform
Standard Ed. 6

javax.sound.sampled
�� AudioFormat

java.lang.Object
  �̳��� javax.sound.sampled.AudioFormat

public class AudioFormat
extends Object

AudioFormat ������������ָ���ض����ݰ��ŵ��ࡣͨ���������Ƶ��ʽ�洢����Ϣ�����Է����ڶ��������������н���λ�ķ�ʽ��

ÿ�������ж���������������ص���Ƶ��ʽ��Դ���طţ������е���Ƶ��ʽָʾ��������������������������͡�����Ŀ�꣨���������У���Ƶ��ʽָ�����ԴӸ��ж�ȡ���������ࡣ��Ȼ�������ļ�Ҳ����Ƶ��ʽ��AudioFileFormat ���װ AudioFormat �Լ������ض����ļ�����Ϣ�����Ƶأ�AudioInputStream ���� AudioFormat��

AudioFormat ����Ӧ���ֳ��������ļ����뼼������������������ (PCM)��mu-law ����� a-law ���롣��Щ���뼼����Ԥ�ȶ���ģ��������ṩ�߿��Դ����µı������͡��ض���ʽʹ�õı���ͨ���� encoding �ֶ�������

�������⣬��Ƶ��ʽ��������һ��ָ���������ݰ��ŵ��������ԡ���Щ���԰����ŵ������������ʡ�������С���ֽ�˳��֡���ʺ�֡��С�����������в�ͬ��������Ƶ�ŵ�����������һ���ŵ����������������ŵ����������ʲ���ÿ�ŵ���ÿ���Ӳ��õ���ѹ“����”������������������������������������ǵ�����������ÿ��˲��ʵ�ʲ�������������һ��������������һ���������������������������Բ���ÿ�����������������Բ����������Ƕ��٣����ʶ�һ�������Ǹ�����ı�׼��;����������Сָʾ���ڴ洢ÿ�����յ�λ��������ֵ�� 8 �� 16������ 16 λ�����������һ���ֽڴ�С���κ��������������ֽ�˳�����Ҫ��ÿ�������е��ֽ�Ҫô�� "little-endian" ��ʽ���У�Ҫô�� "big-endian" ��ʽ���С��������� PCM �ı��룬֡���ڸ���ʱ�������������������������ɣ����֡�Ĵ�С�����ֽ�Ϊ��λ�����ǵ���������С�����ֽ�Ϊ��λ��������������������ʹ����������ı��룬֡���԰�������ϵ��������ѹ�����ݰ����Լ��������������ݡ�������Щ���룬�������ʺ�������С�ڽ����ݽ��뵽 PCM ֮�����ø����ݣ�����������֡���ʺ�֡��С��ȫ��ͬ��

AudioFormat ������԰������Եļ��ϡ�������һ����ֵ�ԣ������� String ���ͣ��������ֵ��Ϊ�����������ָ��������ʽ�淶����ѹ����ʽ�ı����ʡ�������Ҫ�������������ڷ����ṩ�ߵ�������Ƶ��ʽ��Ϣ�ķ�������ˣ������� matches(AudioFormat) �����б����ԡ������������Ѱ�װ�ķ����ṩ�ߵķ������� (AudioFormat, AudioFormat) isConversionSupported�����Կ���ʹ�����ԣ�����ȡ���ڸ��Եķ����ṩ��ʵ�֡�

�±��г��˷����ṩ��Ӧ��ʹ�õ�һЩ�������ԣ�������ã���

���Լ� ֵ���� ����
“������” Integer ��λÿ��Ϊ��λ��ƽ��������
“�ɱ������” Boolean ����ļ����ÿɱ������ (VBR) ���б��룬��Ϊ true
“����” Integer ����/ת��������1 �� 100

���������ṩ�ߣ�������Ĺ�Ӧ��Ѱ�ҹ��������Ѿ��ڵ���������н��������Ե���Ϣ������ѭ��ͬ��Լ����

�����°汾��ʼ��
1.3
������
DataLine.getFormat(), AudioInputStream.getFormat(), AudioFileFormat, FormatConversionProvider

Ƕ����ժҪ
static class AudioFormat.Encoding
          Encoding ������������Ƶ�������ݱ�ʾ��ʽ���ض����͡�
 
�ֶ�ժҪ
protected  boolean bigEndian
          ָʾ���� big-endian ˳���� little-endian ˳��洢��Ƶ���ݡ�
protected  int channels
          ʹ�ô˸�ʽ����Ƶ�ŵ�����������Ϊ 1��������Ϊ 2����
protected  AudioFormat.Encoding encoding
          �˸�ʽʹ�õ���Ƶ���뼼����
protected  float frameRate
          ���д˸�ʽ������ÿ�벥�ź�¼�Ƶ�֡����
protected  int frameSize
          ÿ�����д˸�ʽ������֡�������ֽ�����
protected  float sampleRate
          ���д˸�ʽ������ÿ�벥�Ż�¼�Ƶ���������
protected  int sampleSizeInBits
          ÿ�����д˸�ʽ�����������е�λ����
 
���췽��ժҪ
AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian)
          ������и��������� AudioFormat��
AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian, Map<String,Object> properties)
          ������и��������� AudioFormat��
AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
          ����������� PCM ����͸��������� AudioFormat��
 
����ժҪ
 int getChannels()
          ��ȡ�ŵ�����
 AudioFormat.Encoding getEncoding()
          ��ȡ�˸�ʽ�����ı������͡�
 float getFrameRate()
          ��ȡ��֡ÿ��Ϊ��λ��֡���ʡ�
 int getFrameSize()
          ��ȡ���ֽ�Ϊ��λ��֡��С��
 Object getProperty(String key)
          ��ȡ��ָ��������ֵ��
 float getSampleRate()
          ��ȡ�������ʡ�
 int getSampleSizeInBits()
          ��ȡ�����Ĵ�С��
 boolean isBigEndian()
          ָʾ���� big-endian ˳������ little-endian ˳��洢��Ƶ���ݡ�
 boolean matches(AudioFormat format)
          ָʾ�˸�ʽ�Ƿ���ָ����ʽƥ�䡣
 Map<String,Object> properties()
          ��ȡ�����޸ĵ�����ӳ�䡣
 String toString()
          ����������ʽ���ַ������磺"PCM SIGNED 22050 Hz 16 bit mono big-endian"��
 
���� java.lang.Object �̳еķ���
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

�ֶ���ϸ��Ϣ

encoding

protected AudioFormat.Encoding encoding
�˸�ʽʹ�õ���Ƶ���뼼����


sampleRate

protected float sampleRate
���д˸�ʽ������ÿ�벥�Ż�¼�Ƶ���������


sampleSizeInBits

protected int sampleSizeInBits
ÿ�����д˸�ʽ�����������е�λ����


channels

protected int channels
ʹ�ô˸�ʽ����Ƶ�ŵ�����������Ϊ 1��������Ϊ 2����


frameSize

protected int frameSize
ÿ�����д˸�ʽ������֡�������ֽ�����


frameRate

protected float frameRate
���д˸�ʽ������ÿ�벥�ź�¼�Ƶ�֡����


bigEndian

protected boolean bigEndian
ָʾ���� big-endian ˳���� little-endian ˳��洢��Ƶ���ݡ�

���췽����ϸ��Ϣ

AudioFormat

public AudioFormat(AudioFormat.Encoding encoding,
                   float sampleRate,
                   int sampleSizeInBits,
                   int channels,
                   int frameSize,
                   float frameRate,
                   boolean bigEndian)
������и��������� AudioFormat���ñ���ָ�����ڱ�ʾ���ݵ�Լ���������������������н�һ�����͡�

������
encoding - ��Ƶ���뼼��
sampleRate - ÿ���������
sampleSizeInBits - ÿ�������е�λ��
channels - �������������� 1 ���������� 2 �����ȵȣ�
frameSize - ÿ֡�е��ֽ���
frameRate - ÿ���֡��
bigEndian - ָʾ�Ƿ��� big-endian �ֽ�˳��洢���������е����ݣ�false ��ζ�� little-endian����

AudioFormat

public AudioFormat(AudioFormat.Encoding encoding,
                   float sampleRate,
                   int sampleSizeInBits,
                   int channels,
                   int frameSize,
                   float frameRate,
                   boolean bigEndian,
                   Map<String,Object> properties)
������и��������� AudioFormat���ñ���ָ�����ڱ�ʾ���ݵ�Լ���������������������н�һ�����͡�

������
encoding - ��Ƶ���뼼��
sampleRate - ÿ��������
sampleSizeInBits - ÿ�������е�λ��
channels - ��������������Ϊ 1��������Ϊ 2���ȵȣ�
frameSize - ÿ֡�������ֽ���
frameRate - ÿ��֡��
bigEndian - ָʾ�Ƿ��� big-endian �ֽ�˳��洢���ݣ�false ��ζ�� little-endian��
properties - ������ʽ���Ե� Map<String,Object> ����
�����°汾��ʼ��
1.5

AudioFormat

public AudioFormat(float sampleRate,
                   int sampleSizeInBits,
                   int channels,
                   boolean signed,
                   boolean bigEndian)
����������� PCM ����͸��������� AudioFormat����֡��С����Ϊ����ÿ������һ������������ֽ�������֡��������Ϊ�������ʡ�

������
sampleRate - ÿ���������
sampleSizeInBits - ÿ�������е�λ��
channels - �������������� 1 ���������� 2 ����
signed - ָʾ�������з��ŵģ������޷��ŵ�
bigEndian - ָʾ�Ƿ��� big-endian �ֽ�˳��洢���������е����ݣ�false ��ζ�� little-endian����
������ϸ��Ϣ

getEncoding

public AudioFormat.Encoding getEncoding()
��ȡ�˸�ʽ�����ı������͡�

���أ�
��������
������
AudioFormat.Encoding.PCM_SIGNED, AudioFormat.Encoding.PCM_UNSIGNED, AudioFormat.Encoding.ULAW, AudioFormat.Encoding.ALAW

getSampleRate

public float getSampleRate()
��ȡ�������ʡ�����ѹ����ʽ������ֵ��δѹ����Ƶ���ݵ��������ʡ����� AudioFormat ���ڲ�ѯ���� AudioSystem.isConversionSupported�����ܣ��� DataLine.Info.getFormats��ʱ��AudioSystem.NOT_SPECIFIED ������������ζ�ſ��Խ����κ��������ʡ���û��Ϊ����Ƶ��ʽ������������ʱ�����᷵�� AudioSystem.NOT_SPECIFIED��

���أ�
ÿ������������ AudioSystem.NOT_SPECIFIED
������
getFrameRate(), AudioSystem.NOT_SPECIFIED

getSampleSizeInBits

public int getSampleSizeInBits()
��ȡ�����Ĵ�С������ѹ����ʽ������ֵ��δѹ����Ƶ���ݵ�������С������ AudioFormat ���ڲ�ѯ���� AudioSystem.isConversionSupported�����ܣ��� DataLine.Info.getFormats��ʱ��AudioSystem.NOT_SPECIFIED ��������С��ζ�ſ��Խ����κ�������С����û��Ϊ����Ƶ��ʽ����������Сʱ�����᷵�� AudioSystem.NOT_SPECIFIED��

���أ�
ÿ�������е�λ������ AudioSystem.NOT_SPECIFIED
������
getFrameSize(), AudioSystem.NOT_SPECIFIED

getChannels

public int getChannels()
��ȡ�ŵ��������� AudioFormat ���ڲ�ѯ���� AudioSystem.isConversionSupported�����ܣ��� DataLine.Info.getFormats��ʱ��AudioSystem.NOT_SPECIFIED �ķ���ֵ��ζ�ſ��Խ����κΣ������������ŵ���

���أ�
�ŵ�����������Ϊ 1��������Ϊ 2���ȵȣ����� AudioSystem.NOT_SPECIFIED
������
AudioSystem.NOT_SPECIFIED

getFrameSize

public int getFrameSize()
��ȡ���ֽ�Ϊ��λ��֡��С������ AudioFormat ���ڲ�ѯ���� AudioSystem.isConversionSupported�����ܣ��� DataLine.Info.getFormats��ʱ��AudioSystem.NOT_SPECIFIED ��֡��С��ζ�ſ��Խ����κ�֡��С����û��Ϊ����Ƶ��ʽ����֡��Сʱ�����᷵�� AudioSystem.NOT_SPECIFIED��

���أ�
ÿ֡�ֽ������� AudioSystem.NOT_SPECIFIED
������
getSampleSizeInBits(), AudioSystem.NOT_SPECIFIED

getFrameRate

public float getFrameRate()
��ȡ��֡ÿ��Ϊ��λ��֡���ʡ����� AudioFormat ���ڲ�ѯ���� AudioSystem.isConversionSupported�����ܣ��� DataLine.Info.getFormats��ʱ��AudioSystem.NOT_SPECIFIED ��֡������ζ�ſ��Խ����κ�֡���ʡ���û��Ϊ����Ƶ��ʽ����֡����ʱ�����᷵�� AudioSystem.NOT_SPECIFIED��

���أ�
ÿ��֡������ AudioSystem.NOT_SPECIFIED
������
getSampleRate(), AudioSystem.NOT_SPECIFIED

isBigEndian

public boolean isBigEndian()
ָʾ���� big-endian ˳������ little-endian ˳��洢��Ƶ���ݡ����������С������һ���ֽڣ��򷵻�ֵû��ʵ�����塣

���أ�
����� big-endian �ֽ�˳��洢���ݣ��򷵻� true������� little-endian ˳���򷵻� false

properties

public Map<String,Object> properties()
��ȡ�����޸ĵ�����ӳ�䡣���Եĸ�������������һ�����͡�

���أ�
�����������Ե� Map<String,Object> ��������޷�ʶ���κ����ԣ��򷵻ؿ�ӳ�䡣
�����°汾��ʼ��
1.5
������
getProperty(String)

getProperty

public Object getProperty(String key)
��ȡ��ָ��������ֵ�����Եĸ�������������һ�����͡�

���ָ�����Բ���Ϊ�ض��ļ���ʽ����ģ���˷������� null��

������
key - �������Եļ�
���أ�
����ָ����������ֵ��������Բ����ڣ��򷵻� null��
�����°汾��ʼ��
1.5
������
properties

matches

public boolean matches(AudioFormat format)
ָʾ�˸�ʽ�Ƿ���ָ����ʽƥ�䡣��νƥ����ָ���ָ�ʽ�ı��롢�ŵ�����ÿ��������λ���Լ�ÿ֡�������ֽ�����������ͬ�����ָ����ʽ�IJ�������ֵ��Ϊ AudioSystem.NOT_SPECIFIED����ʾ�κβ������ʾ�ƥ�䣩���������ָ�ʽ�����������ͬ�IJ������ʡ����ָ����ʽ��֡���ʲ�Ϊ AudioSystem.NOT_SPECIFIED������ߵ�֡���ʱ��������ȡ����������С����һ���ֽڣ����ֽڴ洢˳��big-endian �� little-endian������ƥ�䡣

������
format - Ҫ�����Ƿ�ƥ��ĸ�ʽ
���أ�
����˸�ʽ��ָ����ʽƥ�䣬�򷵻� true�����򣬷��� false��

toString

public String toString()
����������ʽ���ַ������磺"PCM SIGNED 22050 Hz 16 bit mono big-endian"���ַ��������ݿ��ܻ��� Java Sound ʵ�ֵIJ�ͬ����ͬ��

���ǣ�
�� Object �е� toString
���أ�
������ʽ�������ַ���

JavaTM Platform
Standard Ed. 6

�ύ��������
�йظ���� API �ο����ϺͿ�����Ա�ĵ�������� Java SE ������Ա�ĵ������ĵ���������ϸ�ġ����򿪷���Ա���������Լ�������������ﶨ�塢ʹ�ü��ɺ͹�������ʾ����

��Ȩ���� 2007 Sun Microsystems, Inc. ��������Ȩ���� ����������֤��������������ĵ����·ַ�������