/** No-arg constructor. Creates an empty clip at 8kHz sample rate. */ public AudioData() { this.format = new AudioFormat(8000f, 16, // sample size in bits 1, // mono true, // signed false); // little endian shorts = new short[0]; }
public AudioFormat getAudioFormat() { return new AudioFormat(Float.parseFloat((String) cbSamplingRate.getSelectedItem()), Integer.parseInt((String) cbBitsPerSample.getSelectedItem()), ((String) cbMonoStereo.getSelectedItem()).equals("mono") ? 1 : 2, true, // signed false); // little-endian }
private static AudioFormat getTestAudioFormat() { float sampleRate = 16000; // 8000,11025,16000,22050,44100,48000 int sampleSizeInBits = 16; // 8,16 int channels = 1; // 1,2 boolean signed = true; // true,false boolean bigEndian = false; // true,false AudioFormat af = new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian); return af; }
/** * Writes the temporary file with the generated audio. * * @param inputStream input stream with the waveform * @param length length of the waveform * @return name of the generated temporary file * @throws IOException */ private static String writeWav(InputStream inputStream, int length) throws IOException { AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, SAMPLE_RATE, 8, 1, 1, SAMPLE_RATE, false); File file = File.createTempFile("wav", "."); AudioSystem.write(new AudioInputStream(inputStream, format, length), AudioFileFormat.Type.WAVE, file); return file.getAbsolutePath(); } }
public static AudioFormat getMP3AudioFormat() { return new AudioFormat(new AudioFormat.Encoding("MPEG1L3"), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, 1, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false); // endianness doesn't matter }
public static AudioFormat getMP3AudioFormat() { return new AudioFormat(new AudioFormat.Encoding("MPEG1L3"), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, 1, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false); // endianness doesn't matter }
public static AudioFormat getOggAudioFormat() { return new AudioFormat(new AudioFormat.Encoding("VORBIS"), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, 1, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false); }
public static AudioFormat getOggAudioFormat() { return new AudioFormat(new AudioFormat.Encoding("VORBIS"), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, 1, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false); }
public JavaSoundAudioRecorder (int samplingRate, boolean isMono) { try { AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, samplingRate, 16, isMono ? 1 : 2, isMono ? 2 : 4, samplingRate, false); line = AudioSystem.getTargetDataLine(format); line.open(format, buffer.length); line.start(); } catch (Exception ex) { throw new GdxRuntimeException("Error creating JavaSoundAudioRecorder.", ex); } }
public JavaSoundAudioRecorder (int samplingRate, boolean isMono) { try { AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, samplingRate, 16, isMono ? 1 : 2, isMono ? 2 : 4, samplingRate, false); line = AudioSystem.getTargetDataLine(format); line.open(format, buffer.length); line.start(); } catch (Exception ex) { throw new GdxRuntimeException("Error creating JavaSoundAudioRecorder.", ex); } }
public JavaSoundAudioRecorder (int samplingRate, boolean isMono) { try { AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, samplingRate, 16, isMono ? 1 : 2, isMono ? 2 : 4, samplingRate, false); line = AudioSystem.getTargetDataLine(format); line.open(format, buffer.length); line.start(); } catch (Exception ex) { throw new GdxRuntimeException("Error creating JavaSoundAudioRecorder.", ex); } }
public JavaSoundAudioRecorder (int samplingRate, boolean isMono) { try { AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, samplingRate, 16, isMono ? 1 : 2, isMono ? 2 : 4, samplingRate, false); line = AudioSystem.getTargetDataLine(format); line.open(format, buffer.length); line.start(); } catch (Exception ex) { throw new GdxRuntimeException("Error creating JavaSoundAudioRecorder.", ex); } }
private static void init() { try { // 44,100 samples per second, 16-bit audio, mono, signed PCM, little Endian AudioFormat format = new AudioFormat((float) SAMPLE_RATE, BITS_PER_SAMPLE, 1, true, false); DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); line = (SourceDataLine) AudioSystem.getLine(info); line.open(format, SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE); // the internal buffer is a fraction of the actual buffer size, this choice is arbitrary // it gets divided because we can't expect the buffered data to line up exactly with when // the sound card decides to push out its samples. buffer = new byte[SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE/3]; } catch (LineUnavailableException e) { System.out.println(e.getMessage()); } // no sound gets made before this call line.start(); }
public static void main(String[] args) throws Exception { double samplingRateFactor = Double.valueOf(args[0]).doubleValue(); for (int i = 1; i < args.length; i++) { AudioInputStream ais = AudioSystem.getAudioInputStream(new File(args[i])); AudioFormat af = new AudioFormat((int) (ais.getFormat().getSampleRate() * samplingRateFactor), ais.getFormat() .getSampleSizeInBits(), ais.getFormat().getChannels(), true, ais.getFormat().isBigEndian()); DDSAudioInputStream ais2 = new DDSAudioInputStream(new AudioDoubleDataSource(ais), af); String outFileName = args[i].substring(0, args[i].length() - 4) + "_child.wav"; AudioSystem.write(ais2, AudioFileFormat.Type.WAVE, new File(outFileName)); } } }
public void load(UnitDatabase unitDatabase) { this.database = unitDatabase; this.timeline = database.getAudioTimeline(); int sampleRate = timeline.getSampleRate(); this.audioformat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sampleRate, // samples per second 16, // bits per sample 1, // mono 2, // nr. of bytes per frame sampleRate, // nr. of frames per second true); // big-endian; this.unitToTimelineSampleRateFactor = sampleRate / (double) database.getUnitFileReader().getSampleRate(); }
public static void main(String[] args) throws Exception { double samplingRateFactor = Double.valueOf(args[0]).doubleValue(); for (int i = 1; i < args.length; i++) { AudioInputStream ais = AudioSystem.getAudioInputStream(new File(args[i])); AudioFormat af = new AudioFormat((int) (ais.getFormat().getSampleRate() * samplingRateFactor), ais.getFormat() .getSampleSizeInBits(), ais.getFormat().getChannels(), true, ais.getFormat().isBigEndian()); DDSAudioInputStream ais2 = new DDSAudioInputStream(new AudioDoubleDataSource(ais), af); String outFileName = args[i].substring(0, args[i].length() - 4) + "_child.wav"; AudioSystem.write(ais2, AudioFileFormat.Type.WAVE, new File(outFileName)); } } }
public void load(UnitDatabase unitDatabase) { this.database = unitDatabase; this.timeline = database.getAudioTimeline(); int sampleRate = timeline.getSampleRate(); this.audioformat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sampleRate, // samples per second 16, // bits per sample 1, // mono 2, // nr. of bytes per frame sampleRate, // nr. of frames per second true); // big-endian; this.unitToTimelineSampleRateFactor = sampleRate / (double) database.getUnitFileReader().getSampleRate(); }
@Test public void testMP3Available() throws Exception { AudioFormat mp3af = new AudioFormat(new AudioFormat.Encoding("MPEG1L3"), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, 1, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false); AudioInputStream waveStream = AudioSystem.getAudioInputStream(this.getClass().getResourceAsStream("test.wav")); // Now attempt conversion: if (MaryRuntimeUtils.canCreateMP3()) { assertTrue(AudioSystem.isConversionSupported(mp3af, waveStream.getFormat())); AudioInputStream mp3Stream = AudioSystem.getAudioInputStream(mp3af, waveStream); } else { assertFalse(AudioSystem.isConversionSupported(mp3af, waveStream.getFormat())); } } }
@Test public void testGetAllData1() { int samplingRate = 16000; AudioFormat af = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, samplingRate, 16, 1, 2, samplingRate, false); double[] testSignal = FFTTest.getSampleSignal(16000); DDSAudioInputStream ais = new DDSAudioInputStream(new BufferedDoubleDataSource(testSignal), af); double[] result = new AudioDoubleDataSource(ais).getAllData(); Assert.assertTrue(result.length == testSignal.length); }
@Test public void testGetAllData2() { int samplingRate = 16000; AudioFormat af = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, samplingRate, 16, 1, 2, samplingRate, false); double[] signal = FFTTest.getSampleSignal(16000); DDSAudioInputStream ais = new DDSAudioInputStream(new BufferedDoubleDataSource(signal), af); double[] result = new AudioDoubleDataSource(ais).getAllData(); double err = MathUtils.sumSquaredError(signal, result); Assert.assertTrue("Error: " + err, err < 1.E-20); }