1   package org.daisy.pipeline.audio;
2   
3   import javax.sound.sampled.AudioFormat;
4   import javax.sound.sampled.AudioSystem;
5   
6   public class PCMAudioFormat extends AudioFormat {
7   
8   	private PCMAudioFormat(AudioFormat format) {
9   		super(format.getEncoding(),
10  		      format.getSampleRate(),
11  		      format.getSampleSizeInBits(),
12  		      format.getChannels(),
13  		      format.getFrameSize(),
14  		      format.getFrameRate(),
15  		      format.isBigEndian());
16  	}
17  
18  	/**
19  	 * @throws IllegalArgumentException if <code>format</code> is not PCM encoded, or has frame rate,
20  	 *                                  frame size, sample rate, sample size, or number of channels
21  	 *                                  not specified.
22  	 */
23  	public static PCMAudioFormat of(AudioFormat format) {
24  		if (format instanceof PCMAudioFormat)
25  			return (PCMAudioFormat)format;
26  		if (!AudioUtils.isPCM(format))
27  			throw new IllegalArgumentException();
28  		if (format.getFrameRate() == AudioSystem.NOT_SPECIFIED)
29  			throw new IllegalArgumentException();
30  		if (format.getFrameSize() == AudioSystem.NOT_SPECIFIED)
31  			throw new IllegalArgumentException();
32  		if (format.getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED)
33  			throw new IllegalArgumentException();
34  		if (format.getSampleRate() == AudioSystem.NOT_SPECIFIED)
35  			throw new IllegalArgumentException();
36  		if (format.getChannels() == AudioSystem.NOT_SPECIFIED)
37  			throw new IllegalArgumentException();
38  		return new PCMAudioFormat(format);
39  	}
40  }