Changeset 1102 for trunk/src/org/apollo/meldex/WavSample.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/apollo/meldex/WavSample.java
r315 r1102 8 8 import javax.sound.sampled.AudioInputStream; 9 9 import javax.sound.sampled.AudioSystem; 10 import javax.swing.JOptionPane; 11 12 @SuppressWarnings("unchecked") // code in java 1.4 10 11 import org.expeditee.gio.EcosystemManager; 12 13 13 public class WavSample 14 14 { … … 68 68 } 69 69 catch (Exception ex) { 70 JOptionPane.showMessageDialog(null, "Exception occurred creating sample.\n\n" + ex);70 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred creating sample.\n\n" + ex); 71 71 return false; 72 72 } … … 90 90 } 91 91 catch (Exception ex) { 92 JOptionPane.showMessageDialog(null, "Exception occurred reloading sample.\n\n" + ex);92 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred reloading sample.\n\n" + ex); 93 93 return false; 94 94 } … … 101 101 } 102 102 catch (Exception ex) { 103 JOptionPane.showMessageDialog(null, "Exception occurred resetting audio stream.\n\n" + ex);103 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred resetting audio stream.\n\n" + ex); 104 104 return false; 105 105 } … … 172 172 if (format.getSampleSizeInBits() == 8) { 173 173 if (format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { 174 JOptionPane.showMessageDialog(null, "Oops! Internal Error: Unexpected audio format (signed 8-bit).");174 EcosystemManager.getGraphicsManager().showDialog("Exception", "Oops! Internal Error: Unexpected audio format (signed 8-bit)."); 175 175 return null; 176 176 } … … 178 178 if (format.getSampleSizeInBits() == 16) { 179 179 if (format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)) { 180 JOptionPane.showMessageDialog(null, "Oops! Internal Error: Unexpected audio format (unsigned 16-bit).");180 EcosystemManager.getGraphicsManager().showDialog("Exception", "Oops! Internal Error: Unexpected audio format (unsigned 16-bit)."); 181 181 return null; 182 182 } … … 188 188 189 189 // Create a new list to store the standardised sample values 190 ArrayList stdTemp = new ArrayList();190 ArrayList<Integer> stdTemp = new ArrayList<Integer>(); 191 191 192 192 // Simply pick values from the sample at the frequency specified … … 218 218 219 219 220 private static ArrayList toStandardEndian(AudioFormat format, ArrayListinData)221 { 222 // Endian details do not apply to 8-bit samples, so no conversion needed223 if (format.getSampleSizeInBits() == 8) {224 return inData;225 }226 227 // Create a new list to store the results228 ArrayList outData = new ArrayList();229 230 // Simply convert each number in the sample to the endian form for the current system231 for (int i = 0; i < inData.size(); i += 2) {232 233 int MSB, LSB;234 if (format.isBigEndian()) {235 MSB = ((Integer) inData.get(i)).intValue(); // First byte is MSB (high order)236 LSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is LSB (low order)237 }238 else {239 LSB = ((Integer) inData.get(i)).intValue(); // First byte is LSB (low order)240 MSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is MSB (high order)241 }242 243 int val = (MSB << 8) + (LSB & 255);244 outData.add(new Integer(val));245 }246 247 return outData;248 } 249 250 251 private static ArrayList toUnsignedValues(AudioFormat format, ArrayListinData)220 private static ArrayList<Integer> toStandardEndian(AudioFormat format, ArrayList<Integer> inData) 221 { 222 // Endian details do not apply to 8-bit samples, so no conversion needed 223 if (format.getSampleSizeInBits() == 8) { 224 return inData; 225 } 226 227 // Create a new list to store the results 228 ArrayList<Integer> outData = new ArrayList<Integer>(); 229 230 // Simply convert each number in the sample to the endian form for the current system 231 for (int i = 0; i < inData.size(); i += 2) { 232 233 int MSB, LSB; 234 if (format.isBigEndian()) { 235 MSB = ((Integer) inData.get(i)).intValue(); // First byte is MSB (high order) 236 LSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is LSB (low order) 237 } 238 else { 239 LSB = ((Integer) inData.get(i)).intValue(); // First byte is LSB (low order) 240 MSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is MSB (high order) 241 } 242 243 int val = (MSB << 8) + (LSB & 255); 244 outData.add(new Integer(val)); 245 } 246 247 return outData; 248 } 249 250 251 private static ArrayList<Integer> toUnsignedValues(AudioFormat format, ArrayList<Integer> inData) 252 252 { 253 253 // PCM_UNSIGNED samples are what we want, so no conversion needed … … 257 257 258 258 // Create a new list to store the results 259 ArrayList outData = new ArrayList();259 ArrayList<Integer> outData = new ArrayList<Integer>(); 260 260 261 261 // Simply convert each signed number in the sample to an unsigned value … … 275 275 276 276 277 private static ArrayList to8bit(AudioFormat format, ArrayListinData)277 private static ArrayList<Integer> to8bit(AudioFormat format, ArrayList<Integer> inData) 278 278 { 279 279 // 8-bit data is what we want, so no conversion necessary … … 283 283 284 284 // Create a new list to store the results 285 ArrayList outData = new ArrayList();285 ArrayList<Integer> outData = new ArrayList<Integer>(); 286 286 287 287 // Simply reduce each value in the sample to an 8-bit value … … 298 298 299 299 300 private static ArrayList toMono(AudioFormat format, ArrayListinData)300 private static ArrayList<Integer> toMono(AudioFormat format, ArrayList<Integer> inData) 301 301 { 302 302 // Mono-channel data is what we want, so no conversion necessary … … 306 306 307 307 // Create a new list to store the results 308 ArrayList outData = new ArrayList();308 ArrayList<Integer> outData = new ArrayList<Integer>(); 309 309 310 310 // Simply average all of the channels for each frame … … 362 362 try { 363 363 if (AudioSystem.write(audioData, AudioFileFormat.Type.WAVE, outFile) == -1) { 364 JOptionPane.showMessageDialog(null, "Problem occurred writing to file.");364 EcosystemManager.getGraphicsManager().showDialog("Exception", "Problem occurred writing to file."); 365 365 return false; 366 366 } 367 367 } 368 368 catch (Exception ex) { 369 JOptionPane.showMessageDialog(null, "Exception occurred saving file.\n\n" + ex);369 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred saving file.\n\n" + ex); 370 370 return false; 371 371 }
Note:
See TracChangeset
for help on using the changeset viewer.