1 19 package org.lucane.applications.audioconf.audio; 20 21 import java.io.Serializable ; 22 23 import javax.sound.sampled.AudioFormat ; 24 import org.xiph.speex.*; 25 26 29 public class AudioConfig implements Serializable 30 { 31 private static final int[][] SPEEX_BUFFERS = { 33 {8, 12, 17, 23, 23, 30, 30, 40, 40, 48, 64}, 34 {12, 17, 22, 27, 35, 45, 54, 62, 72, 88, 108}, 35 {13, 21, 26, 32, 39, 49, 59, 67, 77, 93, 113} 36 }; 37 38 public static final int NARROWBAND = 1; 40 public static final int WIDEBAND = 2; 41 public static final int ULTRA_WIDEBAND = 3; 42 43 private int mode; 45 private int quality; 46 private int channels; 47 48 54 public AudioConfig(int mode, int quality) 55 { 56 this.mode = mode; 57 this.quality = quality; 58 this.channels = 2; 59 } 60 61 66 public int getFrameRate() 67 { 68 if(this.mode == NARROWBAND) 69 return 8000; 70 if(this.mode == WIDEBAND) 71 return 16000; 72 if(this.mode == ULTRA_WIDEBAND) 73 return 32000; 74 75 throw new IllegalStateException ("unknown mode: " + this.mode); 76 } 77 78 83 public int getChannels() 84 { 85 return this.channels; 86 } 87 88 public int getQuality() 89 { 90 return this.quality; 91 } 92 93 public int getSpeexMode() 94 { 95 return this.mode -1; 96 } 97 98 public int getPcmBufferSize() 99 { 100 if(this.mode == NARROWBAND) 101 return 640; 102 if(this.mode == WIDEBAND) 103 return 1280; 104 if(this.mode == ULTRA_WIDEBAND) 105 return 2560; 106 107 throw new IllegalStateException ("unknown mode: " + this.mode); 108 } 109 110 public int getSpeexBufferSize() 111 { 112 return SPEEX_BUFFERS[this.mode-1][this.quality]; 113 } 114 115 public String toString() 116 { 117 return "" +this.mode; 118 } 119 120 122 128 public AudioFormat createAudioFormat(AudioFormat.Encoding type) 129 { 130 return new AudioFormat ( 131 type, 132 this.getFrameRate(), 133 16, 134 this.getChannels(), 135 this.getChannels()*2, 136 this.getFrameRate(), 137 false); 138 } 139 140 public SpeexEncoder createEncoder() 141 { 142 SpeexEncoder encoder = new SpeexEncoder(); 143 encoder.init(getSpeexMode(), getQuality(), getFrameRate(), getChannels()); 144 return encoder; 145 } 146 147 public SpeexDecoder createDecoder() 148 { 149 SpeexDecoder decoder = new SpeexDecoder(); 150 decoder.init(getSpeexMode(), getFrameRate(), getChannels(), false); 151 return decoder; 152 } 153 } | Popular Tags |