I learned that the Line In does not automatically get fed to the SPDIF
output. I wrote the following program to perform this function. It's
working very well right now: I can hear my Wii through Line In and out
to my Home Theater Receiver via SPDIF.
Here's the software in case anyone else is interested:
// package intellisig.audio;
// $Id: Audio.java 170 2007-11-17 00:32:46Z johnr $
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
/**
* This is a simple program to read from the default input sound
device
* and write to the default output sound device. In my case the
default input
* sound device is Line In and the default output device is the SPDIF
* digital output on my Asus P5W DH Deluxe motherboard.
*
* I wrote this problem so that I could run the audio from my Wii
* through the computer and to my Home Theater receiver. I use the
* composite video input on one of my monitors to watch the Wii.
* The Home Theater receiver is across my office and I didn't want to
* have to run an analog audio cable from the Wii to the receiver.
* BTW, I have a component Wii video cable on order which I'll then
* run through a "480p component to VGA" box that I have. I've used
* this setup with XBox in the past. It's nice that XBox has digital
* audio unlike the Wii which is only 2 channel analog.
*
* I didn't realize that I would need to write this problem. In the
* past I've been able to plug an audio source into the Line In port
* on a sound card or motherboard and hear the audio through the
* speakers. Aparently with the Asus motherboard or maybe with SPDIF
* in general this "monitor" feature is not present.
*
* Therefore I wrote this very simple program to read audio in from
* Line In and send it to SPDIF.
*
* Hopefully it will help someone else. It took me longer to write
this
* note than to write the software so there are probably many
improvements
* that could be made.
*
* Instructions:
*
* 1. Get the J2SE JDK/SDK from Sun at
www.javasoft.com and install
it.
* 2. Save this source code to a file called Audio.java.
* 3. Compile using "javac Audio.java"
* 4. Run using "java Audio"
* 5. Control-C to quit
*
* John Roberts
* IntelliSig, Inc.
* J O H N -AT- I N T E L L I S I G .DOT. COM
*
*
* Copyright (C) 2007 John S. Roberts
*
* This program is free software: you can redistribute it and/or
modify
* it under the terms of the GNU General Public License as
published by
* the Free Software Foundation, either version 3 of the License,
or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
License
* along with this program. If not, see <
http://www.gnu.org/
licenses/>.
*
* @author John Roberts
*/
public class Audio
{
public void run()
{
try
{
AudioFormat audioFormat = new AudioFormat(48000.0f, // float
sampleRate
16, // int sampleSizeInBits
2, // int channels
true, // boolean signed
true); // boolean bigEndian
TargetDataLine targetDataLine =
AudioSystem.getTargetDataLine(audioFormat);
SourceDataLine sourceDataLine =
AudioSystem.getSourceDataLine(audioFormat);
targetDataLine.open(audioFormat);
sourceDataLine.open(audioFormat);
targetDataLine.start();
sourceDataLine.start();
int toRead;
int numRead;
int numWritten;
byte[] bytes = new byte[1024 * 64];
while (true)
{
int available;
while ((available = targetDataLine.available()) == 0)
{
Thread.sleep(300);
// println("Available=" + available);
}
toRead = Math.min(available, bytes.length);
numRead = targetDataLine.read(bytes, 0, toRead);
numWritten = 0;
while (numRead > 0)
{
numWritten = sourceDataLine.write(bytes, numWritten, numRead);
numRead -= numWritten;
// println("toRead=" + toRead + " numRead=" + numRead + "
numWritten=" + numWritten);
}
}
}
catch (LineUnavailableException e)
{
e.printStackTrace();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
public static void println(String line)
{
System.out.println(line);
}
public static void main(String[] args)
{
Audio audio = new Audio();
audio.run();
}
}