Examples of AudioInputStream


Examples of javax.sound.sampled.AudioInputStream

    }

    // Get an input stream from an audio file
    public static AudioInputStream openInputStream(String filename, AudioFormat format) throws IOException, UnsupportedAudioFileException
    {
        AudioInputStream stream = null;

        stream = AudioSystem.getAudioInputStream(new File(filename));
        //System.out.println(stream.getFormat());
       
        AudioFormat baseFormat = stream.getFormat();
        AudioFormat decodedFormat =
            new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                            baseFormat.getSampleRate(),
                            16,
                            baseFormat.getChannels(),
                            baseFormat.getChannels() * 2,
                            baseFormat.getSampleRate(),
                            bigEndian);
        stream = AudioSystem.getAudioInputStream(decodedFormat, stream);
        //System.out.println(stream.getFormat());

        // convert to stereo PCM before converting to mono -
        // without this line the conversion process will crap out
        // on stereo MP3s.  But the conversion from mono to stereo
        // is unsupported for some reason...
        if(stream.getFormat().getChannels() >= 2)
            //stream = AudioSystem.getAudioInputStream(MEAPUtil.stereo, stream);
            stream = AudioSystem.getAudioInputStream(
                new AudioFormat(format.getSampleRate(), bitsPerSamp, 2,
                                signed, bigEndian),
                stream);
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

    /**
     * Load samples corresponding to this Chunk
     */
    public double[] getSamples(AudioFormat format) throws IOException, UnsupportedAudioFileException
    {
        AudioInputStream ais = MEAPUtil.openInputStream(srcFile, format);

        // this format had better match the output file format or we
        // have problems
        AudioFormat fmt = ais.getFormat();
       
        int frameSize = fmt.getFrameSize();
        float frameRate = fmt.getFrameRate();
       
        int startByte = (int)(startTime*frameRate*frameSize);
        int byteLen = (int)(length*frameRate*frameSize);
       
        byte[] bytes = new byte[byteLen];

        //System.out.print("getSamples: ais.skip: "+new Date()+" - ");
        ais.skip(startByte);
        //System.out.println(new Date());
        //System.out.print("getSamples: ais.read: "+new Date()+" - ");
        ais.read(bytes, 0, byteLen);
        //System.out.println(new Date());
        ais.close();
       
        double[] samples = new double[(int)(frameRate*length)];
        MEAPUtil.bytes2doubles(bytes, samples, fmt);

        return samples;
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

            FeatChunk ch = (FeatChunk)c.next();

            // let's get some new features
            if(!ch.srcFile.equals(lastAudioFile))
            {
                AudioInputStream ais = openInputStream(ch.srcFile);

                // resample to feSamplingRate
                AudioFormat fmt = new AudioFormat(feSamplingRate,
                                                  format.getSampleSizeInBits(),
                                                  format.getChannels(),
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

  @Override
  public void execute(QueryResult queryResult) {

    try {
      AudioInputStream ais;
      try {
        ais = AudioSystem.getAudioInputStream(PlayWavAction.class.getResource(this.wavFile));
      } catch(Exception e){
        ais = AudioSystem.getAudioInputStream(new File(PlayWavAction.class.getResource(this.wavFile).getFile()));
      }

      AudioFormat format = ais.getFormat();
      DataLine.Info info = new DataLine.Info(Clip.class, format);

      Clip clip = (Clip) AudioSystem.getLine(info);
      clip.open(ais);
      clip.start();
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

        if (!audio_file.exists())
            throw new Exception("File " + audio_file.getName() + " does not exist.");
        if (audio_file.isDirectory())
            throw new Exception("File " + audio_file.getName() + " is a directory.");

        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) {
            throw new Exception("File " + audio_file.getName() + " is not readable.");
        }

        AudioInputStream converted_audio = org.vocvark.jAudioTools.AudioMethods.getConvertedAudioStream(audio_input_stream);

        channel_samples = org.vocvark.jAudioTools.AudioMethods.extractSampleValues(converted_audio);

        samples = DSPMethods.getSamplesMixedDownIntoOneChannel(channel_samples);

        if (channel_samples.length == 1)
            channel_samples = null;

        audio_format = converted_audio.getFormat();

        unique_ID = unique_identifier;

        if (normalize_if_clipped)
            normalizeIfClipped();

        converted_audio.close();
    }
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

        if (audio_input_stream == null)
            throw new Exception("Given AudioInputStream is empty.");

        unique_ID = unique_identifier;

        AudioInputStream converted_audio = org.vocvark.jAudioTools.AudioMethods.getConvertedAudioStream(audio_input_stream);

        channel_samples = org.vocvark.jAudioTools.AudioMethods.extractSampleValues(converted_audio);

        samples = DSPMethods.getSamplesMixedDownIntoOneChannel(channel_samples);

        if (channel_samples.length == 1)
            channel_samples = null;

        audio_format = converted_audio.getFormat();

        if (normalize_if_clipped)
            normalizeIfClipped();

        converted_audio.close();
    }
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

        // Convert samples to 2-D array
        double[][] samples_to_convert = new double[1][];
        samples_to_convert[0] = samples;

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

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

Examples of javax.sound.sampled.AudioInputStream

        // Convert the samples to 2-D array
        double[][] samples_to_convert = new double[1][];
        samples_to_convert[0] = sample_portion;

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

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

Examples of javax.sound.sampled.AudioInputStream

        // Convert the samples to 2-D array
        double[][] samples_to_convert = new double[1][];
        samples_to_convert[0] = sample_portion;

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

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

Examples of javax.sound.sampled.AudioInputStream

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

        // 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
TOP
Copyright © 2018 www.massapi.com. 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.