Package javax.sound.sampled

Examples of javax.sound.sampled.AudioInputStream$TargetDataLineInputStream


            throws Exception {
        // Extract samples from samples field if only one channel present
        double[][] samples_to_convert = getSamplesChannelSegregated(start_sample, end_sample);

        // Convert to an AudioInputStream
        AudioInputStream audio_input_stream
                = org.vocvark.jAudioTools.AudioMethods.convertToAudioInputStream(samples_to_convert, audio_format);

        // Return the resuls
        return audio_input_stream;
    }
View Full Code Here


            throws Exception {
        // Extract samples from samples field if only one channel present
        double[][] samples_to_convert = getSamplesChannelSegregated(start_time, end_time);

        // Convert to an AudioInputStream
        AudioInputStream audio_input_stream
                = org.vocvark.jAudioTools.AudioMethods.convertToAudioInputStream(samples_to_convert, audio_format);

        // Return the resuls
        return audio_input_stream;
    }
View Full Code Here

        // Normalize the file if requested and if necessary
        if (normalize_if_clipped)
            normalizeIfClipped();

        // Convert samples to an AudioInputStream
        AudioInputStream audio_input_stream = null;
        if (multi_channel)
            audio_input_stream = getAudioInputStreamChannelSegregated();
        else
            audio_input_stream = getAudioInputStreamMixedDown();
View Full Code Here

    public static AudioInputStream getInputStream(ByteArrayOutputStream byte_stream,
                                                  AudioFormat audio_format) {
        byte audio_bytes[] = byte_stream.toByteArray();
        InputStream input_byte_stream = new ByteArrayInputStream(audio_bytes);
        long number_of_sample_frames = audio_bytes.length / audio_format.getFrameSize();
        return new AudioInputStream(input_byte_stream, audio_format, number_of_sample_frames);
    }
View Full Code Here

     */
    public static AudioInputStream getInputStream(byte[] audio_bytes,
                                                  AudioFormat audio_format) {
        InputStream input_byte_stream = new ByteArrayInputStream(audio_bytes);
        long number_of_sample_frames = audio_bytes.length / audio_format.getFrameSize();
        return new AudioInputStream(input_byte_stream, audio_format, number_of_sample_frames);
    }
View Full Code Here

     * @throws Exception    Throws informative exceptions if the file is invalid or has
     * an unsupported file format.
     */
    public static AudioInputStream getInputStream(File audio_file)
            throws Exception {
        AudioInputStream audio_input_stream = null;
        try {
            audio_input_stream = AudioSystem.getAudioInputStream(audio_file);
        } catch (UnsupportedAudioFileException ex) {
            throw new Exception("File " + audio_file.getName() + " has an unsupported audio format.");
        } catch (IOException ex) {
View Full Code Here

        int bytes_per_frame = audio_format.getFrameSize();
        long number_frames = (long) (number_bytes / bytes_per_frame);

        // Convert audio_buffer to an AudioInputStream
        ByteArrayInputStream bais = new ByteArrayInputStream(audio.toByteArray());
        AudioInputStream audio_input_stream = new AudioInputStream(bais, audio_format, number_frames);

        // Save audio to disk
        saveToFile(audio_input_stream, save_file, file_type);
    }
View Full Code Here

     * @throws Exception An exception is thrown if a problem occurs during file
     *                   reading or pre- processing.
     */
    private double[] preProcessRecording(File recordingFile) throws Exception {
        // Get the original audio and its format
        AudioInputStream originalStream = AudioSystem.getAudioInputStream(recordingFile);
        AudioFormat originalFormat = originalStream.getFormat();

        // Set the bit depth
        int bitDepth = originalFormat.getSampleSizeInBits();
        if (bitDepth != 8 && bitDepth != 16) {
            bitDepth = 16;
        }

        // If the audio is not PCM signed big endian, then convert it to PCM
        // signed
        // This is particularly necessary when dealing with MP3s
        AudioInputStream secondStream = originalStream;
        if (originalFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED || !originalFormat.isBigEndian()) {
            AudioFormat newFormat = new AudioFormat(
                    AudioFormat.Encoding.PCM_SIGNED,
                    originalFormat.getSampleRate(),
                    bitDepth,
                    originalFormat.getChannels(),
                    originalFormat.getChannels() * (bitDepth / 8),
                    originalFormat.getSampleRate(),
                    true);
            secondStream = AudioSystem.getAudioInputStream(newFormat, originalStream);
        }

        // Convert to the set sampling rate, if it is not already at this
        // sampling rate.
        // Also, convert to an appropriate bit depth if necessary.
        AudioInputStream newStream = secondStream;
        if (originalFormat.getSampleRate() !=  settings.getSamplingRate().floatValue()
                || bitDepth != originalFormat.getSampleSizeInBits() ) {
            AudioFormat newFormat = new AudioFormat(
                    AudioFormat.Encoding.PCM_SIGNED,
                    settings.getSamplingRate().floatValue(),
View Full Code Here

    }
    return 0;
  }
  public AmplitudeAudioInputStream getStream() throws IOException,UnsupportedAudioFileException {
    if(stream==null){
      AudioInputStream  streamInput=null;
      if(file!=null){
        streamInput=AudioSystem.getAudioInputStream(file);
      }else if(url!=null){
        streamInput=AudioSystem.getAudioInputStream(url);
      }else{
        throw new IOException("url/source is missing!");
      }
          AudioFormat  decodedFormat = new AudioFormat(
                  AudioFormat.Encoding.PCM_SIGNED,
                  streamInput.getFormat().getSampleRate(),
                  16,
                  streamInput.getFormat().getChannels(),
                  streamInput.getFormat().getChannels() * 2,
                  streamInput.getFormat().getSampleRate(),
                  false);
      stream=new AmplitudeAudioInputStream(AudioSystem.getAudioInputStream(decodedFormat,streamInput));
    }
    return stream;
  }
View Full Code Here

    public SoundPlayActivity() {
      super("Play Sound");
    }
  protected void executeActivity(ProcessInstance instance) throws Exception {
    AudioInputStream audioInputStream = null;
    SourceDataLine auline = null;

    try {
      try {
        File soundFile = this.getSoundFile().getFile();
        audioInputStream = AudioSystem.getAudioInputStream(soundFile);
      } catch (Exception e) {
        URL url = new URL(evaluateContent(instance, this.getSoundUrl()).toString());
        audioInputStream = AudioSystem.getAudioInputStream(url);
      }

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

      auline = (SourceDataLine) AudioSystem.getLine(info);
      auline.open(format);

      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];

      while (nBytesRead != -1) {
        nBytesRead = audioInputStream.read(abData, 0, abData.length);
        if (nBytesRead >= 0) {
          auline.write(abData, 0, nBytesRead);
        }
      }
     
      auline.drain();
     
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (auline != null) try { auline.close(); } catch (Exception e1) { }
      if (audioInputStream != null) try { audioInputStream.close(); } catch (Exception e1) { }
    }
    fireComplete(instance);

    }
View Full Code Here

TOP

Related Classes of javax.sound.sampled.AudioInputStream$TargetDataLineInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.