Synchronize inputstream read and outputstream close to avoid segfaults. Add Werner xrun patch for xrun problems in linked portaudio.

cusax-fix
Damian Minkov 16 years ago
parent e07578b89b
commit d401fe9893

Binary file not shown.

@ -20,17 +20,43 @@
*/
public class MasterPortAudioStream
{
/**
* The device index we are currently using.
*/
private int deviceIndex = -1;
/**
* The stream pointer we are using or 0 if stopped and not initialized.
*/
private long stream = 0;
/**
* Whether this stream is started.
*/
private boolean started = false;
/**
* The frame size we use.
*/
private int frameSize;
double sampleRate;
/**
* The sample rate for the current stream.
*/
private double sampleRate;
int channels;
/**
* The number of channel for the current stream.
*/
private int channels;
/**
* This is the output stream which is connected to the current input stream.
* When using echo cancellation its the actual output stream, otherwise its
* just a non null object. Need to synch closing stream in order to avoid
* concurrency: using the output stream(in Pa_ReadStream) while closing it.
*/
private Object connectedToStreamSync = new Object();
/**
* The <tt>InputPortAudioStream</tt>s which read audio from this
@ -178,8 +204,12 @@ public synchronized byte[] read()
return new byte[0];
byte[] bytebuff = new byte[PortAudioManager.NUM_SAMPLES*frameSize];
PortAudio.Pa_ReadStream(
stream, bytebuff, PortAudioManager.NUM_SAMPLES);
synchronized(connectedToStreamSync)
{
PortAudio.Pa_ReadStream(
stream, bytebuff, PortAudioManager.NUM_SAMPLES);
}
for(InputPortAudioStream slave : slaves)
slave.setBuffer(bytebuff);
@ -201,6 +231,11 @@ public void setParams(OutputPortAudioStream out,
boolean deNoiseEnabled,
boolean echoCancelEnabled, int frameSize, int filterLength)
{
if(out != null)
{
this.connectedToStreamSync = out.getCloseSyncObject();
}
long outStream = (out == null) ? 0 : out.getStream();
PortAudio.setEchoCancelParams(

@ -16,18 +16,53 @@
*/
public class OutputPortAudioStream
{
/**
* The device index we are currently using.
*/
private final int deviceIndex;
/**
* The sample rate for the current stream.
*/
private final double sampleRate;
/**
* The number of channel for the current stream.
*/
private final int channels;
/**
* The sample format for the current stream.
*/
private final long sampleFormat;
/**
* The frame size we use.
*/
private final int frameSize;
/**
* The stream pointer we are using or 0 if stopped and not initialized.
*/
private long stream;
/**
* Whether this stream is started.
*/
private boolean started = false;
/**
* Buffer left for writing from previous write,
* as everything is split into parts of PortAudioManager.NUM_SAMPLES,
* this is what has left.
*/
private byte[] bufferLeft = null;
/**
* We use this object to sync input stream reads with this output stream
* closes, if this output stream is connected to input stream(when using
* echo cancellation). Cause input stream uses output stream while reading
* and must not use it while this stream is closing.
*/
private Object closeSyncObject = new Object();
/**
* Creates output stream.
* @param deviceIndex the index of the device to use.
@ -78,8 +113,11 @@ public synchronized void close()
if(stream != 0)
{
// stop
PortAudio.Pa_CloseStream(stream);
stream = 0;
synchronized(closeSyncObject)
{
PortAudio.Pa_CloseStream(stream);
stream = 0;
}
PortAudioManager.getInstance().closedOutputPortAudioStream(this);
}
@ -233,4 +271,13 @@ public long getStream()
{
return stream;
}
/**
* Return the object we have used to synchronize Pa_CloseStream.
* @return the closeSyncObject the sync object.
*/
Object getCloseSyncObject()
{
return closeSyncObject;
}
}

Loading…
Cancel
Save