473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.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!!!");
}
}
}
Jul 17 '05 #1
2 4100
the only response is a pop from the speakers
Jul 17 '05 #2
gg
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!!!");
}
}
}

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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?...
1
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...
21
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...
1
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...
5
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...
30
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...
1
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...
2
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
0
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...
0
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...
1
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.