public static void main(String[] args) { try { // final Video<MBFImage> video = new VideoCapture(320, 240); final JavaSoundAudioGrabber audio = new JavaSoundAudioGrabber(new AudioFormat(16, 44.1, 2)); audio.setMaxBufferSize(1024); new Thread(audio).start(); Thread.sleep(100); // final VideoDisplay<MBFImage> display = // VideoDisplay.createVideoDisplay(video, audio); new Thread(new AudioPlayer(audio)).start(); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
/** * Open a line to the Java Sound APIs. * * @throws Exception * if the Java sound system could not be initialised. */ private void openJavaSound() throws Exception { // Convert the OpenIMAJ audio format to a Java Sound audio format object final javax.sound.sampled.AudioFormat audioFormat = new javax.sound.sampled.AudioFormat( (int) (this.getFormat().getSampleRateKHz() * 1000), this .getFormat().getNBits(), this.getFormat() .getNumChannels(), this.getFormat().isSigned(), this .getFormat().isBigEndian()); System.out.println("Creating Java Sound Line with " + this.getFormat()); // Create info to create an output data line final DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat); try { // Get the output line to write to using the given // sample format we just created. this.mLine = (TargetDataLine) AudioSystem.getLine(info); // If no exception has been thrown we open the line. this.mLine.open(audioFormat); } catch (final LineUnavailableException e) { throw new Exception("Could not open Java Sound audio line for" + " the audio format " + this.getFormat()); } }
/** * Main method * * @param args * command-line args (not used) * @throws InterruptedException */ public static void main(final String[] args) throws InterruptedException { // Construct a new audio waveform visualisation final AudioSpectrogram aw = new AudioSpectrogram(440, 600); aw.showWindow("Spectrogram"); // Start a sound grabber that will grab from your default microphone final JavaSoundAudioGrabber jsag = new JavaSoundAudioGrabber(new AudioFormat(16, 44.1, 1)); new Thread(jsag).start(); // Wait until the grabber has started (sometimes it takes a while) while (jsag.isStopped()) Thread.sleep(50); // Then send each of the frames to the visualisation SampleChunk sc = null; while ((sc = jsag.nextSampleChunk()) != null) aw.setData(sc); } }
public void run() { try { this.openJavaSound(); final byte[] data = new byte[this.calculateBufferSize()]; this.fireAudioAvailable(); this.closeJavaSound(); System.out.println("Stopping java sound"); } catch (final Exception e) {
final JavaSoundAudioGrabber xa = new JavaSoundAudioGrabber(new AudioFormat(16, 44.1, 1)); xa.setMaxBufferSize(this.sampleChunkSize); new Thread(xa).start(); new HanningAudioProcessor(xa, this.img.getWidth() * xa.getFormat().getNumChannels())
final JavaSoundAudioGrabber xa = new JavaSoundAudioGrabber( new AudioFormat(16,44.1,1) ); new Thread(xa).start(); final FixedSizeSampleAudioProcessor fs = new FixedSizeSampleAudioProcessor( xa, 128 );
/** * {@inheritDoc} * * @see org.openimaj.audio.AudioStream#nextSampleChunk() */ @Override public SampleChunk nextSampleChunk() { synchronized (this.currentSample) { if (this.isStopped()) return null; try { this.currentSample.wait(); } catch (final InterruptedException e) { e.printStackTrace(); } return this.currentSample; } }
final JavaSoundAudioGrabber xa = new JavaSoundAudioGrabber(new AudioFormat(16, 44.1, 1)); xa.setMaxBufferSize(this.sampleChunkSize); new Thread(xa).start(); new HanningAudioProcessor(xa, this.img.getWidth() * xa.getFormat().getNumChannels())
final JavaSoundAudioGrabber xa = new JavaSoundAudioGrabber( new AudioFormat(16,44.1,1) ); new Thread(xa).start(); final FixedSizeSampleAudioProcessor fs = new FixedSizeSampleAudioProcessor( xa, 128 );
public void run() { try { this.openJavaSound(); final byte[] data = new byte[this.calculateBufferSize()]; this.fireAudioAvailable(); this.closeJavaSound(); System.out.println("Stopping java sound"); } catch (final Exception e) {
/** * {@inheritDoc} * * @see org.openimaj.audio.AudioStream#nextSampleChunk() */ @Override public SampleChunk nextSampleChunk() { synchronized (this.currentSample) { if (this.isStopped()) return null; try { this.currentSample.wait(); } catch (final InterruptedException e) { e.printStackTrace(); } return this.currentSample; } }
public static void main(String[] args) { try { // final Video<MBFImage> video = new VideoCapture(320, 240); final JavaSoundAudioGrabber audio = new JavaSoundAudioGrabber(new AudioFormat(16, 44.1, 2)); audio.setMaxBufferSize(1024); new Thread(audio).start(); Thread.sleep(100); // final VideoDisplay<MBFImage> display = // VideoDisplay.createVideoDisplay(video, audio); new Thread(new AudioPlayer(audio)).start(); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
final JavaSoundAudioGrabber jsag = new JavaSoundAudioGrabber( new AudioFormat( 16, 44.1, 1 ) ); new Thread( jsag ).start();
/** * Open a line to the Java Sound APIs. * * @throws Exception * if the Java sound system could not be initialised. */ private void openJavaSound() throws Exception { // Convert the OpenIMAJ audio format to a Java Sound audio format object final javax.sound.sampled.AudioFormat audioFormat = new javax.sound.sampled.AudioFormat( (int) (this.getFormat().getSampleRateKHz() * 1000), this .getFormat().getNBits(), this.getFormat() .getNumChannels(), this.getFormat().isSigned(), this .getFormat().isBigEndian()); System.out.println("Creating Java Sound Line with " + this.getFormat()); // Create info to create an output data line final DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat); try { // Get the output line to write to using the given // sample format we just created. this.mLine = (TargetDataLine) AudioSystem.getLine(info); // If no exception has been thrown we open the line. this.mLine.open(audioFormat); } catch (final LineUnavailableException e) { throw new Exception("Could not open Java Sound audio line for" + " the audio format " + this.getFormat()); } }
@Override public Component getComponent(final int width, final int height) throws IOException{ final Component comp = super.getComponent(width, height); this.xa = new JavaSoundAudioGrabber(new AudioFormat( 16, 96.1, 1 )); this.xa.setMaxBufferSize( this.sampleChunkSize ); new Thread( this.xa ).start(); this.source = new FrequencyAudioSource(this.xa); this.source.addFrequencyListener(this,new Pair<Integer>(30,3400)); this.spectra = null; return comp; }
final JavaSoundAudioGrabber jsag = new JavaSoundAudioGrabber( new AudioFormat( 16, 44.1, 1 ) ); new Thread( jsag ).start();
/** * From * http://www.javadocexamples.com/java_source/ccs/chaos/NoiseGrabber.java * .html Not sure if this will work for non 44.1KHz samples? * * @return */ private int calculateBufferSize() { final int nmax = (this.maxBufferSize == -1 ? this.mLine.getBufferSize() / 4 : this.maxBufferSize); final int[] FAC44100 = { 7, 7, 5, 5, 3, 3, 2, 2 }; int nwad = 1; for (int i = 0; i < 8; i++) if (nwad * FAC44100[i] <= nmax) nwad *= FAC44100[i]; return nwad << (this.getFormat().getNBits() / 8); }
/** * From * http://www.javadocexamples.com/java_source/ccs/chaos/NoiseGrabber.java * .html Not sure if this will work for non 44.1KHz samples? * * @return */ private int calculateBufferSize() { final int nmax = (this.maxBufferSize == -1 ? this.mLine.getBufferSize() / 4 : this.maxBufferSize); final int[] FAC44100 = { 7, 7, 5, 5, 3, 3, 2, 2 }; int nwad = 1; for (int i = 0; i < 8; i++) if (nwad * FAC44100[i] <= nmax) nwad *= FAC44100[i]; return nwad << (this.getFormat().getNBits() / 8); }