Commit b02b6c17 authored by michelebussolotto@gmail.com's avatar michelebussolotto@gmail.com
Browse files

- Improve debug information

- Bug fix in RingBuffer
- Improve performance of uniform resampler
- add JackTrip.cpp
parent c3c692cd
This diff is collapsed.
......@@ -56,7 +56,6 @@
#endif //__NO_JACK__
#include "PacketHeader.h"
#include "RingBuffer.h"
#include <signal.h>
/** \brief Main class to creates a SERVER (to listen) or a CLIENT (to connect
......@@ -379,8 +378,10 @@ public:
jack_client_t* getClient() const{ return ((JackAudioInterface*)mAudioInterface)->getClient(); }
void setClient(jack_client_t* client){ ((JackAudioInterface*)mAudioInterface)->setClient(client); }
const char* getClientName() const{return ((JackAudioInterface*)mAudioInterface)->getClientName();}
void setUniformResampler( VResampler* uniformResampler_local) {uniformResampler = uniformResampler_local;}
VResampler* getUniformResampler() { return uniformResampler;}
void setAdaptiveResampler( VResampler* uniformResampler_local) {adaptiveResampler = uniformResampler_local;}
void setUniformResampler( Resampler* uniformResampler_local) {uniformResampler = uniformResampler_local;}
VResampler* getAdaptiveResampler() { return adaptiveResampler;}
Resampler* getUniformResampler() { return uniformResampler;}
int8_t* getInputPacket() {return mAudioInterface->getInputPacket();}
void setInputPacket(int8_t* inputPacket) {mAudioInterface->setInputPacket(inputPacket);}
int8_t* getOutputPacket() {return mAudioInterface->getOutputPacket();}
......@@ -687,7 +688,8 @@ private:
volatile bool mReceivedConnection; ///< Bool of received connection from peer
volatile bool mTcpConnectionError;
VResampler *uniformResampler; ///< Pointer to resampler
VResampler *adaptiveResampler; ///< Pointer to resampler
Resampler *uniformResampler; ///< Pointer to resampler
float t_local_del; ///< Time Frame of local host
float t_peer_del ; ///< Time Frame of peer host
float ratio_del; ///< Ratio beetween timeframe/samplerate of local host and peer host
......
......@@ -70,15 +70,6 @@ RingBuffer::RingBuffer(JackTrip* jackTrip, int size,char type) :
deltaXrun(0),
arr(0),
countC(0),
peerPeriodVector(new QVector<uint32_t>(0)),
localPeriodVector(new QVector<uint32_t>(0)),
ratioVector(new QVector<float>(0)),
arrVector(new QVector<float>(0)),
totalSizeVector(new QVector<int32_t>(0)),
readSpaceVector(new QVector<int16_t>(0)),
writeSpaceVector(new QVector<int16_t>(0)),
nReadVector(new QVector<int32_t>(0)),
countCVector(new QVector<int>(0)),
XRunHappened(0)
{
......@@ -203,33 +194,106 @@ int RingBuffer::readSlotAndResampler(int8_t* ptrToReadSlot)
info();
countC = 0;
#endif
if(mJackTrip->isOnAdaptive() ==true)
if(mJackTrip->isOnAdaptive() ==true){
this->setupAdaptive();
nRead = 0;
int frameWorstCase = ceil(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()*mJackTrip->getNumChans()*mJackTrip->getAudioBitResolution()/8) -
mJackTrip->getNumChans()*mJackTrip->getAudioBitResolution()/8;
int frameWorstCase = mJackTrip->getAudioBitResolution()/8*mJackTrip->getNumChans()*floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel());
#ifdef __DEBUG__
cout << "frameWorstCase " << frameWorstCase << endl;
#endif
readNoAdvance(reinterpret_cast<char*>(inputSampleInByte), frameWorstCase);
if(XRunHappened)
return 1;
#ifdef __DEBUG__
cout << "seconda "<< mJackTrip->getNumChans()*floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()) << endl;
#endif
for(int i = 0; i < mJackTrip->getNumChans()*floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()); i++)
mJackTrip->fromBitToSampleConversion(&(inputSampleInByte[i*mJackTrip->getAudioBitResolution()/8]),&inputSampleInterleaved[i], mJackTrip->getAudioBitResolution());
// Setup the resampler and process the samp
#ifdef __DEBUG__
cout << "terza " << floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel())<< endl;
#endif
mJackTrip->getAdaptiveResampler()->inp_count = floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel());
tmpNRead = mJackTrip->getAdaptiveResampler()->inp_count ;
mJackTrip->getAdaptiveResampler()->inp_data = inputSampleInterleaved;
mJackTrip->getAdaptiveResampler()->out_count = mJackTrip->getBufferSizeInSamples() ;
mJackTrip->getAdaptiveResampler()->out_data = outputSampleInterleaved;
while(mJackTrip->getAdaptiveResampler()->out_count && !XRunHappened){
if (mJackTrip->getAdaptiveResampler()->process()){}
// emit signalError("Resampler Error!");
tmpNRead -= mJackTrip->getAdaptiveResampler()->inp_count ;
//cout << tmpNRead << endl;
nRead += tmpNRead;
if (tmpNRead > mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()){}
// emit signalError("Resampler Error!");
//cout << "nRead "<< nRead << endl;
readPointerAdvance(tmpNRead*mJackTrip->getNumChans()*mJackTrip->getAudioBitResolution()/8);
if(mJackTrip->getAdaptiveResampler()->out_count == 0)
continue;
readNoAdvance(reinterpret_cast<char*>(tmpByte), mJackTrip->getNumChans()*mJackTrip->getAudioBitResolution()/8);
if(XRunHappened)
continue;
for(int i = 0; i < mJackTrip->getNumChans(); i++)
mJackTrip->fromBitToSampleConversion(&tmpByte[i*mJackTrip->getAudioBitResolution()/8],&tmpSample[i], mJackTrip->getAudioBitResolution());
mJackTrip->getAdaptiveResampler()->inp_data = tmpSample;
mJackTrip->getAdaptiveResampler()->inp_count = 1;
tmpNRead = mJackTrip->getAdaptiveResampler()->inp_count;
++countC;
}
//cout << "nRead" << nRead << endl;
//DeInterleave
for(int i=0; i<mJackTrip->getBufferSizeInSamples(); i++)
for(uint16_t j=0; j<mJackTrip->getNumChans(); j++){
outputSampleDeInterleaved[j*mJackTrip->getBufferSizeInSamples()+i]
= outputSampleInterleaved[j + i*mJackTrip->getNumChans() ];
}
// Convert Samples in bytes
for(int i = 0; i < ((int)mJackTrip->getBufferSizeInSamples())*mJackTrip->getNumChans(); i++)
mJackTrip->fromSampleToBitConversion(&outputSampleDeInterleaved[i],&ptrToReadSlot[i*mJackTrip->getAudioBitResolution()/8], mJackTrip->getAudioBitResolution());
// Always save memory of the last read slot
std::memset(mLastReadSlot, 0, mJackTrip->getSizeInBytesPerChannel()*mJackTrip->getNumChans()); // set buffer to 0
std::memcpy(mLastReadSlot, (int8_t*)ptrToReadSlot, mJackTrip->getSizeInBytesPerChannel()*mJackTrip->getNumChans());
mBufferIsNotFull.wakeAll();
return 1;
}else{
nRead = 0;
int frameWorstCase = mJackTrip->getAudioBitResolution()/8*mJackTrip->getNumChans()*floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel());
#ifdef __DEBUG__
cout << "frameWorstCase " << frameWorstCase << endl;
#endif
readNoAdvance(reinterpret_cast<char*>(inputSampleInByte), frameWorstCase);
if(XRunHappened)
return 1;
for(int i = 0; i < ceil(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()*mJackTrip->getNumChans()) - mJackTrip->getNumChans(); i++)
#ifdef __DEBUG__
cout << "seconda "<< mJackTrip->getNumChans()*floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()) << endl;
#endif
for(int i = 0; i < mJackTrip->getNumChans()*floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()); i++)
mJackTrip->fromBitToSampleConversion(&(inputSampleInByte[i*mJackTrip->getAudioBitResolution()/8]),&inputSampleInterleaved[i], mJackTrip->getAudioBitResolution());
// Setup the resampler and process the samp
mJackTrip->getUniformResampler()->inp_count = ceil(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()) - 1;
#ifdef __DEBUG__
cout << "terza " << floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel())<< endl;
#endif
mJackTrip->getUniformResampler()->inp_count = floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel());
tmpNRead = mJackTrip->getUniformResampler()->inp_count ;
mJackTrip->getUniformResampler()->inp_data = inputSampleInterleaved;
mJackTrip->getUniformResampler()->out_count = mJackTrip->getBufferSizeInSamples() ;
mJackTrip->getUniformResampler()->out_data = outputSampleInterleaved;
while(mJackTrip->getUniformResampler()->out_count && !XRunHappened){
if (mJackTrip->getUniformResampler()->process())
emit signalError("Resampler Error!");
if (mJackTrip->getUniformResampler()->process()){}
tmpNRead -= mJackTrip->getUniformResampler()->inp_count ;
//cout << tmpNRead << endl;
nRead += tmpNRead;
if (tmpNRead > mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel())
emit signalError("Resampler Error!");
if (tmpNRead > mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()){}
//cout << "nRead "<< nRead << endl;
readPointerAdvance(tmpNRead*mJackTrip->getNumChans()*mJackTrip->getAudioBitResolution()/8);
if(mJackTrip->getUniformResampler()->out_count == 0)
......@@ -250,7 +314,7 @@ int RingBuffer::readSlotAndResampler(int8_t* ptrToReadSlot)
//DeInterleave
for(int i=0; i<mJackTrip->getBufferSizeInSamples(); i++)
for(uint16_t j=0; j<mJackTrip->getNumChans(); j++){
outputSampleDeInterleaved[j*mJackTrip->getPeerBufferSize()+i]
outputSampleDeInterleaved[j*mJackTrip->getBufferSizeInSamples()+i]
= outputSampleInterleaved[j + i*mJackTrip->getNumChans() ];
}
......@@ -265,31 +329,17 @@ int RingBuffer::readSlotAndResampler(int8_t* ptrToReadSlot)
mBufferIsNotFull.wakeAll();
return 1;
}
}
int RingBuffer::setupAdaptive(){
arr = ((mJackTrip->getPeerEstimatedPeriod()*mJackTrip->getRatioDel())/mJackTrip->getEstimatedPeriod());
mJackTrip->getUniformResampler()->set_rratio(arr);
mJackTrip->getAdaptiveResampler()->set_rratio(arr);
return 0;
}
void RingBuffer::info(){
arr = (mJackTrip->getPeerEstimatedPeriod()*mJackTrip->getRatioDel())/mJackTrip->getEstimatedPeriod();
if(arrVector->size()>= SIZEVECTOR)
arrVector->pop_front();
arrVector->push_back(arr);
if(readSpaceVector->size()>= SIZEVECTOR)
readSpaceVector->pop_front();
readSpaceVector->push_back(readSpace());
if(writeSpaceVector->size()>= SIZEVECTOR)
writeSpaceVector->pop_front();
writeSpaceVector->push_back(writeSpace());
if(nReadVector->size()>= SIZEVECTOR)
nReadVector->pop_front();
nReadVector->push_back(nRead);
if(countCVector->size()>= SIZEVECTOR)
countCVector->pop_front();
countCVector->push_back(countC);
}
......@@ -346,50 +396,6 @@ void RingBuffer::overflowReset()
//*******************************************************************************
void RingBuffer::debugDump() const
{
QString strpeerPeriodVector;
QString strarrVector;
strarrVector += "arrVector \t\t";
for (int it = 0; it < arrVector->size(); ++it)
{
strarrVector += QString::number(arrVector->value(it));
strarrVector += "\t";
}
QString strreadPositionVector;
strreadPositionVector += "readSpaceVector \t\t";
for (int it = 0; it < readSpaceVector->size(); ++it)
{
strreadPositionVector += QString::number(readSpaceVector->value(it));
strreadPositionVector += "\t";
}
QString strwritePositionVector;
strwritePositionVector += "writeSpaceVector \t\t";
for (int it = 0; it < writeSpaceVector->size(); ++it)
{
strwritePositionVector += QString::number(writeSpaceVector->value(it));
strwritePositionVector += "\t";
}
QString strnReadVector;
strnReadVector += "nReadVector \t\t";
for (int it = 0; it < nReadVector->size(); ++it)
{
strnReadVector += QString::number(nReadVector->value(it));
strnReadVector += "\t";
}
QString strcountCVector;
strcountCVector += "countCVector \t\t";
for (int it = 0; it < countCVector->size(); ++it)
{
strcountCVector += QString::number(countCVector->value(it));
strcountCVector += "\t";
}
cout << "RingBuffer Type: " << mType << endl;
cout << strarrVector.toUtf8().constData() << endl;
cout << strreadPositionVector.toUtf8().constData() << endl;
cout << strwritePositionVector.toUtf8().constData() << endl;
cout << strnReadVector.toUtf8().constData() << endl;
cout << strcountCVector.toUtf8().constData() << endl;
}
......
......@@ -41,9 +41,6 @@
#include <QWaitCondition>
#include <QMutex>
#include <QMutexLocker>
#include <QObject>
#include <QString>
#include <QVector>
#include <iostream>
#include <cmath>
#include <jack/jack.h>
......@@ -62,9 +59,8 @@ class JackTrip;
* each of which is of size \b SlotSize bytes (8-bits). Slots can be read and
* written asynchronously/synchronously by multiple threads.
*/
class RingBuffer : public QObject
class RingBuffer
{
Q_OBJECT;
public:
......@@ -160,8 +156,6 @@ protected:
JackTrip* mJackTrip;
signals:
void signalError(const char* error_message);
private:
......@@ -198,15 +192,6 @@ private:
double deltaXrun; ///< time between the 2 last xrun
float arr;
int countC;
QVector<uint32_t>* peerPeriodVector;
QVector<uint32_t>* localPeriodVector;
QVector<float>* ratioVector;
QVector<float>* arrVector;
QVector<int32_t>* totalSizeVector;
QVector<int16_t>* readSpaceVector;
QVector<int16_t>* writeSpaceVector;
QVector<int32_t>* nReadVector;
QVector<int>* countCVector;
bool XRunHappened;
};
......
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