Package javax.sound.sampled

Examples of javax.sound.sampled.AudioInputStream$TargetDataLineInputStream


    init(audioFile);
  }

  private void init(InputStream audioFile) {
    try {
      AudioInputStream soundStream = AudioSystem
          .getAudioInputStream(audioFile);
      AudioFormat audioFormat = soundStream.getFormat();
      // define line information based on line type,
      // encoding and frame sizes of audio file
      DataLine.Info dataLineInfo = new DataLine.Info(Clip.class,
          AudioSystem.getTargetFormats(
              AudioFormat.Encoding.ULAW, audioFormat),
View Full Code Here


    public void play(String fileName) {
        if(Main.debug(Main.DEBUG_AUDIO))
            System.err.println("AudioControl::play called "+fileName);
        try {
            AudioInputStream audioInput = AudioSystem.getAudioInputStream( new java.net.URL(baseDir+fileName));
            if (Main.debug(Main.DEBUG_AUDIO))
                System.out.println("    audio format is:"+audioInput.getFormat());
           if (audioLine.isRunning())
                audioLine.stop();
            if (audioLine.isOpen())
                audioLine.close();
            audioLine.open(audioInput);
View Full Code Here

        assertTrue(ok);
    }

    public void testAudioInputStream() throws Exception {

        AudioInputStream stream = AudioSystem.getAudioInputStream(new File(
                "myFile.txt"));
        assertTrue(stream != null);

        // no exception expected
        AudioSystem.write(stream, new AudioFileFormat.Type("TXT", "txt"),
View Full Code Here

    public void testAudioInputStream() throws Exception {
        InputStream is = new ByteArrayInputStream(new byte[1001]);
        AudioFormat format = new AudioFormat(1f, 16, 2, true, false);

        AudioInputStream ais = new AudioInputStream(is, format, 10);

        assertEquals(format, ais.getFormat());
        assertEquals(10, ais.getFrameLength());
        assertEquals(40, ais.available());
        assertEquals(8, ais.read(new byte[10]));
        assertEquals(32, ais.available());
        assertTrue(ais.markSupported());
        ais.mark(1000);
        assertEquals(8, ais.read(new byte[10]));
        assertEquals(24, ais.available());
        assertEquals(0, ais.skip(2));
        assertEquals(8, ais.skip(10));
        ais.reset();
        assertEquals(32, ais.available());
        assertEquals(0, ais.read(new byte[10], -1, 2));
        assertEquals(8, ais.read(new byte[10], 0, 11));
        try {
            ais.read();
            fail("No expected IOException");
        } catch (IOException expected) {
        }
        ais.close(); // no exception expected

        is = new ByteArrayInputStream(new byte[1001]);
        ais = new AudioInputStream(is, format, 500);

        assertEquals(format, ais.getFormat());
        assertEquals(500, ais.getFrameLength());
        assertEquals(1001, ais.available());
        assertEquals(8, ais.read(new byte[10]));
        assertEquals(993, ais.available());
        ais.mark(1000);
        assertEquals(8, ais.read(new byte[10]));
        assertEquals(985, ais.available());
        assertEquals(0, ais.skip(2));
        assertEquals(8, ais.skip(10));
        ais.reset();
        assertEquals(993, ais.available());
        assertEquals(0, ais.read(new byte[10], -1, 2));
        assertEquals(8, ais.read(new byte[10], 0, 11));
        try {
            ais.read();
            fail("No expected IOException");
        } catch (IOException expected) {
        }
        ais.close(); // no exception expected
    }
View Full Code Here

        cancelled = false;
        curIndex = 0;
        PipedInputStream in;
        try {
            in = new PipedInputStream(outputData);
            audioInput = new AudioInputStream(in, currentFormat, size);
        } catch (IOException e) {
            LOGGER.warning(e.getLocalizedMessage());
        }
        while (paused && !cancelled) {
            try {
View Full Code Here

     */
    public synchronized void close() {
  try {
      File file = new File(baseName);
      InputStream is = new SequenceInputStream(outputList.elements());
      AudioInputStream ais = new AudioInputStream(is,
        currentFormat, totBytes / currentFormat.getFrameSize());
            if (false) {
                System.out.println("Avail " + ais.available());
                System.out.println("totBytes " + totBytes);
                System.out.println("FS " + currentFormat.getFrameSize());
            }
            System.out.println("Wrote synthesized speech to " + baseName);
      AudioSystem.write(ais, outputType, file);
View Full Code Here

     *      output was cancelled or interrupted.
     *
     */
    public boolean end()  {
  ByteArrayInputStream bais = new ByteArrayInputStream(outputData);
  AudioInputStream ais = new AudioInputStream
            (bais, currentFormat,
             outputData.length/currentFormat.getFrameSize());
  String name = baseName;
  name = name + fileCount;
  name = name + "." + outputType.getExtension();
View Full Code Here

     */
    private void play(Project project, File file, int loops, Long duration) {

        Clip audioClip = null;

        AudioInputStream audioInputStream = null;


        try {
            audioInputStream = AudioSystem.getAudioInputStream(file);
        } catch (UnsupportedAudioFileException uafe) {
            project.log("Audio format is not yet supported: "
                + uafe.getMessage());
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

        if (audioInputStream != null) {
            AudioFormat format = audioInputStream.getFormat();
            DataLine.Info   info = new DataLine.Info(Clip.class, format,
                                             AudioSystem.NOT_SPECIFIED);
            try {
                audioClip = (Clip) AudioSystem.getLine(info);
                audioClip.addLineListener(this);
View Full Code Here

            //load clip
            Clip clip = AudioSystem.getClip();
           
            InputStream audiosrc = getClass().getResourceAsStream(path);
            InputStream bufferedIn = new BufferedInputStream(audiosrc);
            AudioInputStream ai = AudioSystem.getAudioInputStream(bufferedIn);
            clip.open(ai);
           
            //volume control
            FloatControl control = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            //reduce volume by 30 dec
View Full Code Here

   
    // play audio file
    try
      if (soundOn) {
          File audioFile = new File(fileName)
          AudioInputStream stream = AudioSystem.getAudioInputStream(audioFile);
          AudioFormat format = stream.getFormat();
          DataLine.Info info = new DataLine.Info(Clip.class, format);       
          if (clip != null) {
            clip.close();
          }
          clip = (Clip) AudioSystem.getLine(info);
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.