Not exactly a Java.Sound.* problem...

Hello folks! I am writing a piece of code that takes a .wav file, encoded with 16 bits/sample, and has to perform a "thersholding" operation in these samples. That is, that groups of samples that don't have enough mean energy, shall not be included in the new .wav file that will contain the thresholded sample (the whole process is a short of compression).
The problem is, that for some reason I haven't discovered yet, only half of the bytes of the original file are found in the final file! (But, the thresholding mechanism works well in these half samples :P)
Could you please check on my code? 15 javies for the one who gives me a solution! :)
Here goes my code
// 16bits/sample
// line 47 -> input .wav file
import java.io.*;
import javax.sound.sampled.*;
public class thresholding16 {
public thresholding16() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
AudioFormat audioFormat;
AudioInputStream audioInputStream;
//initial samples from File
byte buffer[] = new byte[10000000];
//thresholded samples ->to be written in a new File
byte newBuffer[] = new byte[10000000];
//the initial 2-byte samples will be represented as an integer (by merging the MSB,LSB of the sample)
int intArray[]=new int[5000000];
//mean energy of samples for every one of the 200000 groups of 25 samples
double energyArray[] = new double[200000];
public static void main(String args[]){
try{
thresholding16 thres=new thresholding16();
thres.moveToBuffer();
catch(Exception x){
System.out.println(x);
void moveToBuffer() {
int cnt=0;
try{
File soundFile =
new File("aFile0.wav"); //to arxeio eisodou pou 8a 'katwfliw8ei'
audioInputStream = AudioSystem.
getAudioInputStream(soundFile);
audioFormat = audioInputStream.getFormat();
System.out.println(audioFormat);
for(int h=0;h<10000000;h++){
buffer[h]=0;
while((cnt = audioInputStream.read(buffer,0,buffer.length)) != -1){
System.out.println("Ta arxika deigmata ws bytes");
for(int j=0;j<10000;j++){
System.out.println(j+" "+buffer[j]);
FileWriter fistream = new FileWriter("16bitArxika.txt");
BufferedWriter outi = new BufferedWriter(fistream);
outi.write("Ta arxika deigmata ws bytes"+"\r\n");
for(int j=0;j<10000;j++){
outi.write(buffer[j]+"\r\n");
//Close the output stream
outi.close();
//merge the 2 bytes of a sample int one integer
for(int j=0;j<5000000;j++){
int num=0;
int msb=0;
int lsb=0;
msb=buffer[j*2+1];
lsb=buffer[j*2];
int h=buffer[j*2+1];
if (h<0){
num=msb&lsb;
else{
num=msb^lsb;
intArray[j]=num;
}//end for
FileWriter fistream = new FileWriter("16bitArxika.txt");
BufferedWriter outi = new BufferedWriter(fistream);
outi.write("Ta arxika deigmata ws bytes"+"\r\n");
for(int j=0;j<200000;j++){
outi.write(intArray[j]+" ");
//Close the output stream
outi.close();
System.out.println("Ena deigma -> enas integer");
for(int j=0;j<500;j++){
System.out.println(j+" "+intArray[j]);
for(int i=0;i<200000;i++){
energyArray=0;
//Mean energy estimated from the type //&#917;=10log(&#949;+1/&#925;&#931;S^2(n))
for(int i=0;i<200000;i++){
for(int j=0;j<25;j++){
energyArray[i]=energyArray[i]+intArray[i*25+j]*intArray[i*25+j];
// System.out.println("Mesh Energeia ana omada");
for(int i=0;i<200000;i++){
double h=0;
h=Math.log(energyArray[i]/25+000000.1)/Math.log(10);
energyArray[i]=h;
//auxiliary array that tells which groups of bytes pass and //which do not
int booleanArray[] = new int[200000];
for(int j=0;j<200000;j++){
booleanArray[j]=0;
if (energyArray[j]>2.1){   //the wanted threshold
booleanArray[j]=1;
for(int i=0;i<10000000;i++){
newBuffer[i]=buffer[i];
//I put 0 to the proper positions, depending on whether the //groups of bytes has passed the thresholding operation
for(int i=0;i<200000;i++){
if(booleanArray[i]==0){
for(int j=0;j<25;j++){
newBuffer[i*25+j*2]=0; // 0 at MSB
for(int j=1;j<26;j++){
newBuffer[i * 25 + j * 2 - 1] = 0; // 0 at LSB
FileWriter fstream = new FileWriter("16bitDeigmataKatwfliwmena.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Ta telika deigmata ws bytes"+"\r\n");
for(int j=0;j<10000000;j++){
out.write(newBuffer[j]+"\r\n");
//Close the output stream
out.close();
//the new .wav file
ByteArrayInputStream bis=new ByteArrayInputStream(newBuffer);
AudioInputStream ais=new AudioInputStream(bis,audioFormat,newBuffer.length/audioFormat.getFrameSize());
int cnt2;
cnt2 = audio system.write(ais,AudioFileFormat.Type.WAVE,new File("aFile0Thres.wav"));
System.out.println(" "+cnt2);
catch (Exception e) {
}//end of method moveToBuffer
private void jbInit() throws Exception {
}//end of class thresholding16

>
How do i merge all the XSL's..... can i use something
like a master XSL that calls the other 4 documenst
one after the other.
Something like <XSL:Import> or <XSL:Include>
You can import other stylesheets and use the templates they contain. You can also import one or more stylesheets and then optionally redefine any templates that they define.
<xsl:stylesheet      version="1.0"      
                                   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                   xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
     <!-- import the core functionality -->
     <xsl:import href="../common/generic_csv.xslt"/>
Some other templating code...
</xsl:stylesheet>Is this what you are after?

Similar Messages

  • Sound problems with movie

    I just purchased the movie "Overboard" in HD. The movie video plays ok, but the sound keeps going in and out.
    I don't understand why this is happening. My music plays ok and I'm not having any other sound problems with my
    computer.  I am running Itunes on a Windows 8.1 desktop computer (Gateway).
    I couldn't figure out how to re-download it or repair it.
    If anyone can help, I'd appreciate it!
    Thanks!

    Hi Larry James,
    If you are having video playback issues in iTunes on your Windows machine, you may find the following articles helpful:
    Apple Support: Troubleshooting iTunes for Windows Vista or Windows 7 video playback performance issues
    http://support.apple.com/kb/ts1718
    Apple Support: Downloading past purchases from the iTunes Store, App Store, and iBooks Store
    http://support.apple.com/kb/ht2519
    Regards,
    - Brenden

  • Sound problem with java and windows (volume)

    Hello,
    Just wondering if there is any way that java can manipulate the sound volume
    in windows...I've searched through the forums here and ive noticed that this question has come up a number of times, but nothing definitive has really been posted.
    My program is a 'server' side portion of a mobile phone app ive written, that im trying to use as a remote to turn up the volume, skip tracks, etc. on my pc via bluetooth. Basically what im doing is sending a string from the mobile phone app to the pc telling it to increment the volume/decrement the volume by a certain amount. Can java do this natively or am i going to need to use a C++ library through JNI (which i have never done before)
    Any help appreciated!
    Thanks,
    Craig

    Victor,
    I've tried your suggestions and found that the first one only alters the volume of the midi file that is being played through java. I want to be able to alter the volume of the sound that I already have coming out of my speakers, through windows master volume control.
    Your second suggestion I also tried but to no luck...i always get the following exception message:
    "Failed trying to find LINE_IN VOLUME control: exception = java.lang.IllegalArgumentException: Line unsupported: LINE_IN source port"This exception occurs no matter what I change LINE_IN to in this segment of code (I want to control sound output so i assume it should be either SPEAKER or LINE_OUT):
    lineOut = (Port)mixer.getLine(Port.Info.LINE_IN);Any other suggestions?
    I noticed on the j2se sound guide site, they mention a way to get a list of supported mixers and/or lines, but im not exactly sure how to go about doing that (maybe it will be helpful?)
    Thanks for your time,
    Craig

  • Wintv 7 930 c not working with FME 3.2 Sound problems :

    Hi Guys my first post here, after 3 days with struggling i gave up,and come here for your expert tips.
    I bought a wintv 7 930 c hd tv card,working fine on my computer,but when i enter FMLE 3.2 and click start i get :
    "Unknown Error Occurred.  Device may be already in use or not working."
    I disabled stereo mix in my sound setting in recording and have only a option to use my hauppauge tv card as line in for sound, but thats impossible for me, and now FMLE 3.2 also freezes a lot and not responding, same is happening when i try using normal stream with manycams and a videofile,no sound ,but good stream, so its the sound problem i cant fix at all here .
    Any good tips would be very appreciate, heck i would even paypal you 20 bucks if you can help me with this .
    Thanks.

    Hello,thanks for your help, yes i understand that by now, i called support.
    So what do you suggest i do,so i can stream from my computer true my tv card and out,is there a 3 part i can use who handle this then use FMLE ?

  • Im having a problem with my mic on my ipod 5th gen it works but it douse not pick up any sound unless i  talk right next to the mic. how can i fix this

    im having a problem with my mic on my ipod 5th gen it works but it douse not pick up any sound  unless I  talk right next to the mic but it sounds low  . how can i fix this

    - Make sure the mic hole is clear and unobstructed. It is the little hole on the back by the camera lens(if has back camera). For the 16 GB one without the back camera the mic hole is on the top edge near the center.
    - Reset the iOS device. Nothing will be lost      
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings                            
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                               
    iOS: Back up and restore your iOS device with iCloud or iTunes
    - Restore to factory settings/new iOS device.                       
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar                                                              

  • Sound problem(earphones are okay ,checked with my pc)problem is when i listen songs on ipod,unwanted sounds along with songs is produced..so music is not cleared.How to remove these noises or unwanted sounds...pls

    sound problem ..
    unwanted sounds are produced continuously along with played music while listening .. earphones are ok(checked with PC)

    sound problem ..
    unwanted sounds are produced continuously along with played music while listening .. earphones are ok(checked with PC)

  • Audio capture delayed with Java Sound and JWS

    Hi.
    I am experiencing quite a strange problem with Java Sound in my Java Web Start application. I am acquiring sound from the microphone through Java Sound, using a code which looks like this:
    ==============================
    AudioFormat audioFormat = new AudioFormat(11025, 8, 1, true, false);
    // Get a TargetDataLine from the appropriate mixer
    DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
    TargetDataLine targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
    // Prepare the line for use
    targetDataLine.open(audioFormat);
    targetDataLine.start();
    targetDataLine.addLineListener(myLineListener);
    // Build an input stream from the line
    AudioInputStream audioInStream = new AudioInputStream(targetDataLine);
    // Create the output file
    File outputFile = new File("C:\\MySampleAudioFile.wav");
    // Start the actual audio file-writing operation
    AudioFileFormat.Type targetFileFormatType = AudioFileFormat.Type.WAVE;
    AudioSystem.write(audioInStream, targetFileFormatType, outputFile);
    ==============================
    This code is executed in an independent thread. As you can see from the code reported above, I add a LineListener to my TargetDataLine.
    The problem is that in my JWS application several seconds (about 5-6 seconds) elapse from the call to AudioSystem.write() and the reception of the START LineEvent on my LineListener. This delay only occurs when my JWS application is downloaded from my public internet website, while it is not present when I test my JWS application on my local LAN server.
    It looks like the call to AudioSystem.write() causes some kind of network connection to the remote web server of the JWS app, and this operation takes some time. In fact, if I download my JWS app to my client from the public web server, then I disable all network connections on my client, then the START event is received immediately after the call to AudioSystem.write()... This is STRANGE, isn't it???
    Do you believe the call to AudioSystem.write(), or any other Java Sound call, may cause a network connection to the server from which the JWS application has been downloaded?
    A final addition to the above picture: I also have a "Java Applet" version of this application, which is exactly identical to the JWS version and uses the same exact code to do audio acquisition from the microphone. But, in this case the delay is not present, even when running the applet from the public web server!
    Any help / suggestion would be highly appreciated.
    Best regards,
    Marco.

    Hi
    Just Visit the following link and download sample source code for rtp in java
    http://javasolution.blogspot.com/2007/04/rtp-using-java.html
    if u want know basic simple java voice chat then visit
    http://javasolution.blogspot.com/2007/04/voice-chat-using-java.html

  • No TV sound - Problem with Pulseaudio and Gnome

    Hi Community!
    Since January 2013 I got big problems with the sound of my tvcard. The card is a Sundtek Media TV Pro. But after all the problems have nothing to to with the card itself!
    So far I found out, that the problem is with Pulseaudio.
    - Sound works under Windows on same PC.
    - Sound don't work under Arch - not with tvtime, not with vlc, etc.
    - Problem occurs even on a new installed system with the Arch-2013-02-01 install medium.
    cat /etc/mediasrv.log
    [1033] Pulseaudio connect reported an error (6 - Connection refused)
    [1033] select error() in audio processor (can be caused because of pulseaudio) (Interrupted system call)
    After setting up a new Arch installation with just xorg-server, gnome, tvtime and the sundtek driver from AUR I run journalctl -b:
    Feb 10 16:25:15 hightower pulseaudio[636]: [pulseaudio] pid.c:
    Daemon already running.
    With sudo journalctl | grep 'Feb 10 16:2' I get the following output:
    Feb 10 16:25:01 hightower rtkit-daemon[489]: Successfully made thread 488 of process 488 (/usr/bin/pulseaudio) owned by '120' high priority at nice level -11.
    Feb 10 16:25:14 hightower rtkit-daemon[489]: Successfully made thread 606 of process 606 (/usr/bin/pulseaudio) owned by '1000' high priority at nice level -11.
    Feb 10 16:25:15 hightower rtkit-daemon[489]: Successfully made thread 636 of process 636 (/usr/bin/pulseaudio) owned by '1000' high priority at nice level -11.
    Feb 10 16:25:15 hightower pulseaudio[636]: [pulseaudio] pid.c: Daemon already running.
    Feb 10 16:28:55 hightower pulseaudio[1000]: [pulseaudio] module-jackdbus-detect.c: Unable to contact D-Bus session bus: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
    Feb 10 16:28:55 hightower pulseaudio[1000]: [pulseaudio] module.c: Failed to load module "module-jackdbus-detect" (argument:""): initialization failed.
    Feb 10 16:28:55 hightower pulseaudio[1000]: [pulseaudio] socket-server.c: bind(): Die Adresse wird bereits verwendet
    Feb 10 16:28:55 hightower pulseaudio[1000]: [pulseaudio] module.c: Failed to load module "module-esound-protocol-unix" (argument: ""): initialization failed.
    Feb 10 16:28:55 hightower pulseaudio[1000]: [pulseaudio] main.c: Module load failed.
    Feb 10 16:28:55 hightower pulseaudio[1000]: [pulseaudio] main.c: Module load failed.
    Feb 10 16:28:55 hightower pulseaudio[1000]: [pulseaudio] main.c: Konnte Daemon nicht initialisieren.
    Feb 10 16:28:55 hightower pulseaudio[997]: [pulseaudio] main.c: Start des Daemons fehlgeschlagen.
    So, if I understand right, pulseaudio is alreade started by the rtkit-daemon and gnome couldn't start it again.
    At https://bugs.archlinux.org/task/30926 I found a hint concerning /etc/xdg/autostart/pulseaudio.desktop and /etc/xdg/autostart/pulseaudio-kde.desktop.
    After removing them from /etc/xdg/autostart and running journalctl -b there are no more errors.
    With sudo journalctl | grep 'pulseaudio' I get:
    sudo journalctl | grep 'Feb 10 17:4' | grep 'pulse*'
    Feb 10 17:41:42 hightower rtkit-daemon[485]: Successfully made thread 484 of process 484 (/usr/bin/pulseaudio) owned by '120' high priority at nice level -11.
    Feb 10 17:41:55 hightower rtkit-daemon[485]: Successfully made thread 625 of process 625 (/usr/bin/pulseaudio) owned by '1000' high priority at nice level -11.
    In my opinion all looks ok! I also checked the channels with the alsamixer and it looks good, too.
    So I ran vlc v4l2://:dev=/dev/video0:width=720:height=576:tuner-frequency=510750:adev=/dev/null:standard=255 - but still no sound.
    With cat /var/log/mediasrv.log I checked the drivers logfile:
    2013-02-10 17:48:55 [343] SETTING DVB-C
    2013-02-10 17:48:55 [343] switching to analog TV
    2013-02-10 17:48:56 [343] SETTING PAL/SECAM
    2013-02-10 17:48:58 [343] invalid audio input selected: 2
    2013-02-10 17:48:58 [343] Setting frequency: 510750000
    2013-02-10 17:48:58 [343] Using settings for Europe
    2013-02-10 17:48:58 [343] Set Pixelformat: 0 YUV 4:2:2 (YUYV)
    2013-02-10 17:48:58 [1033] Starting audio processor (PID 1033)
    2013-02-10 17:48:58 [1033] initializing audio in audio processor
    2013-02-10 17:48:58 [1033] loaded local pulseaudio driver
    2013-02-10 17:48:58 [1033] select error() in audio processor (can be caused because of pulseaudio) (Interrupted system call)
    2013-02-10 17:48:59 [1033] Pulseaudio connect reported an error (6 - Connection refused)
    2013-02-10 17:48:59 [1033] select error() in audio processor (can be caused because of pulseaudio) (Interrupted system call)
    2013-02-10 17:48:59 [1033] Pulseaudio connect reported an error (6 - Connection refused)
    I started tvtime again. This time I ran rm -rf ~/.config/pulse/ and killall pulseaudio to kill the Pulseaudio server. I instantly got a loud noise out of my speakers.
    I closed tvtime and re-opened it. And there it was: TV SOUND OUT OF MY SPEAKERS!
    But now, when I run pavucontrol I get:
    Connection to PulseAudio failed. Automatic retry in 5s.
    In this cas this is likely because PULSE_SERVER in the Environment/X11 root Windows Properties or default-server in client.conf is misconfigured.
    This situation can also arrise when PulseAudio crashed and left stale details in the X11 Root Windows.
    If this is the case, then PuseAudio should autospawn again, or if this is not configured you sould run start-pulseaudio-x11 manually.
    I got the information from Sundtek, that Pulseaudio should not be started as system service. Instead, every user should have an own Pulseaudio daemon and that PA was concepted this way. But they don't know how it is implemented in ArchLinux.
    I also don't know it exactly. So the question to all you ArchLinu pro's:
    How is PA implemented in Arch? And how can I sustainable solve my problem?
    Thank you for your time and help!
    Durag

    There is just one more thing I found out.
    After logging into Gnome and running ps aux | grep pulse I get:
    rebel 727 0.7 0.2 444316 10288 ? S<l 03:02 0:00 /usr/bin/pulseaudio --start --log-target=syslog
    rebel 731 0.0 0.0 71236 2652 ? S 03:02 0:00 /usr/lib/pulse/gconf-helper
    rebel 843 0.0 0.0 17396 1184 pts/0 D+ 03:03 0:00 grep pulse
    To get the sound to work I run:
    rm -rf .config/pulse/
    killall pulseaudio
    killall -9 pulseaudio
    I again run ps aux | grep pulse
    rebel 4016 4.2 0.2 510124 11528 ? Sl 03:06 0:02 /usr/bin/pulseaudio --start --log-target=syslog
    rebel 4020 0.0 0.0 71368 2700 ? S 03:06 0:00 /usr/lib/pulse/gconf-helper
    rebel 4046 0.0 0.0 19456 1216 pts/0 R+ 03:07 0:00 grep pulse
    I can recognize that the STATs have changed. Maybe this can help to solve the problem?

  • Java/OpenJDK problem with OSS/osspd/ALSA/pulseaudio [SOLVED]

    I've got problems with sound output of java programs, which usually try to hog /dev/dsp, using pulseaudio and openjdk 7.
    Some rare java apps' sound methods surprisingly do work. Others (which the majority of java programs seem to use) do not. In Sun Java I could make those work by using 'padsp', however this method apparently fails on Archlinux with both latest Oracle Java (formerly worked on Ubuntu w/ Sun Java 6) and with OpenJDK too.
    So I tried 'osspd' (package is called 'ossp') and it shows the root process "/usr/sbin/osspd --dsp-slave=/usr/sbin/ossp-padsp" been started, but the java applications will still not provide sound which I find pretty odd. I tried adding 'soundcore.preclaim_oss=0' to the 'kernel..' line in my grub's menu.lst, but that didn't help either.
    Last edited by Jindur (2012-05-20 02:59:20)

    It's been quite a while, but I finally found a solution (read: big ugly hack).
    Someone literally created a biguglyhack and posted it here:
    http://lifein19x19.com/forum/viewtopic. … 243#p98243
    (downloadable file there: javadummymixer_biguglyhack.zip [12.97 KiB] -> rename it from .zip to .jar and move it into your java's lib/ext folder -> profit!)
    I applied it to OpenJDK 6 (should be same for 7 though) and all my java sound works flawlessly now, with pulseaudio, without any need for padsp stuff or osspd or whatever.
    My sound.properties file reads:
    javax.sound.sampled.Clip=com.sun.media.sound.DirectAudioDeviceProvider
    javax.sound.sampled.Port=com.sun.media.sound.PortMixerProvider
    javax.sound.sampled.SourceDataLine=com.sun.media.sound.DirectAudioDeviceProvider
    javax.sound.sampled.TargetDataLine=com.sun.media.sound.DirectAudioDeviceProvider
    but actually I'm not sure whether that even matters at all.
    (Side note: The linked thread also mentions a "-D.sun.." command-line parameter that supposedly forces java to avoid disfunctional audio methods. The above biguglyhack however worked for me without any need of applying that command-line parameter.)
    Last edited by Jindur (2012-05-20 02:58:05)

  • New iTunes 6.02 AND new QuickTIme 7.04 Video Sound Problems

    Hi, I had updated my iTunes for Windows 6.01 and Quick Time 7.03 to the newest versions. The new software both yield the same issue for me. They will not play videos with sound properly. When I am on Quick Time and click to play a *.mov that I have had way before iTunes or iPod, and any other playable movies in Quick Time, the video starts, there is no sound for a few seconds and then this clicking sound starts. For instance if I had a movie that is abour 20 seconds long, it will never get the synced sound with it. Let's say the first sentence would be Hi, how are you today-----------------it sounds like this: Huh-huh-huh-huh-huh-huh-huh-huh-huh-huh-huh-how-how-how-how-how-how-how-how-how -how-how-how-how-how-how-er-er-er-er-er-er-er-er-er-er-er-er-er-er-er-er-er-er-e r-u-u-u-u-u-uu--u-u-u-u-u-u-u-u-u-u-u-u-u-u-u-u-u-u-u-u-u--u-u-u. I think you get the point. If this is a video with just sound and no spoken word in the video, it also sounds chopy, clicky, and vibrating like that and over the course of 20 seconds plays this out like this, when is should be the correct maybe 3 second part.
    This also is the same exact thing that happens in the new iTunes. Exactly. Whether it is downloaded from the iTunes Store or imported in, or even converted with the new convert to iPod option.
    The only good thing is when I put the 4 new movies on my iPod that I had converted form *.mov format with the new convert to iPod option, they play just fine on the the iPod which has the software version 1.0 software on it, not the newest firmware. But as I said nothing plays correctly soundwise from videos from the iTunes Software.
    I tried uninstalling both new versions and reinstalling them with the same problem. I therefore uninstalled them again and installed iTunes 6.01 back on my computer and thus QuickTime 7.03 and there are no problems at all with either older version of iTunes or QuickTime.
    Please advise. It this a diagnosed problem as of yet???

    Consult this article
    http://docs.info.apple.com/article.html?artnum=93610h
    This is a User to User forum by the way. Apple does not really come in here.

  • Sound problem with my iPod touch! Need urgent help!

    I have an iPod Touch 8gb 3rd gen (2nd gen) and have owned it for a couple years. Recently I've been noticing some sound problems when I listen to music with earbuds/headphones. One of the earbuds will lose sound and won't produce music but if I twist the input plug it produce little or full sound but if it moves out of a certain position it won't produce sound out of that bud. I'm using Skullcandy Ink'd earbuds so I thought maybe since they arn't great it might be a manufacturer defect but I used them with my iPod Nano 2gb 1st gen and I could hear out of both earbuds perfectly. I even plugged in my iPod Touch into a car adapter so I could listen to my music through the car stereo and it went in and out of sound so I realize now it is my iPod and not  3rd party equipment I've been using with it that is the problem. Since its the iPod what is the exact problem and how do I fix it? I really don't want to use my old iPod since it doesn't have enough storage for my music now and I'm already getting something else for Christmas that I've been wanting for a while. Please help!

    If your car adapter works thru the headphone jack, the problem could just be dirt inside the jack.
    Try just putting in and out the headphone plug a few times. You can also try cleaning the jack, just don't use anything wet. Cotton swabs are also not advisable as they might leave lint and make things worse.
    To make sure it's not a oft ware issue, try to Reset your device.  
    Press and hold both the Sleep/Wake button and the Home button for at least ten seconds, until the Apple logo appears (ignore the Slide to Power Off that shows up first).

  • Question about Java Sound example?

    Hello,
    I found this example AudioPlayer, when searching for an example of how to play .wav files in Java.
    The code seems quite long, and wondered if anyone could advise if this is the best way to play a wav file?
    And could anyone explain if the EXTERNAL_BUFFER_SIZE should allows be set to 128000;
    Thank you
    import java.io.File;
    import java.io.IOException;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.SourceDataLine;
    public class SimpleAudioPlayer
         private static final int     EXTERNAL_BUFFER_SIZE = 128000;
         public static void main(String[] args)
                We check that there is exactely one command-line
                argument.
                If not, we display the usage message and exit.
              if (args.length != 1)
                   printUsageAndExit();
                Now, that we're shure there is an argument, we
                take it as the filename of the soundfile
                we want to play.
              String     strFilename = args[0];
              File     soundFile = new File(strFilename);
                We have to read in the sound file.
              AudioInputStream     audioInputStream = null;
              try
                   audioInputStream = AudioSystem.getAudioInputStream(soundFile);
              catch (Exception e)
                     In case of an exception, we dump the exception
                     including the stack trace to the console output.
                     Then, we exit the program.
                   e.printStackTrace();
                   System.exit(1);
                From the AudioInputStream, i.e. from the sound file,
                we fetch information about the format of the
                audio data.
                These information include the sampling frequency,
                the number of
                channels and the size of the samples.
                These information
                are needed to ask Java Sound for a suitable output line
                for this audio file.
              AudioFormat     audioFormat = audioInputStream.getFormat();
                Asking for a line is a rather tricky thing.
                We have to construct an Info object that specifies
                the desired properties for the line.
                First, we have to say which kind of line we want. The
                possibilities are: SourceDataLine (for playback), Clip
                (for repeated playback)     and TargetDataLine (for
                recording).
                Here, we want to do normal playback, so we ask for
                a SourceDataLine.
                Then, we have to pass an AudioFormat object, so that
                the Line knows which format the data passed to it
                will have.
                Furthermore, we can give Java Sound a hint about how
                big the internal buffer for the line should be. This
                isn't used here, signaling that we
                don't care about the exact size. Java Sound will use
                some default value for the buffer size.
              SourceDataLine     line = null;
              DataLine.Info     info = new DataLine.Info(SourceDataLine.class,
                                                                 audioFormat);
              try
                   line = (SourceDataLine) AudioSystem.getLine(info);
                     The line is there, but it is not yet ready to
                     receive audio data. We have to open the line.
                   line.open(audioFormat);
              catch (LineUnavailableException e)
                   e.printStackTrace();
                   System.exit(1);
              catch (Exception e)
                   e.printStackTrace();
                   System.exit(1);
                Still not enough. The line now can receive data,
                but will not pass them on to the audio output device
                (which means to your sound card). This has to be
                activated.
              line.start();
                Ok, finally the line is prepared. Now comes the real
                job: we have to write data to the line. We do this
                in a loop. First, we read data from the
                AudioInputStream to a buffer. Then, we write from
                this buffer to the Line. This is done until the end
                of the file is reached, which is detected by a
                return value of -1 from the read method of the
                AudioInputStream.
              int     nBytesRead = 0;
              byte[]     abData = new byte[EXTERNAL_BUFFER_SIZE];
              while (nBytesRead != -1)
                   try
                        nBytesRead = audioInputStream.read(abData, 0, abData.length);
                   catch (IOException e)
                        e.printStackTrace();
                   if (nBytesRead >= 0)
                        int     nBytesWritten = line.write(abData, 0, nBytesRead);
                Wait until all data are played.
                This is only necessary because of the bug noted below.
                (If we do not wait, we would interrupt the playback by
                prematurely closing the line and exiting the VM.)
                Thanks to Margie Fitch for bringing me on the right
                path to this solution.
              line.drain();
                All data are played. We can close the shop.
              line.close();
                There is a bug in the jdk1.3/1.4.
                It prevents correct termination of the VM.
                So we have to exit ourselves.
              System.exit(0);
         private static void printUsageAndExit()
              out("SimpleAudioPlayer: usage:");
              out("\tjava SimpleAudioPlayer <soundfile>");
              System.exit(1);
         private static void out(String strMessage)
              System.out.println(strMessage);
    }

    I didnot go thru the code you posted but I know that the following workstry {
            // From file
            AudioInputStream stream = AudioSystem.getAudioInputStream(new File("audiofile"));
            // From URL
            stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));
            // At present, ALAW and ULAW encodings must be converted
            // to PCM_SIGNED before it can be played
            AudioFormat format = stream.getFormat();
            if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
                format = new AudioFormat(
                        AudioFormat.Encoding.PCM_SIGNED,
                        format.getSampleRate(),
                        format.getSampleSizeInBits()*2,
                        format.getChannels(),
                        format.getFrameSize()*2,
                        format.getFrameRate(),
                        true);        // big endian
                stream = AudioSystem.getAudioInputStream(format, stream);
            // Create the clip
            DataLine.Info info = new DataLine.Info(
                Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));
            Clip clip = (Clip) AudioSystem.getLine(info);
            // This method does not return until the audio file is completely loaded
            clip.open(stream);
            // Start playing
            clip.start();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        } catch (LineUnavailableException e) {
        } catch (UnsupportedAudioFileException e) {
        }

  • Using the 'java.sound.*' libraries and classes

    Hello,
    I am a complete noob to Java. So please forgive me if I seem a little stupid in the things I ask.
    I would like to know which development kit I should download to be able to gain access to the 'java.sound.*' and midi libraries and classes.
    I downloaded the Java SE 6 SDK but I could get access to these classes.
    I use JCreator as my compiler and I kept getting an error along the lines of 'java.sound.* package does not exist'. I have tried compiling the code with NetBeans and also wiuth Eclipse and I still have no luck and I get the same message. I am guessing the compiler is not the problem and it is the SDK as I can access other classes such as javax.swing and java.awt etc.
    If you could give me a link to the relevant SDK and maybe a good compiler, it would be greatly appreciated.
    Also I am using Windows XP and Windows Vista so if you could provide me with support for either of these operating systems then that would be great.
    Thank You
    Lee

    Here's the code for an SSCCE (Small Self Contained Compilable Example) of a working java sound application. If you don't provide a file name, It does expect you to have a wave file of Ballroom Blitz in your javatest directory, but doesn't everybody?
    To build and run it do:
    javac -cp . SoundPlayer.java
    java -cp . SoundPlayer  yourWaveFile.wav  
    import java.io.*;
    import javax.sound.sampled.*;
    import javax.sound.sampled.DataLine.*;
    public class SoundPlayer implements LineListener
         private float bufTime;
         private File soundFile;
         private SourceDataLine line;
         private AudioInputStream stream;
         private AudioFormat format;
         private Info info;
         private boolean opened;
         private int frameSize;
         private long frames;
         private int bufFrames;
         private int bufsize;
         private boolean running;
         private boolean shutdown;
         private long firstFrame, lastFrame;
         private float frameRate;
         private long currentFrame;
         private float currentTime;
         private Thread playThread;
         // constructor, take a path to an audio file
         public SoundPlayer(String path)
              this(path, 2);     // use 2 second buffer
         // or a path and a buffer size
         public SoundPlayer(String path, float bt)
              this(new File(path),bt);
         public SoundPlayer(File sf)
              this(sf, 2);  // use 2 second buffer
         public SoundPlayer(File sf, float bt)
              bufTime = bt;          // seconds per buffer
              soundFile = sf;
              openSound();
         private void openSound()
              System.out.println("Opening file"+soundFile.getName());
              try
                   firstFrame = 0;
                   currentFrame = 0;
                   shutdown = false;
                   running = false;
                   stream=AudioSystem.getAudioInputStream(soundFile);
                   format=stream.getFormat();
                   if(format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED)
                        System.out.println("Converting Audio stream format");
                        stream = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED,stream);
                        format = stream.getFormat();
                   frameSize = format.getFrameSize();
                   frames = stream.getFrameLength();
                   lastFrame = frames;
                   frameRate = format.getFrameRate();
                   bufFrames = (int)(frameRate*bufTime);
                   bufsize = frameSize * bufFrames;
                   System.out.println("frameRate="+frameRate);
                   System.out.println("frames="+frames+" frameSize="+frameSize+" bufFrames="+bufFrames+" bufsize="+bufsize);
                   info=new Info(SourceDataLine.class,format,bufsize);
                   line = (SourceDataLine)AudioSystem.getLine(info);
                   line.addLineListener(this);
                   line.open(format,bufsize);
                   opened = true;
              catch(Exception e)
                   e.printStackTrace();
         public void stop()
              System.out.println ("Stopping");
              if(running)
                   running = false;
                   shutdown = true;
                   if(playThread != null)
                        playThread.interrupt();
                        try{playThread.join();}
                        catch(Exception e){e.printStackTrace();}
              if (opened) close();
         private void close()
              System.out.println("close line");
              line.close();
              try{stream.close();}catch(Exception e){}
              line.removeLineListener(this);
              opened = false;
         // set the start and stop time
         public void setTimes(float t0, float tz)
              currentTime = t0;
              firstFrame = (long)(frameRate*t0);
              if(tz > 0)
                   lastFrame = (long)(frameRate*tz);
              else lastFrame = frames;
              if(lastFrame > frames)lastFrame = frames;
              if(firstFrame > lastFrame)firstFrame = lastFrame;
         public void playAsync(float start, float end)
              setTimes(start,end);
              playAsync();
         // play the sound asynchronously */
         public void playAsync()
              System.out.println("Play async");
              if(!opened)openSound();
              if(opened && !running)
                   playThread = new Thread(new Runnable(){public void run(){play();}});
                   playThread.start();
         public void play(float start, float end)
              setTimes(start,end);
              play();
         // play the sound in the calling thread
         public void play()
              if(!opened)openSound();
              if(opened && !running)
                   running = true;
                   int writeSize = frameSize*bufFrames/2; // amount we write at a time
                   byte buf[] = new byte[writeSize];     // our io buffer
                   int len;
                   long framesRemaining = lastFrame-firstFrame;
                   int framesRead;
                   currentFrame=firstFrame;
                   System.out.println("playing file, firstFrame="+firstFrame+" lastFrame="+lastFrame);
                   try
                        line.start();
                        if(firstFrame > 0)
                             long sa = firstFrame * frameSize;
                             System.out.println("Skipping "+firstFrame+" frames="+sa+" bytes");
                             while(sa > 0)sa -= stream.skip(sa);
                        while (running && framesRemaining > 0)
                             len = stream.read(buf,0,writeSize); // read our block
                             if(len > 0)
                                  framesRead = len/frameSize;
                                  framesRemaining -= framesRead;
                                  currentTime = currentFrame/frameRate;
                                  if(currentTime < 0)throw(new Exception("time too low"));
                                  System.out.println("time="+currentTime+" writing "+len+" bytes");
                                  line.write(buf,0,len);
                                  currentFrame+=framesRead;
                             else framesRemaining = 0;
                        if(running)
                             line.drain();                     // let it play out
                             while(line.isActive() && running)
                                  System.out.println("line active");
                                  Thread.sleep(100);
                             shutdown = true;
                        running = false;
                   catch(Exception e)
                        e.printStackTrace();
                        shutdown = true;
                        running = false;
                   if(shutdown)
                        close();
         // return current time relative to start of sound
         public float getTime()
              return ((float)line.getMicrosecondPosition())/1000000;
         // return total time
         public float getLength()
              return (float)frames / frameRate;
         // stop the sound playback, return time in seconds
         public float  pause()
              running = false;
              line.stop();
              return getTime();
         public void update(LineEvent le)
              System.out.println("Line event"+le.toString());
         // play a short simple PCM encoded clip
         public static void playShortClip(String fnm)
              java.applet.AudioClip clip=null;
              try
                   java.io.File file = new java.io.File(fnm);     // get a file for the name provided
                   if(file.exists())                    // only try to use a real file
                        clip = java.applet.Applet.newAudioClip(file.toURL()); // get the audio clip
                   else
                        System.out.println("file="+fnm+" not found");
              catch(Exception e)
                   System.out.println("Error building audio clip from file="+fnm);
                   e.printStackTrace();
              if(clip != null)     // we may not actually have a clip
                   final java.applet.AudioClip rclip = clip;
                   new Thread
                   (new Runnable()
                             public void run()
                                  rclip.play();
                   ).start();
         public boolean isOpened()
              return opened;
         public boolean isRunning()
              return running;
        public void showControls() {
            Control [] controls = line.getControls();
            for (Control c :controls) {
                System.out.println(c.toString());
        public void setGain(float gain) {
            FloatControl g = (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);
            g.setValue(gain);
        public static void main(String [] args) {
            float gain = 0;
            String file = "c:\\javatest\\BallroomBlitz.wav";
              for(String arg : args) {
                for(int i = 0; i < arg.length(); i++) {
                    char c  = arg.charAt(i);
                    if (c == '-') {
                        gain -= 1;
                    } else if (c == '+') {
                        gain += 1;
                    } else {
                             file = arg;
            SoundPlayer sp = new SoundPlayer(file);
            sp.showControls();
            System.out.println("setting gain to " + gain);
            sp.setGain(gain);
            sp.play();
    }

  • Sound problem in HP Pavillion dv9810us Notebook PC

    Hi :
    For last more than 8 months I am having this problem.  First  problem started with skype call.  My laptop lost its speaker and showed a red X mark next to sound icon.  I couldn't find any thing to fix the problem, so I did system recovery to factory setting.  After that my computer downloaded windows update and security updates for vista.  It upgraded my vista service pack 1 to service pack 2.  In middle of this downloading stage several times I lost sound and then again got back it and again lost.  I couldn't find any good solution.  It is so frustrating that I can't view any videos in internet explorer which is upgraded to 9 now .  I tried to watch videos in FIREFOX or Google Chrome.  But no sound after few minutes watching.  Every time I lost sound I tried to fix with microsft system restore or sound hardware restallation or total system recovery to factory setting.  Nothing solve my problem permanantly.  I contact with Microsfot vista forum, but no solutions actually fix my audio problem.   At this moment my sound icon has red X mark . 
    This morning when I started my laptop it was ok with sound, I watched one news on Yahoo.  But after that the same sound problem.  In the mean time my computer downloaded vista updates automatically and installed it.  When computer restarted  my sound icon got red X mark.  I don't understand why with some windows updates take my sound off.  If I don't want to install those updates, still the sound went off when I watch videos on yahoo or Youtube.  It says Yahoo is not responding, sometimes it says internet explorer is not responding.  I followed all kind of solution that I got from microsft vista forum but nothing worked out.  I don't know how I can fix this problem.
    This question was solved.
    View Solution.

    Quick and easy fix is to buy a cheap USB sound card (it resembles a flash drive).  Just do a google search and you should find one for $2 to $3.
    I had the same problem where my sound disappeared and would intermittently work when I rebooted until finally it quit and rebooting wouldn't help.  It seemed to have happened after a windows update AND after having errors with the QuickTouch On Screen Display. Upon research, I discovered many people had the exact same problem with this model.  
    I used Restore Manager to restore the drivers for the QTOSD and for the sound card and although I stopped getting errors for the QTOSD, it did not fix the sound.  My quick and easy resolution to my sound problem was to purchase a USB sound card online for $2.49 at Overstock dot com.  I also bought one from a local computer store, MicroCenter, that I liked better (because it had a long cord) for $10.  My sound works perfect now; HOWEVER, I just realized tonight that I NO LONGER HAVE A DIAL UP MODEM EITHER.       You should check to see if yours is still visible in Device Manager or in your dial up connections if you have one.  I suspect the problems I had also killed my modem beyond detection because it's also a Conexant HDAUDIO Soft Data Fax Modem with SmartCP (the sound card driver is also Conexant HD).  The Restore Manager won't reinstall the drivers because it doesn't see the device.  It's too expensive to repair the motherboard and I don't have to have the dial up modem so for now I will just enjoy sound and my laptop for as long as it continues to live.  
    Again, just buy a cheap USB sound card (it looks similar to a flash drive) for a quick and easy fix.  I hope this helps.  Good luck.  I hope you don't have other issues resulting from this as I did..

  • An I18N bug from java sound should be fixed.

    When you try to list some audio related names (such as mix name, port name, control name) by using java sound api, and if the names are writtened by non-ascii character such as Chinese, you will get the strange characters, that means java sound api does not support internationalization character. Here is the sample:
    *     SystemMixerFrame.java
    * Copyright (c) 2001 - 2002 by Matthias Pfisterer
    * All rights reserved.
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    * - Redistributions of source code must retain the above copyright notice,
    * this list of conditions and the following disclaimer.
    * - Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    * OF THE POSSIBILITY OF SUCH DAMAGE.
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.BooleanControl;
    import javax.sound.sampled.CompoundControl;
    import javax.sound.sampled.Control;
    import javax.sound.sampled.EnumControl;
    import javax.sound.sampled.FloatControl;
    import javax.sound.sampled.Line;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.Mixer;
    import javax.sound.sampled.Port;
    IDEAS:
    - user setting tab style vs. show complete windows for multiple mixers (horicontal/vertical)
    - user setting unix style (L/R volume) vs. windows style (volume/balance)
    /**     TODO:
    public class TestSystemMixer {
         /**     TODO:
         private static final Port.Info[]     EMPTY_PORT_INFO_ARRAY = new Port.Info[0];
         public static void main(String[] args) {
              new TestSystemMixer();
              System.exit(0);
         /**     TODO:
         public TestSystemMixer()
              List portMixers = getPortMixers();
              if (portMixers.size() == 0) {
                   out("There are no mixers that support Port lines.SystemMixer: Error");
                   System.exit(1);
              Iterator iterator = portMixers.iterator();
              while (iterator.hasNext())
                   Mixer     mixer = (Mixer) iterator.next();
                   String     strMixerName = mixer.getMixerInfo().getName();
                   out("mixername:" + strMixerName);
                   createMixerPanel(mixer);
         /**     Returns the Mixers that support Port lines.
         private List getPortMixers()
              List supportingMixers = new ArrayList();
              Mixer.Info[]     aMixerInfos = AudioSystem.getMixerInfo();
              for (int i = 0; i < aMixerInfos.length; i++)
                   Mixer     mixer = AudioSystem.getMixer(aMixerInfos);
                   boolean     bSupportsPorts = arePortsSupported(mixer);
                   if (bSupportsPorts)
                        supportingMixers.add(mixer);
              return supportingMixers;
         /**     TODO:
         // should be implemented by:
         // Mixer.isLineSupported(new Line.Info(Port.class))
         private boolean arePortsSupported(Mixer mixer)
              Line.Info[]     infos;
              infos = mixer.getSourceLineInfo();
              for (int i = 0; i < infos.length; i++)
                   if (infos[i] instanceof Port.Info)
                        return true;
              infos = mixer.getTargetLineInfo();
              for (int i = 0; i < infos.length; i++)
                   if (infos[i] instanceof Port.Info)
                        return true;
              return false;
         /**     TODO:
         private void createMixerPanel(Mixer mixer)
              Port.Info[]     infosToCheck = getPortInfo(mixer);
              for (int i = 0; i < infosToCheck.length; i++)
                   Port     port = null;
                   try
                        port = (Port) mixer.getLine(infosToCheck[i]);
                        port.open();
                   catch (LineUnavailableException e)
                        e.printStackTrace();
                   if (port != null)
                        createPortPanel(port);
         /**     TODO:
         private Port.Info[] getPortInfo(Mixer mixer)
              Line.Info[]     infos;
              List portInfoList = new ArrayList();
              infos = mixer.getSourceLineInfo();
              for (int i = 0; i < infos.length; i++)
                   if (infos[i] instanceof Port.Info)
                        portInfoList.add((Port.Info) infos[i]);
              infos = mixer.getTargetLineInfo();
              for (int i = 0; i < infos.length; i++)
                   if (infos[i] instanceof Port.Info)
                        portInfoList.add((Port.Info) infos[i]);
              Port.Info[]     portInfos = (Port.Info[]) portInfoList.toArray(EMPTY_PORT_INFO_ARRAY);
              return portInfos;
         /**     TODO:
         private void createPortPanel(Port port)
              String     strPortName = ((Port.Info) port.getLineInfo()).getName();
              out("Portname:" + strPortName);
              Control[]     aControls = port.getControls();
    //          for (int i = 0; i < aControls.length; i++)
              if (aControls.length > 1) {
                   // In fact in the windows system, it named SPEAKER port, and it contains play controls.
                   out("ignore the port " + strPortName + " that contains more than one control.");
              } else {
                   // this is record control.
                   out("control:" + aControls[0].toString());
                   createControlComponent(aControls[0]);
                   if (aControls[0] instanceof FloatControl)
                   else
         /**     TODO:
         private void createControlComponent(Control control)
              if (control instanceof BooleanControl)
              String          strControlName = control.getType().toString();
              out("sub control type BooleanControl:" + strControlName);
              else if (control instanceof EnumControl)
              String     strControlName = control.getType().toString();
              out("sub control type EnumControl:" + strControlName);
              System.out.println("WARNING: EnumControl is not yet supported");
              else if (control instanceof FloatControl)
              String     strControlName = control.getType().toString();
              out("sub control type FloatControl:" + strControlName);
              else if (control instanceof CompoundControl)
              String     strControlName = control.getType().toString();
              out("sub control type CompoundControl:" + strControlName);
              Control[]     aControls = ((CompoundControl)control).getMemberControls();
              for (int i = 0; i < aControls.length; i++)
                   Control con = aControls[i];
                   if (con instanceof BooleanControl) {
                        out("sub sub control type BooleanControl:" + con.getType().toString());
                        if (strControlName.equalsIgnoreCase("Stereo Mix")) {
                             ((BooleanControl) con).setValue(true);
                   else if (con instanceof EnumControl) {
                        out("sub sub control type EnumControl:" + con.getType().toString());
                   else if (con instanceof FloatControl)
                        if (isBalanceOrPan((FloatControl) con))
                        out("sub sub control type FloatControl balance:" + con.getType().toString());
                        else
                        out("sub sub control type FloatControl pan:" + con.getType().toString());
                   else
         /** Returns whether the type of a FloatControl is BALANCE or PAN.
         private static boolean isBalanceOrPan(FloatControl control)
              Control.Type type = control.getType();
              return type.equals(FloatControl.Type.PAN) || type.equals(FloatControl.Type.BALANCE);
         private static void out(String message)
              System.out.println(message);
    /*** SystemMixerFrame.java ***/
    Compile and run the code below on non-ascii Windows OS, you will catch the problem.
    The solution I provide:
    Download the jdk 1.4.2 source, search the files named PortMixer.c && PortMixerProvider.c and replace the method "NewStringUTF" with the method below:
    jstring WindowsTojstring2( JNIEnv* env, char* str )
    jstring rtn = 0;
    int slen = strlen(str);
    unsigned short* buffer = 0;
    if( slen == 0 )
    rtn = (*env)->NewStringUTF(env,str );
    else
    int length = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)str, slen, NULL, 0 );
    buffer = malloc( length*2 + 1 );
    if( MultiByteToWideChar( CP_ACP, 0, (LPCSTR)str, slen, (LPWSTR)buffer, length ) >0 )
    rtn = (*env)->NewString( env, (jchar*)buffer, length );
    if( buffer )
    free( buffer );
    return rtn;
    Rebuild jdk source code as per sun build document. Got the result files and pick up jsound.dll, replace the original jsound.dll in your JRE with the fixed file.
    Then the problem solved. I also hope sun will fix the problem in the future version of JDK.
    Or any one can help me to submit this article to the sun JDK team.
    Jiawei Zhang
    From Chinese, The city of Shanghai.
    MSN: [email protected]

    If you only wanted to get a beep you could have used Toolkit.beep
    Very simple and fast.
    Rommie.

Maybe you are looking for