Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/apollo/meldex/WavSample.java

    r315 r1102  
    88import javax.sound.sampled.AudioInputStream;
    99import javax.sound.sampled.AudioSystem;
    10 import javax.swing.JOptionPane;
    11 
    12 @SuppressWarnings("unchecked") // code in java 1.4
     10
     11import org.expeditee.gio.EcosystemManager;
     12
    1313public class WavSample
    1414{
     
    6868        }
    6969        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);
    7171            return false;
    7272        }
     
    9090            }
    9191            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);
    9393                return false;
    9494            }
     
    101101            }
    102102            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);
    104104                return false;
    105105            }
     
    172172        if (format.getSampleSizeInBits() == 8) {
    173173            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).");
    175175                return null;
    176176            }
     
    178178        if (format.getSampleSizeInBits() == 16) {
    179179            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).");
    181181                return null;
    182182            }
     
    188188
    189189        // Create a new list to store the standardised sample values
    190         ArrayList stdTemp = new ArrayList();
     190        ArrayList<Integer> stdTemp = new ArrayList<Integer>();
    191191
    192192        // Simply pick values from the sample at the frequency specified
     
    218218
    219219
    220     private static ArrayList toStandardEndian(AudioFormat format, ArrayList 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 outData = new ArrayList();
    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 toUnsignedValues(AudioFormat format, ArrayList inData)
     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)
    252252    {
    253253        // PCM_UNSIGNED samples are what we want, so no conversion needed
     
    257257
    258258        // Create a new list to store the results
    259         ArrayList outData = new ArrayList();
     259        ArrayList<Integer> outData = new ArrayList<Integer>();
    260260
    261261        // Simply convert each signed number in the sample to an unsigned value
     
    275275
    276276
    277     private static ArrayList to8bit(AudioFormat format, ArrayList inData)
     277    private static ArrayList<Integer> to8bit(AudioFormat format, ArrayList<Integer> inData)
    278278    {
    279279        // 8-bit data is what we want, so no conversion necessary
     
    283283
    284284        // Create a new list to store the results
    285         ArrayList outData = new ArrayList();
     285        ArrayList<Integer> outData = new ArrayList<Integer>();
    286286
    287287        // Simply reduce each value in the sample to an 8-bit value
     
    298298
    299299
    300     private static ArrayList toMono(AudioFormat format, ArrayList inData)
     300    private static ArrayList<Integer> toMono(AudioFormat format, ArrayList<Integer> inData)
    301301    {
    302302        // Mono-channel data is what we want, so no conversion necessary
     
    306306
    307307        // Create a new list to store the results
    308         ArrayList outData = new ArrayList();
     308        ArrayList<Integer> outData = new ArrayList<Integer>();
    309309
    310310        // Simply average all of the channels for each frame
     
    362362        try {
    363363            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.");
    365365                return false;
    366366            }
    367367        }
    368368        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);
    370370            return false;
    371371        }
Note: See TracChangeset for help on using the changeset viewer.