Commit 0ce4b472 authored by sletz's avatar sletz
Browse files

Automatic adaptative ringbuffer size mode when -g = 0.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3423 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 74c74ac6
......@@ -27,6 +27,7 @@ Torben Hohn
2009-03-10 Stephane Letz <letz@grame.fr>
* Add -g (ring-buffer) parameter to netadapter.
* Automatic adaptative ringbuffer size mode when -g = 0.
2009-03-09 Stephane Letz <letz@grame.fr>
......
......@@ -153,10 +153,16 @@ namespace Jack
void JackAudioAdapterInterface::ResetRingBuffers()
{
if (fRingbufferSize == 0) {
fRingbufferCurSize *=2;
if (fRingbufferCurSize > DEFAULT_RB_SIZE)
fRingbufferCurSize = DEFAULT_RB_SIZE;
}
for (int i = 0; i < fCaptureChannels; i++)
fCaptureRingBuffer[i]->Reset();
fCaptureRingBuffer[i]->Reset(fRingbufferCurSize);
for (int i = 0; i < fPlaybackChannels; i++)
fPlaybackRingBuffer[i]->Reset();
fPlaybackRingBuffer[i]->Reset(fRingbufferCurSize);
}
void JackAudioAdapterInterface::Reset()
......@@ -170,11 +176,22 @@ namespace Jack
//ringbuffers
fCaptureRingBuffer = new JackResampler*[fCaptureChannels];
fPlaybackRingBuffer = new JackResampler*[fPlaybackChannels];
for (int i = 0; i < fCaptureChannels; i++ )
fCaptureRingBuffer[i] = new JackLibSampleRateResampler(fQuality, fRingbufferSize);
for (int i = 0; i < fPlaybackChannels; i++ )
fPlaybackRingBuffer[i] = new JackLibSampleRateResampler(fQuality, fRingbufferSize);
fRingbufferCurSize = (fRingbufferSize == 0) ? DEFAULT_ADAPTATIVE_SIZE : DEFAULT_RB_SIZE;
if (fRingbufferSize == 0) {
jack_info("Ringbuffer automatic adaptative mode");
}
for (int i = 0; i < fCaptureChannels; i++ ) {
fCaptureRingBuffer[i] = new JackLibSampleRateResampler(fQuality);
fCaptureRingBuffer[i]->Reset(fRingbufferCurSize);
}
for (int i = 0; i < fPlaybackChannels; i++ ) {
fPlaybackRingBuffer[i] = new JackLibSampleRateResampler(fQuality);
fPlaybackRingBuffer[i]->Reset(fRingbufferCurSize);
}
if (fCaptureChannels > 0)
jack_log("ReadSpace = %ld", fCaptureRingBuffer[0]->ReadSpace());
if (fPlaybackChannels > 0)
......@@ -213,7 +230,7 @@ namespace Jack
}
for (int i = 0; i < fPlaybackChannels; i++) {
fPlaybackRingBuffer[i]->SetRatio(1 / ratio);
fPlaybackRingBuffer[i]->SetRatio(1/ratio);
if (fPlaybackRingBuffer[i]->ReadResample(outputBuffer[i], inNumberFrames) < inNumberFrames)
failure = true;
}
......
......@@ -90,6 +90,7 @@ namespace Jack
unsigned int fQuality;
unsigned int fRingbufferSize;
unsigned int fRingbufferCurSize;
jack_time_t fPullAndPushTime;
bool fRunning;
......@@ -108,6 +109,7 @@ namespace Jack
fPIControler(sample_rate / sample_rate, 256),
fCaptureRingBuffer(NULL), fPlaybackRingBuffer(NULL),
fQuality(0), fRingbufferSize(DEFAULT_RB_SIZE),
fRingbufferCurSize(0),
fPullAndPushTime(0),
fRunning(false)
{}
......
......@@ -31,8 +31,8 @@ JackLibSampleRateResampler::JackLibSampleRateResampler()
jack_error("JackLibSampleRateResampler::JackLibSampleRateResampler err = %s", src_strerror(error));
}
JackLibSampleRateResampler::JackLibSampleRateResampler(unsigned int quality, unsigned int ringbuffer_size)
:JackResampler(ringbuffer_size)
JackLibSampleRateResampler::JackLibSampleRateResampler(unsigned int quality)
:JackResampler()
{
switch (quality) {
case 0:
......@@ -67,9 +67,9 @@ JackLibSampleRateResampler::~JackLibSampleRateResampler()
src_delete(fResampler);
}
void JackLibSampleRateResampler::Reset()
void JackLibSampleRateResampler::Reset(unsigned int new_size)
{
JackResampler::Reset();
JackResampler::Reset(new_size);
src_reset(fResampler);
}
......
......@@ -40,13 +40,13 @@ class JackLibSampleRateResampler : public JackResampler
public:
JackLibSampleRateResampler();
JackLibSampleRateResampler(unsigned int quality, unsigned int ringbuffer_size);
JackLibSampleRateResampler(unsigned int quality);
virtual ~JackLibSampleRateResampler();
unsigned int ReadResample(float* buffer, unsigned int frames);
unsigned int WriteResample(float* buffer, unsigned int frames);
void Reset();
void Reset(unsigned int new_size);
};
}
......
......@@ -30,23 +30,17 @@ JackResampler::JackResampler()
jack_ringbuffer_read_advance(fRingBuffer, (sizeof(float) * fRingBufferSize) / 2);
}
JackResampler::JackResampler(unsigned int ringbuffer_size)
:fRatio(1),fRingBufferSize(ringbuffer_size)
{
fRingBuffer = jack_ringbuffer_create(sizeof(float) * fRingBufferSize);
jack_ringbuffer_read_advance(fRingBuffer, (sizeof(float) * fRingBufferSize) / 2);
}
JackResampler::~JackResampler()
{
if (fRingBuffer)
jack_ringbuffer_free(fRingBuffer);
}
void JackResampler::Reset()
void JackResampler::Reset(unsigned int new_size)
{
jack_ringbuffer_reset(fRingBuffer);
jack_ringbuffer_read_advance(fRingBuffer, (sizeof(float) * fRingBufferSize) / 2);
fRingBufferSize = new_size;
jack_ringbuffer_reset_size(fRingBuffer, sizeof(float) * fRingBufferSize);
jack_ringbuffer_read_advance(fRingBuffer, (sizeof(float) * fRingBufferSize / 2));
}
unsigned int JackResampler::ReadSpace()
......
......@@ -26,7 +26,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
#define DEFAULT_RB_SIZE 16384
#define DEFAULT_RB_SIZE 32768
#define DEFAULT_ADAPTATIVE_SIZE 2048
inline float Range(float min, float max, float val)
{
......@@ -49,10 +50,9 @@ class JackResampler
public:
JackResampler();
JackResampler(unsigned int ringbuffer_size);
virtual ~JackResampler();
virtual void Reset();
virtual void Reset(unsigned int new_size);
virtual unsigned int ReadResample(float* buffer, unsigned int frames);
virtual unsigned int WriteResample(float* buffer, unsigned int frames);
......
......@@ -192,6 +192,16 @@ int jack_ringbuffer_mlock(jack_ringbuffer_t *rb);
*/
void jack_ringbuffer_reset(jack_ringbuffer_t *rb);
/**
* Reset the internal "available" size, and read and write pointers, making an empty buffer.
*
* This is not thread safe.
*
* @param rb a pointer to the ringbuffer structure.
* @param sz the new size, that must be less than allocated size.
*/
void jack_ringbuffer_reset_size (jack_ringbuffer_t * rb, size_t sz);
/**
* Write data into the ringbuffer.
*
......
......@@ -55,6 +55,7 @@ EXPORT void jack_ringbuffer_read_advance(jack_ringbuffer_t *rb, size_t cnt);
EXPORT size_t jack_ringbuffer_read_space(const jack_ringbuffer_t *rb);
EXPORT int jack_ringbuffer_mlock(jack_ringbuffer_t *rb);
EXPORT void jack_ringbuffer_reset(jack_ringbuffer_t *rb);
EXPORT void jack_ringbuffer_reset_size (jack_ringbuffer_t * rb, size_t sz);
EXPORT size_t jack_ringbuffer_write(jack_ringbuffer_t *rb, const char *src,
size_t cnt);
void jack_ringbuffer_write_advance(jack_ringbuffer_t *rb, size_t cnt);
......@@ -123,6 +124,19 @@ jack_ringbuffer_reset (jack_ringbuffer_t * rb)
rb->write_ptr = 0;
}
/* Reset the read and write pointers to zero. This is not thread
safe. */
EXPORT void
jack_ringbuffer_reset_size (jack_ringbuffer_t * rb, size_t sz)
{
rb->size = sz;
rb->size_mask = rb->size;
rb->size_mask -= 1;
rb->read_ptr = 0;
rb->write_ptr = 0;
}
/* Return the number of bytes available for reading. This is the
number of bytes in front of the read pointer and behind the write
pointer. */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment