/*
  * Create a new empty sound
  */
 public ArrayList<Integer> newSound(int soundLength) {
   myHelper = new Helper(soundLength);
   myHelper.setViewer(this);
   data = myHelper.getData();
   createMainFrame();
   return data;
 }
  /*
   * Load a sound given a specific file name
   */
  public ArrayList<Integer> load(String filename) {
    if (filename == null) {
      System.err.println("Please specify a valid file name");
      return null;
    }

    File file = new File(filename);
    if (!file.isFile()) {
      System.err.println("File not found");
      return null;
    }

    String name = file.getName();
    if (!(name.endsWith(".au")
        || name.endsWith(".wav")
        || name.endsWith(".aiff")
        || name.endsWith(".aif"))) {
      System.err.println(
          "Audio format not supported. Please use either files ending with '.au', '.wav', '.aiff', '.aif'");
      return null;
    }

    myHelper = new Helper(file);
    myHelper.setViewer(this);
    createMainFrame();
    data = myHelper.getData();
    return data;
  }
  /*
   * Load some sound data from through a file chooser
   * We restrict the allowed file formats to .wav, .au .aif .aiff.
   * We only check agains the file name. The file may actually be encoded
   * differently.
   */
  public ArrayList<Integer> load() {
    JFileChooser fileChooser = new JFileChooser();
    File thisFile = new File(".");
    try {
      fileChooser = new JFileChooser(thisFile.getCanonicalPath());
    } catch (Exception e) {
      System.out.println("Cannot find current directory.");
      // Will simply load from default path instead.
    }
    fileChooser.setFileFilter(
        new javax.swing.filechooser.FileFilter() {
          public boolean accept(File f) {
            if (f.isDirectory()) {
              return true;
            }
            String name = f.getName();
            if (name.endsWith(".au")
                || name.endsWith(".wav")
                || name.endsWith(".aiff")
                || name.endsWith(".aif")) {
              return true;
            }
            return false;
          }

          public String getDescription() {
            return ".au, .wav, .aif";
          }
        });

    int returnVal = fileChooser.showOpenDialog(new JFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fileChooser.getSelectedFile();
      myHelper = new Helper(file);
      myHelper.setViewer(this);
      data = myHelper.getData();
      createMainFrame();
      return data;
    }
    return null;
  }