public void draw() { background(0); stroke(255); // perform a forward FFT on the samples in jingle's mix buffer, // which contains the mix of both the left and right channels of the file fft.forward(jingle.mix); for (int i = 0; i < fft.specSize(); i++) { // draw the line for frequency band i, scaling it up a bit so we can see it line(i, height / 2, i, height / 2 - fft.getBand(i) * 4); } stroke(255, 0, 0); for (int beat : beats) { float x = beat * width / totalSamples; line(x, 0, x, height); } stroke(255, 255, 0); float x = jingle.position() * width / jingle.length(); line(x, 0, x, height); image(preview, 0, 0); stroke(0, 255, 0); float s = (float) width / samples.length; line(loopStart * s, 0, loopStart * s, height); line(loopEnd * s, 0, loopEnd * s, height); }
/** * Test method for {@code AudioPlayer#play(URL)} * * @throws Exception audio fault exception, e.g. can't open stream, unhandleable audio format * @throws MalformedURLException wrong URL */ @Test(timeout = 4 * MAX_DURATION) public void testPlay() throws MalformedURLException, Exception { File wav1 = new File(TestUtils.getRegressionDataFile(6851, "20111003_121226.wav")); File wav2 = new File(TestUtils.getRegressionDataFile(6851, "20111003_121557.wav")); for (File w : new File[] {wav1, wav2}) { System.out.println("Playing " + w.toPath()); URL url = w.toURI().toURL(); long start = System.currentTimeMillis(); AudioPlayer.play(url); assertTrue(AudioPlayer.playing()); assertFalse(AudioPlayer.paused()); AudioPlayer.pause(); assertFalse(AudioPlayer.playing()); assertTrue(AudioPlayer.paused()); AudioPlayer.play(url, AudioPlayer.position()); while (AudioPlayer.playing() && (System.currentTimeMillis() - start) < MAX_DURATION) { Thread.sleep(500); } long duration = System.currentTimeMillis() - start; System.out.println("Play finished after " + Utils.getDurationString(duration)); assertTrue(duration < MAX_DURATION); AudioPlayer.reset(); Thread.sleep(1000); // precaution, see #13809 } }