Java Sound Problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Josh

    Java Sound Problems

    I am having a problem with sound in my program, it takes information from a
    TargetDataLine, put's it in a temporary file, then takes it back out of the
    temporary file and plays it using a SourceDataLine. currently, it does not
    play back.

    andrewjj20

    the play method:
    class Player implements Runnable {
    public Player() {
    }
    public void run() {
    try {
    int bufferSize = (int)(format.ge tFrameSize()*ra te*1);
    byte[] bytes = new byte[(int)bufferSize/12];
    lineOut.open(fo rmat,bufferSize );
    stopS = false;
    recording = false;
    playing = true;
    if (debug) {
    print("playing" );
    }
    status.setText( "Playing");
    lineOut.start() ;
    while (!stopS) {
    if (in.available() != 0) {
    if(lineOut.avai lable() != 0) {
    in.read(bytes);
    lineOut.write(b ytes, 0, bytes.length);
    }
    } else {
    stopS = true;
    resetGUI();
    }
    }
    lineOut.drain() ;
    lineOut.stop();
    lineOut.close() ;
    lineOut = null;
    stopS = false;
    recording = false;
    playing = false;
    status.setText( "Done");
    if (debug) {
    print("Done");
    }
    } catch (LineUnavailabl eException ex) {
    error("I can't acces the nessesary audio functions now");
    } catch (IOException ex) {
    error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
    }
    }
    }

    the record method:
    class Recorder implements Runnable {
    public Recorder() {
    }
    public void run() {
    try {
    int bufferSize = (int)(format.ge tFrameSize()*ra te*0.2);
    byte[] bytes = new byte[(int)bufferSize/5];
    lineIn.open(for mat,bufferSize) ;
    if (debug){
    print("recordin g");
    }
    stopS = false;
    lineIn.start();
    status.setText( "Recording" );
    recording = true;
    while (!stopS) {
    lineIn.read(byt es, 0, bytes.length);
    out.write(bytes .length);
    }
    lineIn.stop();
    out.close();
    lineIn.close();
    lineIn = null;
    out = null;
    stopS = false;
    recording = false;
    modified = true;
    newFile = false;
    status.setText( "Done");
    if (debug) {
    print("Done");
    }
    } catch (LineUnavailabl eException ex) {
    error("I can't acces the nessesary audio functions now");
    } catch (IOException ex) {
    error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
    }
    }
    }
  • Josh

    #2
    Re: Java Sound Problems

    the only response is a pop from the speakers

    Comment

    • gg

      #3
      Re: Java Sound Problems

      you may want to take a look at this

      under the section play sounds from an application
      "Josh" <andrewjj20@yah oo.com> wrote in message
      news:2eg2b.1161 5$_5.231928@new s1.telusplanet. net...[color=blue]
      > I am having a problem with sound in my program, it takes information from[/color]
      a[color=blue]
      > TargetDataLine, put's it in a temporary file, then takes it back out of[/color]
      the[color=blue]
      > temporary file and plays it using a SourceDataLine. currently, it does not
      > play back.
      >
      > andrewjj20
      >
      > the play method:
      > class Player implements Runnable {
      > public Player() {
      > }
      > public void run() {
      > try {
      > int bufferSize = (int)(format.ge tFrameSize()*ra te*1);
      > byte[] bytes = new byte[(int)bufferSize/12];
      > lineOut.open(fo rmat,bufferSize );
      > stopS = false;
      > recording = false;
      > playing = true;
      > if (debug) {
      > print("playing" );
      > }
      > status.setText( "Playing");
      > lineOut.start() ;
      > while (!stopS) {
      > if (in.available() != 0) {
      > if(lineOut.avai lable() != 0) {
      > in.read(bytes);
      > lineOut.write(b ytes, 0, bytes.length);
      > }
      > } else {
      > stopS = true;
      > resetGUI();
      > }
      > }
      > lineOut.drain() ;
      > lineOut.stop();
      > lineOut.close() ;
      > lineOut = null;
      > stopS = false;
      > recording = false;
      > playing = false;
      > status.setText( "Done");
      > if (debug) {
      > print("Done");
      > }
      > } catch (LineUnavailabl eException ex) {
      > error("I can't acces the nessesary audio functions now");
      > } catch (IOException ex) {
      > error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
      > }
      > }
      > }
      >
      > the record method:
      > class Recorder implements Runnable {
      > public Recorder() {
      > }
      > public void run() {
      > try {
      > int bufferSize = (int)(format.ge tFrameSize()*ra te*0.2);
      > byte[] bytes = new byte[(int)bufferSize/5];
      > lineIn.open(for mat,bufferSize) ;
      > if (debug){
      > print("recordin g");
      > }
      > stopS = false;
      > lineIn.start();
      > status.setText( "Recording" );
      > recording = true;
      > while (!stopS) {
      > lineIn.read(byt es, 0, bytes.length);
      > out.write(bytes .length);
      > }
      > lineIn.stop();
      > out.close();
      > lineIn.close();
      > lineIn = null;
      > out = null;
      > stopS = false;
      > recording = false;
      > modified = true;
      > newFile = false;
      > status.setText( "Done");
      > if (debug) {
      > print("Done");
      > }
      > } catch (LineUnavailabl eException ex) {
      > error("I can't acces the nessesary audio functions now");
      > } catch (IOException ex) {
      > error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
      > }
      > }
      > }[/color]


      Comment

      Working...