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 @@ ...@@ -56,7 +56,6 @@
#endif //__NO_JACK__ #endif //__NO_JACK__
#include "PacketHeader.h" #include "PacketHeader.h"
#include "RingBuffer.h"
#include <signal.h> #include <signal.h>
/** \brief Main class to creates a SERVER (to listen) or a CLIENT (to connect /** \brief Main class to creates a SERVER (to listen) or a CLIENT (to connect
...@@ -379,8 +378,10 @@ public: ...@@ -379,8 +378,10 @@ public:
jack_client_t* getClient() const{ return ((JackAudioInterface*)mAudioInterface)->getClient(); } jack_client_t* getClient() const{ return ((JackAudioInterface*)mAudioInterface)->getClient(); }
void setClient(jack_client_t* client){ ((JackAudioInterface*)mAudioInterface)->setClient(client); } void setClient(jack_client_t* client){ ((JackAudioInterface*)mAudioInterface)->setClient(client); }
const char* getClientName() const{return ((JackAudioInterface*)mAudioInterface)->getClientName();} const char* getClientName() const{return ((JackAudioInterface*)mAudioInterface)->getClientName();}
void setUniformResampler( VResampler* uniformResampler_local) {uniformResampler = uniformResampler_local;} void setAdaptiveResampler( VResampler* uniformResampler_local) {adaptiveResampler = uniformResampler_local;}
VResampler* getUniformResampler() { return uniformResampler;} void setUniformResampler( Resampler* uniformResampler_local) {uniformResampler = uniformResampler_local;}
VResampler* getAdaptiveResampler() { return adaptiveResampler;}
Resampler* getUniformResampler() { return uniformResampler;}
int8_t* getInputPacket() {return mAudioInterface->getInputPacket();} int8_t* getInputPacket() {return mAudioInterface->getInputPacket();}
void setInputPacket(int8_t* inputPacket) {mAudioInterface->setInputPacket(inputPacket);} void setInputPacket(int8_t* inputPacket) {mAudioInterface->setInputPacket(inputPacket);}
int8_t* getOutputPacket() {return mAudioInterface->getOutputPacket();} int8_t* getOutputPacket() {return mAudioInterface->getOutputPacket();}
...@@ -687,7 +688,8 @@ private: ...@@ -687,7 +688,8 @@ private:
volatile bool mReceivedConnection; ///< Bool of received connection from peer volatile bool mReceivedConnection; ///< Bool of received connection from peer
volatile bool mTcpConnectionError; 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_local_del; ///< Time Frame of local host
float t_peer_del ; ///< Time Frame of peer host float t_peer_del ; ///< Time Frame of peer host
float ratio_del; ///< Ratio beetween timeframe/samplerate of local host and 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) : ...@@ -70,15 +70,6 @@ RingBuffer::RingBuffer(JackTrip* jackTrip, int size,char type) :
deltaXrun(0), deltaXrun(0),
arr(0), arr(0),
countC(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) XRunHappened(0)
{ {
...@@ -203,93 +194,152 @@ int RingBuffer::readSlotAndResampler(int8_t* ptrToReadSlot) ...@@ -203,93 +194,152 @@ int RingBuffer::readSlotAndResampler(int8_t* ptrToReadSlot)
info(); info();
countC = 0; countC = 0;
#endif #endif
if(mJackTrip->isOnAdaptive() ==true) if(mJackTrip->isOnAdaptive() ==true){
this->setupAdaptive(); this->setupAdaptive();
nRead = 0; nRead = 0;
int frameWorstCase = ceil(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()*mJackTrip->getNumChans()*mJackTrip->getAudioBitResolution()/8) - int frameWorstCase = mJackTrip->getAudioBitResolution()/8*mJackTrip->getNumChans()*floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel());
mJackTrip->getNumChans()*mJackTrip->getAudioBitResolution()/8; #ifdef __DEBUG__
cout << "frameWorstCase " << frameWorstCase << endl;
readNoAdvance(reinterpret_cast<char*>(inputSampleInByte), frameWorstCase); #endif
if(XRunHappened) readNoAdvance(reinterpret_cast<char*>(inputSampleInByte), frameWorstCase);
return 1;
for(int i = 0; i < ceil(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()*mJackTrip->getNumChans()) - mJackTrip->getNumChans(); 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;
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!");
tmpNRead -= mJackTrip->getUniformResampler()->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->getUniformResampler()->out_count == 0)
continue;
readNoAdvance(reinterpret_cast<char*>(tmpByte), mJackTrip->getNumChans()*mJackTrip->getAudioBitResolution()/8);
if(XRunHappened) if(XRunHappened)
continue; return 1;
for(int i = 0; i < mJackTrip->getNumChans(); i++) #ifdef __DEBUG__
mJackTrip->fromBitToSampleConversion(&tmpByte[i*mJackTrip->getAudioBitResolution()/8],&tmpSample[i], mJackTrip->getAudioBitResolution()); cout << "seconda "<< mJackTrip->getNumChans()*floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()) << endl;
mJackTrip->getUniformResampler()->inp_data = tmpSample; #endif
mJackTrip->getUniformResampler()->inp_count = 1; for(int i = 0; i < mJackTrip->getNumChans()*floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()); i++)
tmpNRead = mJackTrip->getUniformResampler()->inp_count; mJackTrip->fromBitToSampleConversion(&(inputSampleInByte[i*mJackTrip->getAudioBitResolution()/8]),&inputSampleInterleaved[i], mJackTrip->getAudioBitResolution());
++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->getPeerBufferSize()+i]
= outputSampleInterleaved[j + i*mJackTrip->getNumChans() ];
}
// Convert Samples in bytes // Setup the resampler and process the samp
for(int i = 0; i < ((int)mJackTrip->getBufferSizeInSamples())*mJackTrip->getNumChans(); i++) #ifdef __DEBUG__
mJackTrip->fromSampleToBitConversion(&outputSampleDeInterleaved[i],&ptrToReadSlot[i*mJackTrip->getAudioBitResolution()/8], mJackTrip->getAudioBitResolution()); 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;
#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());
// Always save memory of the last read slot // Setup the resampler and process the samp
std::memset(mLastReadSlot, 0, mJackTrip->getSizeInBytesPerChannel()*mJackTrip->getNumChans()); // set buffer to 0 #ifdef __DEBUG__
std::memcpy(mLastReadSlot, (int8_t*)ptrToReadSlot, mJackTrip->getSizeInBytesPerChannel()*mJackTrip->getNumChans()); cout << "terza " << floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel())<< endl;
mBufferIsNotFull.wakeAll(); #endif
mJackTrip->getUniformResampler()->inp_count = floor(mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel());
return 1; 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()){}
tmpNRead -= mJackTrip->getUniformResampler()->inp_count ;
//cout << tmpNRead << endl;
nRead += tmpNRead;
if (tmpNRead > mJackTrip->getPeerBufferSize()*mJackTrip->getRatioDel()){}
//cout << "nRead "<< nRead << endl;
readPointerAdvance(tmpNRead*mJackTrip->getNumChans()*mJackTrip->getAudioBitResolution()/8);
if(mJackTrip->getUniformResampler()->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->getUniformResampler()->inp_data = tmpSample;
mJackTrip->getUniformResampler()->inp_count = 1;
tmpNRead = mJackTrip->getUniformResampler()->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;
}
} }
int RingBuffer::setupAdaptive(){ int RingBuffer::setupAdaptive(){
arr = ((mJackTrip->getPeerEstimatedPeriod()*mJackTrip->getRatioDel())/mJackTrip->getEstimatedPeriod()); arr = ((mJackTrip->getPeerEstimatedPeriod()*mJackTrip->getRatioDel())/mJackTrip->getEstimatedPeriod());
mJackTrip->getUniformResampler()->set_rratio(arr); mJackTrip->getAdaptiveResampler()->set_rratio(arr);
return 0; return 0;
} }
void RingBuffer::info(){ void RingBuffer::info(){
arr = (mJackTrip->getPeerEstimatedPeriod()*mJackTrip->getRatioDel())/mJackTrip->getEstimatedPeriod(); 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() ...@@ -346,50 +396,6 @@ void RingBuffer::overflowReset()
//******************************************************************************* //*******************************************************************************
void RingBuffer::debugDump() const 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 @@ ...@@ -41,9 +41,6 @@
#include <QWaitCondition> #include <QWaitCondition>
#include <QMutex> #include <QMutex>
#include <QMutexLocker> #include <QMutexLocker>
#include <QObject>
#include <QString>
#include <QVector>
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <jack/jack.h> #include <jack/jack.h>
...@@ -62,9 +59,8 @@ class JackTrip; ...@@ -62,9 +59,8 @@ class JackTrip;
* each of which is of size \b SlotSize bytes (8-bits). Slots can be read and * each of which is of size \b SlotSize bytes (8-bits). Slots can be read and
* written asynchronously/synchronously by multiple threads. * written asynchronously/synchronously by multiple threads.
*/ */
class RingBuffer : public QObject class RingBuffer
{ {
Q_OBJECT;
public: public:
...@@ -160,8 +156,6 @@ protected: ...@@ -160,8 +156,6 @@ protected:
JackTrip* mJackTrip; JackTrip* mJackTrip;
signals:
void signalError(const char* error_message);
private: private:
...@@ -198,15 +192,6 @@ private: ...@@ -198,15 +192,6 @@ private:
double deltaXrun; ///< time between the 2 last xrun double deltaXrun; ///< time between the 2 last xrun
float arr; float arr;
int countC; 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; 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