FileDocCategorySizeDatePackage
AUMux.javaAPI DocJMF 2.1.1e4761Mon May 12 12:20:58 BST 2003com.sun.media.multiplexer.audio

AUMux

public class AUMux extends BasicMux

Fields Summary
private static final int
HEADER_SIZE
private static final int
UNKNOWN_ENCODING
private AudioFormat
audioFormat
private int
sampleSizeInBits
private int
encoding
private double
sampleRate
private int
channels
private static final int
AU_SUN_MAGIC
private static final int
AU_ULAW_8
private static final int
AU_ALAW_8
private static final int
AU_LINEAR_8
private static final int
AU_LINEAR_16
private static final int
AU_LINEAR_24
private static final int
AU_LINEAR_32
private static final int
AU_FLOAT
private static final int
AU_DOUBLE
Format
bigEndian
Constructors Summary
public AUMux()

 /* 64-bit IEEE floating point */

      
	supportedInputs = new Format[1];
	supportedInputs[0] = new AudioFormat(null);
	supportedOutputs = new ContentDescriptor[1];
	supportedOutputs[0] = new FileTypeDescriptor(FileTypeDescriptor.BASIC_AUDIO);
    
Methods Summary
private intgetEncoding(java.lang.String encodingString, int sampleSizeInBits)

	if (encodingString.equalsIgnoreCase(AudioFormat.ULAW))
	    return AU_ULAW_8;
	else if (encodingString.equalsIgnoreCase(AudioFormat.ALAW))
	    return AU_ALAW_8;
	else if (encodingString.equalsIgnoreCase(AudioFormat.LINEAR)) {
	    if (sampleSizeInBits == 8)
		return AU_LINEAR_8;
	    else if (sampleSizeInBits == 16)
		return AU_LINEAR_16;
	    else if (sampleSizeInBits == 24)
		return AU_LINEAR_24;
	    else if (sampleSizeInBits == 32)
		return AU_LINEAR_32;
	    else
		return UNKNOWN_ENCODING;
	} else if (encodingString.equalsIgnoreCase("float"))
	    return AU_FLOAT;
	else if (encodingString.equalsIgnoreCase("double"))
	    return AU_DOUBLE;
	else {
	    //System.out.println("getEncoding: returns UNKNOWN_ENCODING");
	    return UNKNOWN_ENCODING;
	}
    
public java.lang.StringgetName()

	return "Basic Audio Multiplexer";
    
public javax.media.FormatsetInputFormat(javax.media.Format format, int trackID)


          

	String reason = null;
	
	if (!(format instanceof AudioFormat))
	    return null;
	
	audioFormat = (AudioFormat) format;

	String encodingString = audioFormat.getEncoding();
	sampleSizeInBits = audioFormat.getSampleSizeInBits();

	// Linear Data has to be in big endian and should be signed
	if (encodingString.equalsIgnoreCase(AudioFormat.LINEAR)) {
	    if (sampleSizeInBits > 8 &&
		audioFormat.getEndian() == AudioFormat.LITTLE_ENDIAN)
		return null;

	    if (audioFormat.getSigned() == AudioFormat.UNSIGNED)
		return null;

	    if (audioFormat.getEndian() == AudioFormat.NOT_SPECIFIED ||
		audioFormat.getSigned() == AudioFormat.NOT_SPECIFIED)
		audioFormat = (AudioFormat)audioFormat.intersects(bigEndian);
	}

	// System.out.println("encodingString is " + encodingString);
	encoding = getEncoding(encodingString, sampleSizeInBits);
	if (encoding == UNKNOWN_ENCODING) {
	    reason = "No support for encoding " + encodingString;
	}

	sampleRate = audioFormat.getSampleRate();
	channels = audioFormat.getChannels();

	if (reason == null)
	    return audioFormat;
	else
	    return null;
    
public intsetNumTracks(int nTracks)

	if (nTracks != 1)
	    return 1;
	else
	    return super.setNumTracks(nTracks);
    
protected voidwriteFooter()

	seek(8);
	bufClear();
	bufWriteInt(fileSize - HEADER_SIZE);
	bufFlush();
    
protected voidwriteHeader()

	bufClear();
	bufWriteInt(AU_SUN_MAGIC);
	bufWriteInt(HEADER_SIZE);
	bufWriteInt(-1); // Size of data, to be filled in at the end
	bufWriteInt(encoding);
	bufWriteInt((int) sampleRate);
	bufWriteInt(channels);
	bufFlush();