My objective is very simple, I want to transmit string data from PC1 to PC2 through an audio cable using the PCM methodology. However, I'm encountering some problems when I record the data from PC2. In fact I was expecting ASCII numeric values, instead I read values like these:
1111000-100111100010211211100222312121222222121111111111000000000-10-2-1-1-1-1-1-10-1-1-1-1-2-2-2-1-2-2-1-1-2-2-2-1-1-10-1-1-1-3-2-2-1-1-1110-10-10-1011110-10011100-20-10000-1000-10-1-1-1000-1-1-1-2-1-1-1-10-10-1-1-2-1-1-1000000101100101110011113121111222312111122111111021111101000010000-1-1-10-1010100110011011111012121110-1-3-5-4-4-7-8-11-15-15-19-23-27-34-38-38-32-28-27-31-33-34-34-32-25-14228568510912212612311811310810396888175747577798079745933-3-47-84-110-116-99-62-162757727264565151525248433735363836302092151421242215109101416123-9-19-22-17-82661-2-4-4-2-3-4-6-8-8-8-8-8-9-11-11-11-10-10-10-11-12-12-11-9-7-8-9-10-8-4030-5-51111710-15-52-90-118-127-121-109-98-94-93-96-93-87-5-5-5-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-7-7-6-6-6-6-7-6-6-6-6-6-6-6-6-6-7-5-5-6-6-6-5-6-6-6-5-6-6-5-5-5-6-6-6-5-6-5-5-5-5-4-5-5-5-4-5-5-5-5-5-5-5-4-5-4-4-4-4-4-4-4-4-4-3-3-3-4-3-3-3-3-3-2-4-3-2-4-2-2-2-3-3-2-2-3-2-2-2-3-2-3-2-2-2-2-2-2-1-2-1-1-1-1-2-1-1-1-1-1-1-10-2-
here you can find the code that I use to read data from Microphone audio port:
public static void Setup_Audio_Read() throws Exception {
format = null;
targetInfo = null;
targetLine = null;
format = new AudioFormat(Encoding.PCM_SIGNED, 44000, 8, 1, 1, 44000, true);
targetInfo = new DataLine.Info(TargetDataLine.class, format);
targetLine = (TargetDataLine) AudioSystem.getLine(targetInfo);
targetLine.open(format, targetData.length); //targetLine.open(format,targetLine.getBufferSize());
targetLine.start();
}
private static long extendSign(long temp, int bitsPerSample) {
int extensionBits = 64 - bitsPerSample;
return (temp << extensionBits) >> extensionBits;
}
public static void ReadLineData() throws IOException {
nBytesRead = targetLine.read(targetData, 0, targetData.length);
}
static public void Read() throws Exception {
Setup_Audio_Read();
int waiting_time = 0;
int bytesread = 0;
PrintStream out = new PrintStream(new FileOutputStream("C:\\Users\\Ale\\Desktop\\Prova\\Token.txt"));
while (waiting_time < 500) {
ReadLineData();
System.out.println(waiting_time);
long temp = 0;
int i = 0;
int bitsPerSample = format.getSampleSizeInBits();
int bytesPerSample = bytesPerSample(bitsPerSample);
while (i < nBytesRead) {
temp = (targetData[i] & 0xffL);
temp = extendSign(temp, bitsPerSample);
out.print(temp);
i = i + bytesPerSample;
}
waiting_time +
}
out.close();
}
as you can see I used the suggestions reported in this forum: How do I use audio sample data from Java Sound?
but it seems doesn't work.
What do you think? How can I solve this problem? Thanks in advance. Regards.
Ale