473,769 Members | 7,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!!!");
}
}
}
Jul 17 '05 #1
2 4125
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********@yah oo.com> wrote in message
news:2e******** ***********@new s1.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.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!!!");
}
}
}

Jul 17 '05 #3

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

Similar topics

3
6993
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? (I'm assuming it uses MIDI.)
1
2600
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 problems playing a steady beat. Has anyone achieved good timing by using a plugin like JSyn in addition to Java? Can you do MIDI code with JSyn, or just raw sound synthesis? Are there other plugins for doing realtime MIDI without sound synthesis? ...
21
4455
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 serious problem, and I was hoping someone might have thoughts.
1
4316
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 have short time to set up this application and i'm really new to this kind of problem (sound analisys). I take a look at JTAPI but i don't have any telephone in this context, i just have to analyze a normal sound signal from the sound card. I...
5
4441
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 this via an ssh session. In the building the GUI works pretty much as if I was running it directly from the host machine, no lags or performance problems. Over longer distances I start to see some lagging, the GUI loses some responsiveness, it's...
30
10956
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 from processes I've written over a TCP connection. My processes are all written in C; his are all done in Java. He's new to Java, and I've never really used it. My input is basically a stream of 32-bit unsigned integers (e.g., the
1
2360
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 volume. wave2: This static method takes an AudioInputStream and alters it so that it seems to move from left to right. The resultant new audio stream is then returned. down: This static method takes a 16 bit AudioInputStream and returns an...
2
2037
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 guitar pro. What i want to do is after composing these notes on a free stave, i have to play the notes but firstly i need to record the sounds , i searched about the sound file formats, the sound api for java supports wav files. If you know any...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.