Package javax.sound.sampled

Examples of javax.sound.sampled.AudioInputStream$TargetDataLineInputStream


     * This converts the file to something that jav can play.
     * @param clipURL url of audio clip
     */
    private static void playSoundInternal(URL clipURL) {
        try {
            AudioInputStream fis =  AudioSystem.getAudioInputStream(clipURL);
            //System.out.println("File AudioFormat: " + fis.getFormat());

            AudioInputStream ais = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, fis);
            AudioFormat af = ais.getFormat();
            //System.out.println("AudioFormat: " + af.toString());

            SourceDataLine line = AudioSystem.getSourceDataLine(af);

            line.open(af);
            int bufSize = line.getBufferSize();

            line.start();

            byte[] data = new byte[bufSize];
            int bytesRead;

            while ((bytesRead = ais.read(data,0,data.length)) != -1) {
                line.write(data,0,bytesRead);
            }

            line.drain();
            line.stop();
View Full Code Here


     */
    private byte[] getSound( String sPath ) {
        try {
            //URL url = SpeechSynthesizer.class.getResource( fileName );
            URL url = FileUtil.getURL(sPath);
            AudioInputStream stream = AudioSystem.getAudioInputStream( url );
            AudioFormat format = stream.getFormat();

            // -- convert an ALAW/ULAW sound to PCM for playback --
            if ( (format.getEncoding() == AudioFormat.Encoding.ULAW) ||
                    (format.getEncoding() == AudioFormat.Encoding.ALAW) ) {
                AudioFormat tmpFormat = createAudioFormat(format);
                stream = AudioSystem.getAudioInputStream( tmpFormat, stream );
                format = tmpFormat;
            }

            if ( line == null ) {
                line = createDataLine(format);
            }

            // -- some size calculations --
            int frameSizeInBytes = format.getFrameSize();
            int bufferLengthInFrames = line.getBufferSize() >> 3;
            int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;

            byte[] data = new byte[bufferLengthInBytes];

            // -- read the data bytes and count them --
            int numBytesRead = 0;
            numBytesRead = stream.read(data);

            byte maxByte = 0;

            // -- truncate the byte array to the correct size --
            byte[] newData = new byte[numBytesRead];
View Full Code Here

      new Thread(new Runnable() {
        public void run() {
          try {
            Clip clp = AudioSystem.getClip();

            AudioInputStream aisStream =
                AudioSystem.getAudioInputStream(Sound.class.getResourceAsStream(strPath));
    
           
            clp.open(aisStream);
            clp.start();
View Full Code Here

    Clip clp = null;
   
    // this line caused the original exceptions
   
    try {
      AudioInputStream aisStream =
            AudioSystem.getAudioInputStream(Sound.class.getResourceAsStream(strPath));
      clp = AudioSystem.getClip();
        clp.open( aisStream );
       
    } catch (UnsupportedAudioFileException exp) {
View Full Code Here

                JizzTrackAudioReader.SAMPLE_RATE,
                JizzTrackAudioReader.SAMPLE_SIZE_IN_BITS,
                JizzTrackAudioReader.CHANNELS, JizzTrackAudioReader.FRAME_SIZE,
                JizzTrackAudioReader.FRAME_RATE,
                JizzTrackAudioReader.BIG_ENDIAN);
        AudioInputStream ais = new AudioInputStream(rawIn, format,
                rawFile.length() / 4);

        File wavFile = new File(outputTo, filename + ".wav");
        AudioSystem.write(ais, AudioFileFormat.Type.WAVE, wavFile);

        ais.close();
        rawFile.delete();
    }
View Full Code Here

public class JizzJavaSoundTrackAudioReaderImpl implements JizzTrackAudioReader {
    @Override
    public InputStream decode(InputStream encoded, String fileExtension)
            throws IOException, UnsupportedTrackTypeException {
        try {
            AudioInputStream encodedIn = AudioSystem
                    .getAudioInputStream(encoded);

            // CD (red-book) format
            AudioFormat decodedFormat = new AudioFormat(
                    AudioFormat.Encoding.PCM_SIGNED,
View Full Code Here

  public music(int t)
  {
    type=t;
    if(type==2)
    {
      AudioInputStream ais;
      try {
       
        ais = AudioSystem.getAudioInputStream(new File("elevatordoor.wav"));
          clip = AudioSystem.getClip();
            clip.open(ais);
View Full Code Here

    public static SonarSample loadSample(String resourceName) throws UnsupportedAudioFileException, IOException
    {
        // Hack to prevent "mark/reset not supported" on some systems
        //byte[] d = rip(SampleLoader.class.getResourceAsStream(resourceName));
      byte[] d = rip(new FileInputStream(resourceName));
        AudioInputStream ais = AudioSystem.getAudioInputStream(new ByteArrayInputStream(d));
        return buildSample(rip(ais), ais.getFormat());
    }
View Full Code Here

        if (!soundFile.exists()) {
            //System.err.println("Wave file not found: " + filename);
            return;
        }

        AudioInputStream audioInputStream = null;
        try {

            audioInputStream = AudioSystem.getAudioInputStream(soundFile);
        } catch (UnsupportedAudioFileException e1) {
            //e1.printStackTrace();
            return;
        } catch (IOException e1) {
            //e1.printStackTrace();
            return;
        }


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

        try {
            auline = (SourceDataLine) AudioSystem.getLine(info);
            auline.open(format);
        } catch (LineUnavailableException e) {
            //e.printStackTrace();
            auline = null;
            return;
        } catch (Exception e) {
            //e.printStackTrace();
            auline = null;
            return;
        }

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

        try {
            while (nBytesRead != -1) {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
//                nBytesRead *= 4; // todo relate to real size of format
                if (nBytesRead >= 0)
                    auline.write(abData, 0, nBytesRead);
            }
        } catch (IOException e) {
View Full Code Here

    }

    // Returns test sound.
    private AudioInputStream getTestSoundAS()
    {
        AudioInputStream audioInputStream = null;
        try
        {
            InputStream inputStream = getTestSoundIS();
            audioInputStream = AudioSystem.getAudioInputStream(inputStream);
        } catch (Exception e)
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.