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.getFrameSize()*rate*1);
byte[] bytes = new byte[(int)bufferSize/12];
lineOut.open(format,bufferSize);
stopS = false;
recording = false;
playing = true;
if (debug) {
print("playing");
}
status.setText("Playing");
lineOut.start();
while (!stopS) {
if (in.available() != 0) {
if(lineOut.available() != 0) {
in.read(bytes);
lineOut.write(bytes, 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 (LineUnavailableException 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.getFrameSize()*rate*0.2);
byte[] bytes = new byte[(int)bufferSize/5];
lineIn.open(format,bufferSize);
if (debug){
print("recording");
}
stopS = false;
lineIn.start();
status.setText("Recording");
recording = true;
while (!stopS) {
lineIn.read(bytes, 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 (LineUnavailableException ex) {
error("I can't acces the nessesary audio functions now");
} catch (IOException ex) {
error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
}
}
} 2 4100
the only response is a pop from the speakers
you may want to take a look at this http://ls10-www.cs.uni-dortmund.de/L...d/playing.html
under the section play sounds from an application
"Josh" <an********@yahoo.com> wrote in message
news:2e*******************@news1.telusplanet.net.. . 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.getFrameSize()*rate*1); byte[] bytes = new byte[(int)bufferSize/12]; lineOut.open(format,bufferSize); stopS = false; recording = false; playing = true; if (debug) { print("playing"); } status.setText("Playing"); lineOut.start(); while (!stopS) { if (in.available() != 0) { if(lineOut.available() != 0) { in.read(bytes); lineOut.write(bytes, 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 (LineUnavailableException 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.getFrameSize()*rate*0.2); byte[] bytes = new byte[(int)bufferSize/5]; lineIn.open(format,bufferSize); if (debug){ print("recording"); } stopS = false; lineIn.start(); status.setText("Recording"); recording = true; while (!stopS) { lineIn.read(bytes, 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 (LineUnavailableException ex) { error("I can't acces the nessesary audio functions now"); } catch (IOException ex) { error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!"); } } } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: SOB-like MIDIs |
last post by:
The applet for endlessly rising/falling scale
(auditory illusion)
on this page is fantastic!
http://www.cs.ubc.ca/nest/imager/contributions/flinn/Illusions/ST/st.html
How is this done?...
|
by: Mark Smart |
last post by:
I am interested in developing applets that generate MIDI data in real
time with good solid timing. I've downloaded the Java Sound Demo and,
as others on this newsgroup have noted, it has severe...
|
by: BlackHawke |
last post by:
My name is Nick Soutter, I own a small game development company
(www.aepoxgames.net) making our first game (www.andromedaonline.net) in
java.
I am writing because we are having a very...
|
by: nemokid |
last post by:
hi all,
i need to write an application that listen for DTMF tones from
standard audio input (from the mic) and execute an action depending on
the digit extracted from the DTMF tone. Unfortunaly i...
|
by: Zach |
last post by:
This is all on linux using jdk1.3. My application is written in AWT,
no swing.
The application requires running it on the host machine and tunneling
the GUI back to a client. I've been doing...
|
by: Richard |
last post by:
Level: Java newbie, C experienced
Platform: Linux and Win32, Intel
Another programmer and I are working on a small project together.
He's writing a server process in Java that accepts input...
|
by: mmc |
last post by:
3 methods needs doing;
wave1: This static method takes an AudioInputStream and gradually lowers and then raises the volume so that the new AudioInputStream appears to be constantly alerting in...
|
by: desturrr |
last post by:
I am planning to start writing an application by java. Let me tell what i have in my mind. There is going to be stave and client can input the notes for the song on the stave, as you know just like...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |