[speex-dev] Lost ogg sync using jspeex
rthummal
rthummal at csnet.cs.odu.edu
Fri May 14 08:32:06 PDT 2004
Hi
I am getting lost ogg sync exception when I tried to decompress a speex stream. I am using the following program for both compressing as well as decompressing. I am just planning to test how jspeex works.
// File AudioCapture.java
import javax.sound.sampled.spi.*;
import javax.sound.sampled.*;
import org.xiph.speex.spi.*;
import java.util.*;
import java.net.*;
import java.io.*;
public class AudioCapture
{
public static void main(String args[])
{
int bufferlength=44100;
int framelength=1280;
int frameduration=1000;
Vector recordBuffer=new Vector();
try
{
AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 8000, 16, 1, 2, 8000, true);
System.out.println("AudioFormat Created");
DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class,audioFormat,8000);
System.out.println("Dataline.Info Created");
//DataLine.Info outputDataLineInfo = new DataLine.Info(SourceDataLine.class,audioFormat,44100);
TargetDataLine targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
System.out.println("TargetDataLine Created");
//SourceDataLine sourceDataLine = (SourceDataLine) AudioSystem.getLine(outputDataLineInfo);
AudioInputStream auin=new AudioInputStream(targetDataLine);
PipedOutputStream pout=new PipedOutputStream();
//PipedInputStream pin=new PipedInputStream(pout);
//ServerSocket serverSocket = new ServerSocket(5555);
Pcm2SpeexAudioInputStream pcm2speex=new Pcm2SpeexAudioInputStream(auin, audioFormat, AudioSystem.NOT_SPECIFIED);
SpeexPlayer speexPlayer = new SpeexPlayer(pout);
//Speex2PcmAudioInputStream speex2pcm=new Speex2PcmAudioInputStream(pin, audioFormat,AudioSystem.NOT_SPECIFIED);
//Socket clientSocket = serverSocket.accept();
//ObjectOutputStream toClient = new ObjectOutputStream(clientSocket.getOutputStream());
//BufferedReader fromClient = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
targetDataLine.open(audioFormat,8000);
targetDataLine.start();
//sourceDataLine.open(audioFormat,44100);
//sourceDataLine.start();
double ratio=bufferlength/framelength;
byte[] frame=new byte[framelength];
System.out.println("Entering While...");
System.out.println("Writing into piped output stream done...");
System.out.println("Constructing speex encoder.");
System.out.println("Speex encoder constructed.");
System.out.println("Speex info: ");
System.out.println("Bitrate: "+pcm2speex.getEncoder().getBitRate());
System.out.println("Frame size: "+pcm2speex.getEncoder().getFrameSize());
System.out.println("Complexity: "+pcm2speex.getEncoder().getComplexity());
System.out.println("Mode: "+pcm2speex.getEncoder().getMode());
System.out.println("Sampling rate: "+pcm2speex.getEncoder().getSamplingRate());
System.out.println("relative quality: "+pcm2speex.getEncoder().getRelativeQuality());
System.out.println("*** end of speex info");
System.out.println("everything ok in writer");
//int count = 0;
speexPlayer.start();
while(true)
{
/*count++;
if(count == 11)
{
System.exit(0);
}*/
frame=new byte[framelength];
//System.out.println("Reading from Audio Input Stream...");
//int n=auin.read(frame, 0, frame.length);
//System.out.println("Reading Done by Audio InputStream...");
//System.out.println("Writing into Piped Output Stream...");
//System.out.println(frame.length);
//int m=pcm2speex.read();
pcm2speex.read(frame);
System.out.println("Frame buffer Successfully Read");
for(int i = 0;i<framelength;i++)
{
System.out.print(frame[i]);
}
System.out.println("End of Frame Contents...");
pout.write(frame,0,framelength);
System.out.println("Wrote into Pout");
//System.out.println("Read by Spx.."+m);
//recordBuffer.addElement(frame);
//byte[] buffer=(byte[]) recordBuffer.elementAt(0);
//toClient.write(buffer);
//toClient.flush();
//recordBuffer.removeElementAt(0);
}
}
catch(LineUnavailableException e)
{
System.out.println("LineUnavailableException...."+e.getMessage());
}
catch(IOException e)
{
System.out.println("IOException ....."+e.getMessage());
}
}
}
class SpeexPlayer extends Thread
{
PipedOutputStream pout;
PipedInputStream pin;
AudioFormat audioFormat;
int bufferlength;
DataLine.Info outputDataLineInfo;
SourceDataLine sourceDataLine;
Speex2PcmAudioInputStream speex2pcm;
byte[] tempBuffer;
int framelength;
int count;
double ratio;
public SpeexPlayer(PipedOutputStream pout)
{
try
{
this.pout = pout;
pin = new PipedInputStream(pout);
count = 0;
framelength = 1280;
bufferlength = 1280;
tempBuffer = new byte[bufferlength];
//ratio = bufferlength / framelength;
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, false);
outputDataLineInfo = new DataLine.Info(SourceDataLine.class,audioFormat,44100);
sourceDataLine = (SourceDataLine) AudioSystem.getLine(outputDataLineInfo);
speex2pcm=new Speex2PcmAudioInputStream(pin, audioFormat,AudioSystem.NOT_SPECIFIED);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
}
catch(IOException e)
{
System.out.println("Exception raised in SpeexPlayer..."+e.getMessage());
}
catch(LineUnavailableException e)
{
System.out.println("Exception raised in SpeexPlayer..."+e.getMessage());
}
}
public void run()
{
while(true)
{
count++;
try
{
speex2pcm.read(tempBuffer);
System.out.println("Successfully decoded..."+count);
}
catch(IOException e)
{
System.out.println("Exception raised in thread of SpeexPlayer..."+e.getMessage());
System.out.println("Count is...."+count);
}
//try
//{
sourceDataLine.write(tempBuffer,0,framelength);
tempBuffer = new byte[bufferlength];
/*try
{
sleep(5000);
}
catch(InterruptedException e)
{
}*/
/*}
catch(IOException e)
{
System.out.println("Exception raised in thread of SpeexPlayer..."+e.getMessage());
}*/
}
}
}
Any kind of help would be very great
Thanks in advance...
Raghu
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'speex-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Speex-dev
mailing list