示例#1
1
  /**
   * @param filename the
   * @param is
   * @return
   */
  AudioInputStream getAudioInputStream(String filename) {
    AudioInputStream ais = null;
    BufferedInputStream bis = null;
    if (filename.startsWith("http")) {
      try {
        ais = getAudioInputStream(new URL(filename));
      } catch (MalformedURLException e) {
        error("Bad URL: " + e.getMessage());
      } catch (UnsupportedAudioFileException e) {
        error("URL is in an unsupported audio file format: " + e.getMessage());
      } catch (IOException e) {
        Sound.error("Error reading the URL: " + e.getMessage());
      }
    } else {
      try {
        // InputStream is = createInput(filename);
        InputStream is =
            new FileInputStream(filename) {

              @Override
              public int read() throws IOException {
                // TODO Auto-generated method stub
                return 0;
              }
            };

        debug("Base input stream is: " + is.toString());
        bis = new BufferedInputStream(is);
        ais = getAudioInputStream(bis);
        // don't mark it like this because it means the entire
        // file will be loaded into memory as it plays. this
        // will cause out-of-memory problems with very large files.
        // ais.mark((int)ais.available());
        debug(
            "Acquired AudioInputStream.\n"
                + "It is "
                + ais.getFrameLength()
                + " frames long.\n"
                + "Marking support: "
                + ais.markSupported());
      } catch (IOException ioe) {
        error("IOException: " + ioe.getMessage());
      } catch (UnsupportedAudioFileException uafe) {
        error("Unsupported Audio File: " + uafe.getMessage());
      }
    }
    return ais;
  }
示例#2
1
  /** Creates an AudioInputStream from a sound from an input stream */
  public AudioInputStream getAudioInputStream(InputStream is) {

    try {
      if (!is.markSupported()) {
        is = new BufferedInputStream(is);
      }
      // open the source stream
      AudioInputStream source = AudioSystem.getAudioInputStream(is);

      // convert to playback format
      return AudioSystem.getAudioInputStream(playbackFormat, source);
    } catch (UnsupportedAudioFileException ex) {
      ex.printStackTrace();
    } catch (IOException ex) {
      ex.printStackTrace();
    } catch (IllegalArgumentException ex) {
      ex.printStackTrace();
    }

    return null;
  }
示例#3
0
    public void run() {
      InputStream ins = GameScreen.class.getResourceAsStream("res/bgmusic.wav");
      AudioInputStream audioIn;
      // System.out.println(ins);

      try {
        clip = AudioSystem.getClip();
        audioIn = AudioSystem.getAudioInputStream(ins);
        clip.open(audioIn);
      } catch (UnsupportedAudioFileException e) {
        // ignore
        e.printStackTrace();
        return;
      } catch (IOException e) {
        // ignore
        e.printStackTrace();
        return;
      } catch (LineUnavailableException e) {
        // ignore
        e.printStackTrace();
        return;
      }
      // System.out.println("woohoo");

      clip.loop(Clip.LOOP_CONTINUOUSLY);
    }
  @Test
  public void testExtractFeaturesExtractsFeaturesCorrectly() {
    Word w = new Word(0, 1, "test");
    regions.add(w);

    WavReader reader = new WavReader();
    WavData wav = null;
    try {
      wav = reader.read(TEST_DIR + "/bdc-test.wav");
    } catch (UnsupportedAudioFileException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (AuToBIException e) {
      e.printStackTrace();
    }
    w.setAttribute("wav", wav);

    try {
      fe.extractFeatures(regions);
      Spectrum s = (Spectrum) w.getAttribute("spectrum");
      assertEquals(835, s.numFrames());
      assertEquals(256, s.numFreqs());
      // Assume that the spectrum extraction algorithm is tested in SpectrumExtractor.
      // Here we'll make sure that the generated spectrum passes some sanity checks.
    } catch (FeatureExtractorException e) {
      fail();
    }
  }
示例#5
0
 private Map<String, Object> getID3Tags(String filename) {
   debug("Getting the properties.");
   Map<String, Object> props = new HashMap<String, Object>();
   try {
     MpegAudioFileReader reader = new MpegAudioFileReader(this);
     // InputStream stream = createInput(filename);
     InputStream stream = new FileInputStream(filename);
     AudioFileFormat baseFileFormat = reader.getAudioFileFormat(stream, stream.available());
     stream.close();
     if (baseFileFormat instanceof TAudioFileFormat) {
       TAudioFileFormat fileFormat = (TAudioFileFormat) baseFileFormat;
       props = fileFormat.properties();
       if (props.size() == 0) {
         error("No file properties available for " + filename + ".");
       } else {
         debug("File properties: " + props.toString());
       }
     }
   } catch (UnsupportedAudioFileException e) {
     error("Couldn't get the file format for " + filename + ": " + e.getMessage());
   } catch (IOException e) {
     error("Couldn't access " + filename + ": " + e.getMessage());
   }
   return props;
 }
  /**
   * Sets the audio file from which the data-stream will be generated of.
   *
   * @param audioFileURL The location of the audio file to use
   * @param streamName The name of the InputStream. if <code>null</code> the complete path of the
   *     audio file will be uses as stream name.
   */
  public void setAudioFile(URL audioFileURL, String streamName) {
    // first close the last stream if there's such a one
    if (dataStream != null) {
      try {
        dataStream.close();
      } catch (IOException e) {
        e.printStackTrace();
      }

      dataStream = null;
    }

    assert audioFileURL != null;
    if (streamName != null) streamName = audioFileURL.getPath();

    AudioInputStream audioStream = null;
    try {
      audioStream = AudioSystem.getAudioInputStream(audioFileURL);
    } catch (UnsupportedAudioFileException e) {
      System.err.println("Audio file format not supported: " + e);
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    curAudioFile = new File(audioFileURL.getFile());
    for (AudioFileProcessListener fileListener : fileListeners)
      fileListener.audioFileProcStarted(curAudioFile);

    setInputStream(audioStream, streamName);
  }
  @Test
  public void testExtractFeaturesExtractsFeatures() {
    Word w = new Word(0, 1, "test");
    regions.add(w);

    WavReader reader = new WavReader();
    WavData wav = null;
    try {
      wav = reader.read(TEST_DIR + "/test.wav");
    } catch (UnsupportedAudioFileException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (AuToBIException e) {
      e.printStackTrace();
    }
    w.setAttribute("wav", wav);

    try {
      fe.extractFeatures(regions);
      assertTrue(w.hasAttribute("spectrum"));
    } catch (FeatureExtractorException e) {
      fail();
    }
  }
示例#8
0
  @Override
  public void run() {
    running = true;
    done = false;
    Log.println("WAV Source START");
    if (audioStream == null)
      try {
        initWav();
      } catch (UnsupportedAudioFileException e1) {
        Log.errorDialog("ERROR", "Unsupported File Format\n" + e1.getMessage());
        e1.printStackTrace(Log.getWriter());
        running = false;
      } catch (IOException e1) {
        Log.errorDialog("ERROR", "There was a problem opening the wav file\n" + e1.getMessage());
        e1.printStackTrace(Log.getWriter());
        running = false;
      }

    while (running) {
      //			Log.println("wav running");
      if (audioStream != null) {
        int nBytesRead = 0;
        if (circularBuffer.getCapacity() > readBuffer.length) {
          try {
            nBytesRead = audioStream.read(readBuffer, 0, readBuffer.length);
            bytesRead = bytesRead + nBytesRead;
            framesProcessed = framesProcessed + nBytesRead / frameSize;
            // Check we have not stopped mid read
            if (audioStream == null) running = false;
            else if (!(audioStream.available() > 0)) running = false;
          } catch (IOException e) {
            Log.errorDialog("ERROR", "Failed to read from file " + fileName);
            e.printStackTrace(Log.getWriter());
          }
        } else {
          try {
            Thread.sleep(1);
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          // Log.println("No room in Buffer");
        }
        for (int i = 0; i < nBytesRead; i += 2) {
          // circularBuffer.add(readBuffer[i]);
          circularBuffer.add(readBuffer[i], readBuffer[i + 1]);
        }
      }
    }
    framesProcessed = totalFrames;
    cleanup(); // This might cause the decoder to miss the end of a file (testing inconclusive) but
               // it also ensure the file is close and stops an error if run again very quickly
    running = false;
    try {
      Thread.sleep(100);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    Log.println("WAV Source EXIT");
  }
示例#9
0
  // return data as a byte array
  private byte[] readByte(String filename) {
    byte[] data = null;
    AudioInputStream ais = null;
    try {

      // try to read from file
      File file = new File(filename);
      if (file.exists()) {
        ais = AudioSystem.getAudioInputStream(file);
        data = new byte[ais.available()];
        ais.read(data);
      }

      // try to read from URL
      else {
        URL url = StdAudio.class.getResource(filename);
        ais = AudioSystem.getAudioInputStream(url);
        data = new byte[ais.available()];
        ais.read(data);
      }
    } catch (IOException e) {
      System.out.println(e.getMessage());
      throw new RuntimeException("Could not read " + filename);
    } catch (UnsupportedAudioFileException e) {
      System.out.println(e.getMessage());
      throw new RuntimeException(filename + " in unsupported audio format");
    }

    return data;
  }
示例#10
0
 @ActionDoc(text = "plays a sound from the sounds folder")
 public static void playSound(
     @ParamDoc(name = "filename", text = "the filename with extension") String filename) {
   try {
     InputStream is = new FileInputStream(SOUND_DIR + File.separator + filename);
     if (filename.toLowerCase().endsWith(".mp3")) {
       Player player = new Player(is);
       playInThread(player);
     } else {
       AudioInputStream ais = AudioSystem.getAudioInputStream(is);
       Clip clip = AudioSystem.getClip();
       clip.open(ais);
       playInThread(clip);
     }
   } catch (FileNotFoundException e) {
     logger.error("Cannot play sound '{}': {}", new String[] {filename, e.getMessage()});
   } catch (JavaLayerException e) {
     logger.error("Cannot play sound '{}': {}", new String[] {filename, e.getMessage()});
   } catch (UnsupportedAudioFileException e) {
     logger.error(
         "Format of sound file '{}' is not supported: {}",
         new String[] {filename, e.getMessage()});
   } catch (IOException e) {
     logger.error("Cannot play sound '{}': {}", new String[] {filename, e.getMessage()});
   } catch (LineUnavailableException e) {
     logger.error("Cannot play sound '{}': {}", new String[] {filename, e.getMessage()});
   }
 }
示例#11
0
    protected void startFile(File file) {
      currentFile = file;
      AudioFormat format;
      try {
        format = AudioSystem.getAudioFileFormat(file).getFormat();
        float samplerate = format.getSampleRate();
        int size = 1024;
        int overlap = 0;

        PitchResyntheziser prs = new PitchResyntheziser(samplerate);
        estimationGain = new GainProcessor(estimationGainSlider.getValue() / 100.0);
        estimationDispatcher = AudioDispatcher.fromFile(file, size, overlap);
        estimationDispatcher.addAudioProcessor(new PitchProcessor(algo, samplerate, size, prs));
        estimationDispatcher.addAudioProcessor(estimationGain);
        estimationDispatcher.addAudioProcessor(new AudioPlayer(format));

        sourceGain = new GainProcessor(sourceGainSlider.getValue() / 100.0);
        sourceDispatcher = AudioDispatcher.fromFile(file, size, overlap);
        sourceDispatcher.addAudioProcessor(sourceGain);
        sourceDispatcher.addAudioProcessor(new AudioPlayer(format));

        new Thread(estimationDispatcher).start();
        new Thread(sourceDispatcher).start();

      } catch (UnsupportedAudioFileException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (LineUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  public void testPropertiesFile() {
    String[] testPropsAFF = {
      "duration",
      "title",
      "author",
      "album",
      "date",
      "comment",
      "copyright",
      "ogg.bitrate.min",
      "ogg.bitrate.nominal",
      "ogg.bitrate.max"
    };
    String[] testPropsAF = {"vbr", "bitrate"};

    File file = new File(filename);
    AudioFileFormat baseFileFormat = null;
    AudioFormat baseFormat = null;
    try {
      baseFileFormat = AudioSystem.getAudioFileFormat(file);
      baseFormat = baseFileFormat.getFormat();
      if (out != null) out.println("-> Filename : " + filename + " <-");
      if (out != null) out.println(baseFileFormat);
      if (baseFileFormat instanceof TAudioFileFormat) {
        Map properties = ((TAudioFileFormat) baseFileFormat).properties();
        if (out != null) out.println(properties);
        for (int i = 0; i < testPropsAFF.length; i++) {
          String key = testPropsAFF[i];
          if (properties.get(key) != null) {
            String val = (properties.get(key)).toString();
            // if (out != null)  out.println(key+"="+val);
            String valexpected = props.getProperty(key);
            // assertEquals(key,valexpected,val);
          }
        }
      } else {
        assertTrue("testPropertiesFile : TAudioFileFormat expected", false);
      }

      if (baseFormat instanceof TAudioFormat) {
        Map properties = ((TAudioFormat) baseFormat).properties();
        for (int i = 0; i < testPropsAF.length; i++) {
          String key = testPropsAF[i];
          if (properties.get(key) != null) {
            String val = (properties.get(key)).toString();
            if (out != null) out.println(key + "=" + val);
            String valexpected = props.getProperty(key);
            // assertEquals(key,valexpected,val);
          }
        }
      } else {
        assertTrue("testPropertiesFile : TAudioFormat expected", false);
      }
    } catch (UnsupportedAudioFileException e) {
      assertTrue("testPropertiesFile : " + e.getMessage(), false);
    } catch (IOException e) {
      assertTrue("testPropertiesFile : " + e.getMessage(), false);
    }
  }
示例#13
0
  public void run() {

    File soundFile = new File(filename);
    if (!soundFile.exists()) {
      System.err.println("Wave file not found: " + filename);
      Dialog.erreur(null, "Le fichier " + filename + " n'a pas été trouver.");
      return;
    }

    AudioInputStream audioInputStream = null;
    try {
      audioInputStream = AudioSystem.getAudioInputStream(soundFile);
    } catch (UnsupportedAudioFileException e1) {
      e1.printStackTrace();
      return;
    } catch (IOException e1) {
      e1.printStackTrace();
      return;
    }

    AudioFormat format = audioInputStream.getFormat();
    SourceDataLine auline = null;
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

    try {
      auline = (SourceDataLine) AudioSystem.getLine(info);
      auline.open(format);
    } catch (LineUnavailableException e) {
      e.printStackTrace();
      return;
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    if (auline.isControlSupported(FloatControl.Type.PAN)) {
      FloatControl pan = (FloatControl) auline.getControl(FloatControl.Type.PAN);
      if (curPosition == Position.RIGHT) pan.setValue(1.0f);
      else if (curPosition == Position.LEFT) pan.setValue(-1.0f);
    }

    auline.start();
    int nBytesRead = 0;
    byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];

    try {
      while (nBytesRead != -1) {
        nBytesRead = audioInputStream.read(abData, 0, abData.length);
        if (nBytesRead >= 0) auline.write(abData, 0, nBytesRead);
      }
    } catch (IOException e) {
      e.printStackTrace();
      return;
    } finally {
      auline.drain();
      auline.close();
    }
  }
示例#14
0
  public void run() {

    File soundFile = new File(this.filename);
    if (!soundFile.exists()) {
      System.err.println("nicht gefunden: " + filename);
      return;
    }

    AudioInputStream audioInputStream = null;
    try {
      audioInputStream = AudioSystem.getAudioInputStream(soundFile);
    } catch (UnsupportedAudioFileException e1) {
      e1.printStackTrace();
      return;
    } catch (IOException e1) {
      e1.printStackTrace();
      return;
    }

    AudioFormat format = audioInputStream.getFormat();
    SourceDataLine auline = null;
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

    try {
      auline = (SourceDataLine) AudioSystem.getLine(info);
      auline.open(format);
    } catch (LineUnavailableException e) {
      e.printStackTrace();
      return;
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    FloatControl rate = (FloatControl) auline.getControl(FloatControl.Type.SAMPLE_RATE);

    rate.setValue(rate.getValue() * 5f);

    auline.start();
    int nBytesRead = 0;
    byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];

    try {
      while (nBytesRead != -1) {
        nBytesRead = audioInputStream.read(abData, 0, abData.length);
        if (nBytesRead >= 0) auline.write(abData, 0, nBytesRead);
      }
    } catch (IOException e) {
      e.printStackTrace();
      return;
    } finally {
      auline.drain();
      auline.close();
    }
  }
示例#15
0
 /** @param filename le lien vers le fichier song (URL ou absolute path) */
 public SoundServer(String filename) {
   try {
     AudioInputStream stream = AudioSystem.getAudioInputStream(new File(filename));
     format = stream.getFormat();
     samples = getSamples(stream);
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
示例#16
0
 @Override
 public void actionPerformed(final ActionEvent e) {
   String name = e.getActionCommand();
   PitchEstimationAlgorithm newAlgo = PitchEstimationAlgorithm.valueOf(name);
   algo = newAlgo;
   try {
     setNewMixer(currentMixer);
   } catch (LineUnavailableException e1) {
     e1.printStackTrace();
   } catch (UnsupportedAudioFileException e1) {
     e1.printStackTrace();
   }
 }
示例#17
0
 /** Load all sounds */
 private static void load() {
   loaded = true;
   try {
     startSound = Resources.loadSound("/sounds/start.wav");
     backgroundSound = Resources.loadSound("/sounds/background.wav");
     placeholderSound = Resources.loadSound("/sounds/placeholder.wav");
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (LineUnavailableException e) {
     e.printStackTrace();
   }
 }
示例#18
0
  public WavEffect(String fileName) {
    URL url = getClass().getResource("/audios/" + fileName);
    try {
      clip = AudioSystem.getClip();
      AudioInputStream input = AudioSystem.getAudioInputStream(url);
      clip.open(input);

    } catch (LineUnavailableException e) {
      e.printStackTrace();
    } catch (UnsupportedAudioFileException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
示例#19
0
 public static void ScoreUp() {
   try {
     AudioInputStream audioIn;
     Clip clip;
     clip = AudioSystem.getClip();
     audioIn = AudioSystem.getAudioInputStream(Main.class.getResource("/Sounds/Score.wav"));
     clip.open(audioIn);
     clip.start();
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (LineUnavailableException e) {
     e.printStackTrace();
   }
 }
示例#20
0
  private void sound(String nameSound) {
    Clip clip;
    try {

      clip = AudioSystem.getClip();
      clip.open(AudioSystem.getAudioInputStream(new File("resource/fileSound/" + nameSound)));
      clip.start();

    } catch (UnsupportedAudioFileException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (LineUnavailableException e) {
      e.printStackTrace();
    }
  }
 /**
  * for extracting amplitude array the format we are using :16bit, 22khz, 1 channel, littleEndian,
  *
  * @return PCM audioData
  * @throws Exception
  */
 public float[] extractAmplitudeFromFileByteArrayInputStream(ByteArrayInputStream bis) {
   try {
     audioInputStream = AudioSystem.getAudioInputStream(bis);
   } catch (UnsupportedAudioFileException e) {
     System.out.println("unsupported file type, during extract amplitude");
     e.printStackTrace();
   } catch (IOException e) {
     System.out.println("IOException during extracting amplitude");
     e.printStackTrace();
   }
   float milliseconds =
       (long)
           ((audioInputStream.getFrameLength() * 1000)
               / audioInputStream.getFormat().getFrameRate());
   durationSec = milliseconds / 1000.0;
   return extractFloatDataFromAudioInputStream(audioInputStream);
 }
示例#22
0
 @SuppressWarnings("static-access")
 private void PlayMusic() {
   try {
     AudioInputStream audioIn;
     Clip clip;
     clip = AudioSystem.getClip();
     audioIn = AudioSystem.getAudioInputStream(this.getClass().getResource("/Sounds/Main.wav"));
     clip.open(audioIn);
     clip.start();
     clip.loop(clip.LOOP_CONTINUOUSLY);
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (LineUnavailableException e) {
     e.printStackTrace();
   }
 }
示例#23
0
 // Constructor to construct each element of the enum with its own sound file.
 SoundEffect(String soundFileName) {
   try {
     // Use URL (instead of File) to read from disk and JAR.
     URL url = this.getClass().getClassLoader().getResource(soundFileName);
     // Set up an audio input stream piped from the sound file.
     AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
     // Get a clip resource.
     clip = AudioSystem.getClip();
     // Open audio clip and load samples from the audio input stream.
     clip.open(audioInputStream);
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (LineUnavailableException e) {
     e.printStackTrace();
   }
 }
 public static void Play() {
   try {
     // Open an audio input stream.
     File soundFile = new File("foo.wav");
     AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);
     // Get a sound clip resource.
     Clip clip = AudioSystem.getClip();
     // Open audio clip and load samples from the audio input stream.
     clip.open(audioIn);
     clip.start();
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (LineUnavailableException e) {
     e.printStackTrace();
   }
 }
示例#25
0
 public void testPropertiesShoutcast() {
   AudioFileFormat baseFileFormat = null;
   AudioFormat baseFormat = null;
   String shoutURL = (String) props.getProperty("shoutcast");
   try {
     URL url = new URL(shoutURL);
     baseFileFormat = AudioSystem.getAudioFileFormat(url);
     baseFormat = baseFileFormat.getFormat();
     if (out != null) out.println("-> URL : " + url.toString() + " <-");
     if (out != null) out.println(baseFileFormat);
     if (baseFileFormat instanceof TAudioFileFormat) {
       Map properties = ((TAudioFileFormat) baseFileFormat).properties();
       Iterator it = properties.keySet().iterator();
       while (it.hasNext()) {
         String key = (String) it.next();
         String val = null;
         if (properties.get(key) != null) val = (properties.get(key)).toString();
         if (out != null) out.println(key + "='" + val + "'");
       }
     } else {
       assertTrue("testPropertiesShoutcast : TAudioFileFormat expected", false);
     }
     if (baseFormat instanceof TAudioFormat) {
       Map properties = ((TAudioFormat) baseFormat).properties();
       Iterator it = properties.keySet().iterator();
       while (it.hasNext()) {
         String key = (String) it.next();
         String val = null;
         if (properties.get(key) != null) val = (properties.get(key)).toString();
         if (out != null) out.println(key + "='" + val + "'");
       }
     } else {
       assertTrue("testPropertiesShoutcast : TAudioFormat expected", false);
     }
   } catch (UnsupportedAudioFileException e) {
     assertTrue("testPropertiesShoutcast : " + e.getMessage(), false);
   } catch (IOException e) {
     assertTrue("testPropertiesShoutcast : " + e.getMessage(), false);
   }
 }
示例#26
0
  public void _testDumpPropertiesFile() {
    File file = new File(filename);
    AudioFileFormat baseFileFormat = null;
    AudioFormat baseFormat = null;
    try {
      baseFileFormat = AudioSystem.getAudioFileFormat(file);
      baseFormat = baseFileFormat.getFormat();
      if (out != null) out.println("-> Filename : " + filename + " <-");
      if (baseFileFormat instanceof TAudioFileFormat) {
        Map properties = ((TAudioFileFormat) baseFileFormat).properties();
        Iterator it = properties.keySet().iterator();
        while (it.hasNext()) {
          String key = (String) it.next();
          String val = (properties.get(key)).toString();
          if (out != null) out.println(key + "='" + val + "'");
        }
      } else {
        assertTrue("testDumpPropertiesFile : TAudioFileFormat expected", false);
      }

      if (baseFormat instanceof TAudioFormat) {
        Map properties = ((TAudioFormat) baseFormat).properties();
        Iterator it = properties.keySet().iterator();
        while (it.hasNext()) {
          String key = (String) it.next();
          String val = (properties.get(key)).toString();
          if (out != null) out.println(key + "='" + val + "'");
        }
      } else {
        assertTrue("testDumpPropertiesFile : TAudioFormat expected", false);
      }
    } catch (UnsupportedAudioFileException e) {
      assertTrue("testDumpPropertiesFile : " + e.getMessage(), false);
    } catch (IOException e) {
      assertTrue("testDumpPropertiesFile : " + e.getMessage(), false);
    }
  }
示例#27
0
  public void run() {

    try {
      player.open("/Users/apurvaj/Desktop/0.wav");
      long start = 0;

      while (!finish) {
        player.playAt(start);
        synchronized (obj) {
          try {
            obj.wait(100);
          } catch (InterruptedException e) {
            System.out.println("Here");
            e.printStackTrace();
          }
        }

        start = player.stop();
        synchronized (obj) {
          try {
            obj.wait(100);
          } catch (InterruptedException e) {
            System.out.println("Here");
            e.printStackTrace();
          }
        }
      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (UnsupportedAudioFileException e) {
      e.printStackTrace();
    }
  }
示例#28
0
 /** @see com.groovemanager.sampled.AudioPlayerProvider#startRec() */
 public AudioFormat startRec() throws NotReadyException {
   tabItem
       .getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               waveDisplay.scroll(1);
             }
           });
   try {
     out =
         AudioManager.getDefault()
             .getAudioFileOutputStream(
                 source, format, AudioFileFormat.Type.WAVE, null, null, null);
   } catch (IOException e) {
     e.printStackTrace();
     throw new NotReadyException(e.getMessage());
   } catch (UnsupportedAudioFileException e) {
     e.printStackTrace();
     throw new NotReadyException(e.getMessage());
   }
   recording = true;
   return format;
 }
示例#29
0
 /** @see com.groovemanager.sampled.AudioPlayerProvider#stopRec() */
 public void stopRec() {
   modified = true;
   canRec = false;
   recording = false;
   try {
     out.close();
     File tempPeak = File.createTempFile("gmtmp_", ".gmpk");
     ((DynamicPeakWaveForm) afWF.getPeakWaveForm()).close(source.lastModified());
     try {
       AudioFileWaveForm aw = new AudioFileWaveForm(source, afWF.getPeakWaveForm(), 32 * 1024, 25);
       fileFormat = AudioSystem.getAudioFileFormat(source);
       cutList.setSource(new AudioFileSource(source, aw));
       waveDisplay.showAll();
     } catch (UnsupportedAudioFileException e1) {
       e1.printStackTrace();
       editor.errorMessage(e1.getMessage());
     }
     this.editor.player.setProvider(this);
   } catch (IOException e) {
     e.printStackTrace();
     editor.errorMessage(e.getMessage());
   }
   editor.zoomWaveDisplay.setSource(this);
 }
示例#30
0
  public void testPropertiesFile() {
    String[] testPropsAFF = {
      "duration",
      "title",
      "author",
      "album",
      "date",
      "comment",
      "copyright",
      "mp3.framerate.fps",
      "mp3.copyright",
      "mp3.padding",
      "mp3.original",
      "mp3.length.bytes",
      "mp3.frequency.hz",
      "mp3.length.frames",
      "mp3.mode",
      "mp3.channels",
      "mp3.version.mpeg",
      "mp3.framesize.bytes",
      "mp3.vbr.scale",
      "mp3.version.encoding",
      "mp3.header.pos",
      "mp3.version.layer",
      "mp3.crc"
    };
    String[] testPropsAF = {"vbr", "bitrate"};

    File file = new File(filename);
    AudioFileFormat baseFileFormat = null;
    AudioFormat baseFormat = null;
    try {
      baseFileFormat = AudioSystem.getAudioFileFormat(file);
      baseFormat = baseFileFormat.getFormat();
      if (out != null) out.println("-> Filename : " + filename + " <-");
      if (out != null) out.println(baseFileFormat);
      if (baseFileFormat instanceof TAudioFileFormat) {
        Map properties = ((TAudioFileFormat) baseFileFormat).properties();
        if (out != null) out.println(properties);
        for (int i = 0; i < testPropsAFF.length; i++) {
          String key = testPropsAFF[i];
          String val = null;
          if (properties.get(key) != null) val = (properties.get(key)).toString();
          if (out != null) out.println(key + "='" + val + "'");
          String valexpected = props.getProperty(key);
          assertEquals(key, valexpected, val);
        }
      } else {
        assertTrue("testPropertiesFile : TAudioFileFormat expected", false);
      }

      if (baseFormat instanceof TAudioFormat) {
        Map properties = ((TAudioFormat) baseFormat).properties();
        for (int i = 0; i < testPropsAF.length; i++) {
          String key = testPropsAF[i];
          String val = null;
          if (properties.get(key) != null) val = (properties.get(key)).toString();
          if (out != null) out.println(key + "='" + val + "'");
          String valexpected = props.getProperty(key);
          assertEquals(key, valexpected, val);
        }
      } else {
        assertTrue("testPropertiesFile : TAudioFormat expected", false);
      }
    } catch (UnsupportedAudioFileException e) {
      assertTrue("testPropertiesFile : " + e.getMessage(), false);
    } catch (IOException e) {
      assertTrue("testPropertiesFile : " + e.getMessage(), false);
    }
  }