some code style changes, added first implementation of mixer in client window

This commit is contained in:
Volker Fischer 2006-12-07 18:57:26 +00:00
parent 63adf15507
commit 7f4bea94eb
5 changed files with 531 additions and 490 deletions

View file

@ -33,7 +33,8 @@ CClient::CClient () : bRun ( false ), Socket ( &Channel ),
iNetwBufSizeFactIn ( DEF_NET_BLOCK_SIZE_FACTOR ) iNetwBufSizeFactIn ( DEF_NET_BLOCK_SIZE_FACTOR )
{ {
// connection for protocol // connection for protocol
QObject::connect ( &Channel, SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), QObject::connect ( &Channel,
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) ); this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
QObject::connect ( &Channel, SIGNAL ( ReqJittBufSize() ), QObject::connect ( &Channel, SIGNAL ( ReqJittBufSize() ),
@ -42,7 +43,8 @@ CClient::CClient () : bRun ( false ), Socket ( &Channel ),
QObject::connect ( &Channel, SIGNAL ( ProtocolStatus ( bool ) ), QObject::connect ( &Channel, SIGNAL ( ProtocolStatus ( bool ) ),
this, SLOT ( OnProtocolStatus ( bool ) ) ); this, SLOT ( OnProtocolStatus ( bool ) ) );
QObject::connect ( &Channel, SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ), QObject::connect ( &Channel,
SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ),
SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ) ); SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ) );
} }
@ -102,37 +104,37 @@ void CClient::OnProtocolStatus ( bool bOk )
void CClient::Init() void CClient::Init()
{ {
/* set block sizes (in samples) */ // set block sizes (in samples)
iBlockSizeSam = MIN_BLOCK_SIZE_SAMPLES; iBlockSizeSam = MIN_BLOCK_SIZE_SAMPLES;
iSndCrdBlockSizeSam = MIN_SND_CRD_BLOCK_SIZE_SAMPLES; iSndCrdBlockSizeSam = MIN_SND_CRD_BLOCK_SIZE_SAMPLES;
vecsAudioSndCrd.Init(iSndCrdBlockSizeSam * 2); /* stereo */ vecsAudioSndCrd.Init ( iSndCrdBlockSizeSam * 2 ); // stereo
vecdAudioSndCrdL.Init ( iSndCrdBlockSizeSam ); vecdAudioSndCrdL.Init ( iSndCrdBlockSizeSam );
vecdAudioSndCrdR.Init ( iSndCrdBlockSizeSam ); vecdAudioSndCrdR.Init ( iSndCrdBlockSizeSam );
vecdAudioL.Init ( iBlockSizeSam ); vecdAudioL.Init ( iBlockSizeSam );
vecdAudioR.Init ( iBlockSizeSam ); vecdAudioR.Init ( iBlockSizeSam );
Sound.InitRecording(iSndCrdBlockSizeSam * 2 /* stereo */); Sound.InitRecording ( iSndCrdBlockSizeSam * 2 ); // stereo
Sound.InitPlayback(iSndCrdBlockSizeSam * 2 /* stereo */); Sound.InitPlayback ( iSndCrdBlockSizeSam * 2 ); // stereo
/* resample objects are always initialized with the input block size */ // resample objects are always initialized with the input block size
/* record */ // record
ResampleObjDownL.Init ( iSndCrdBlockSizeSam, SND_CRD_SAMPLE_RATE, SAMPLE_RATE ); ResampleObjDownL.Init ( iSndCrdBlockSizeSam, SND_CRD_SAMPLE_RATE, SAMPLE_RATE );
ResampleObjDownR.Init ( iSndCrdBlockSizeSam, SND_CRD_SAMPLE_RATE, SAMPLE_RATE ); ResampleObjDownR.Init ( iSndCrdBlockSizeSam, SND_CRD_SAMPLE_RATE, SAMPLE_RATE );
/* playback */ // playback
ResampleObjUpL.Init ( iBlockSizeSam, SAMPLE_RATE, SND_CRD_SAMPLE_RATE ); ResampleObjUpL.Init ( iBlockSizeSam, SAMPLE_RATE, SND_CRD_SAMPLE_RATE );
ResampleObjUpR.Init ( iBlockSizeSam, SAMPLE_RATE, SND_CRD_SAMPLE_RATE ); ResampleObjUpR.Init ( iBlockSizeSam, SAMPLE_RATE, SND_CRD_SAMPLE_RATE );
/* init network buffers */ // init network buffers
vecsNetwork.Init ( iBlockSizeSam ); vecsNetwork.Init ( iBlockSizeSam );
vecdNetwData.Init ( iBlockSizeSam ); vecdNetwData.Init ( iBlockSizeSam );
/* init moving average buffer for response time evaluation */ // init moving average buffer for response time evaluation
RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE ); RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE );
/* init time for response time evaluation */ // init time for response time evaluation
TimeLastBlock = QTime::currentTime(); TimeLastBlock = QTime::currentTime();
AudioReverb.Clear(); AudioReverb.Clear();
@ -142,31 +144,31 @@ void CClient::run()
{ {
int i, iInCnt; int i, iInCnt;
/* Set thread priority (The working thread should have a higher // Set thread priority (The working thread should have a higher
priority than the GUI) */ // priority than the GUI)
#ifdef _WIN32 #ifdef _WIN32
SetThreadPriority ( GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL ); SetThreadPriority ( GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL );
#else #else
/* set the process to realtime privs, taken from // set the process to realtime privs, taken from
"http://www.gardena.net/benno/linux/audio" but does not seem to work, // "http://www.gardena.net/benno/linux/audio" but does not seem to work,
maybe a problem with user rights */ // maybe a problem with user rights
struct sched_param schp; struct sched_param schp;
memset ( &schp, 0, sizeof ( schp ) ); memset ( &schp, 0, sizeof ( schp ) );
schp.sched_priority = sched_get_priority_max ( SCHED_FIFO ); schp.sched_priority = sched_get_priority_max ( SCHED_FIFO );
sched_setscheduler ( 0, SCHED_FIFO, &schp ); sched_setscheduler ( 0, SCHED_FIFO, &schp );
#endif #endif
/* init object */ // init object
Init(); Init();
/* runtime phase --------------------------------------------------------- */ // runtime phase ------------------------------------------------------------
bRun = true; bRun = true;
/* main loop of working thread */ // main loop of working thread
while ( bRun ) while ( bRun )
{ {
/* get audio from sound card (blocking function) */ // get audio from sound card (blocking function)
if ( Sound.Read ( vecsAudioSndCrd ) ) if ( Sound.Read ( vecsAudioSndCrd ) )
{ {
PostWinMessage ( MS_SOUND_IN, MUL_COL_LED_RED ); PostWinMessage ( MS_SOUND_IN, MUL_COL_LED_RED );
@ -176,7 +178,7 @@ void CClient::run()
PostWinMessage ( MS_SOUND_IN, MUL_COL_LED_GREEN ); PostWinMessage ( MS_SOUND_IN, MUL_COL_LED_GREEN );
} }
/* copy data from one stereo buffer in two separate buffers */ // copy data from one stereo buffer in two separate buffers
iInCnt = 0; iInCnt = 0;
for ( i = 0; i < iSndCrdBlockSizeSam; i++ ) for ( i = 0; i < iSndCrdBlockSizeSam; i++ )
{ {
@ -184,25 +186,25 @@ void CClient::run()
vecdAudioSndCrdR[i] = (double) vecsAudioSndCrd[iInCnt++]; vecdAudioSndCrdR[i] = (double) vecsAudioSndCrd[iInCnt++];
} }
/* resample data for each channel seaparately */ // resample data for each channel seaparately
ResampleObjDownL.Resample ( vecdAudioSndCrdL, vecdAudioL ); ResampleObjDownL.Resample ( vecdAudioSndCrdL, vecdAudioL );
ResampleObjDownR.Resample ( vecdAudioSndCrdR, vecdAudioR ); ResampleObjDownR.Resample ( vecdAudioSndCrdR, vecdAudioR );
/* update signal level meters */ // update signal level meters
SignalLevelMeterL.Update ( vecdAudioL ); SignalLevelMeterL.Update ( vecdAudioL );
SignalLevelMeterR.Update ( vecdAudioR ); SignalLevelMeterR.Update ( vecdAudioR );
/* add reverberation effect if activated */ // add reverberation effect if activated
if ( iReverbLevel != 0 ) if ( iReverbLevel != 0 )
{ {
/* first attenuation amplification factor */ // first attenuation amplification factor
const double dRevLev = (double) iReverbLevel / AUD_REVERB_MAX / 2; const double dRevLev = (double) iReverbLevel / AUD_REVERB_MAX / 2;
if ( bReverbOnLeftChan ) if ( bReverbOnLeftChan )
{ {
for (i = 0; i < iBlockSizeSam; i++) for (i = 0; i < iBlockSizeSam; i++)
{ {
/* left channel */ // left channel
vecdAudioL[i] += vecdAudioL[i] +=
dRevLev * AudioReverb.ProcessSample ( vecdAudioL[i] ); dRevLev * AudioReverb.ProcessSample ( vecdAudioL[i] );
} }
@ -211,35 +213,40 @@ void CClient::run()
{ {
for ( i = 0; i < iBlockSizeSam; i++ ) for ( i = 0; i < iBlockSizeSam; i++ )
{ {
/* right channel */ // right channel
vecdAudioR[i] += vecdAudioR[i] +=
dRevLev * AudioReverb.ProcessSample ( vecdAudioR[i] ); dRevLev * AudioReverb.ProcessSample ( vecdAudioR[i] );
} }
} }
} }
/* mix both signals depending on the fading setting */ // mix both signals depending on the fading setting
const int iMiddleOfFader = AUD_FADER_IN_MAX / 2; const int iMiddleOfFader = AUD_FADER_IN_MAX / 2;
const double dAttFact = const double dAttFact =
(double) ( iMiddleOfFader - abs ( iMiddleOfFader - iAudioInFader ) ) / (double) ( iMiddleOfFader - abs ( iMiddleOfFader - iAudioInFader ) ) /
iMiddleOfFader; iMiddleOfFader;
for ( i = 0; i < iBlockSizeSam; i++ ) for ( i = 0; i < iBlockSizeSam; i++ )
{ {
double dMixedSignal; double dMixedSignal;
if ( iAudioInFader > iMiddleOfFader ) if ( iAudioInFader > iMiddleOfFader )
{
dMixedSignal = vecdAudioL[i] + dAttFact * vecdAudioR[i]; dMixedSignal = vecdAudioL[i] + dAttFact * vecdAudioR[i];
}
else else
{
dMixedSignal = vecdAudioR[i] + dAttFact * vecdAudioL[i]; dMixedSignal = vecdAudioR[i] + dAttFact * vecdAudioL[i];
}
vecsNetwork[i] = Double2Short ( dMixedSignal ); vecsNetwork[i] = Double2Short ( dMixedSignal );
} }
/* send it through the network */ // send it through the network
Socket.SendPacket ( Channel.PrepSendPacket ( vecsNetwork ), Socket.SendPacket ( Channel.PrepSendPacket ( vecsNetwork ),
Channel.GetAddress () ); Channel.GetAddress () );
/* receive a new block */ // receive a new block
if ( Channel.GetData ( vecdNetwData ) ) if ( Channel.GetData ( vecdNetwData ) )
{ {
PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_GREEN ); PostWinMessage ( MS_JIT_BUF_GET, MUL_COL_LED_GREEN );
@ -311,10 +318,10 @@ fflush(pFileDelay);
*/ */
/* check if channel is connected */ // check if channel is connected
if ( Channel.IsConnected() ) if ( Channel.IsConnected() )
{ {
/* write mono input signal in both sound-card channels */ // write mono input signal in both sound-card channels
for ( i = 0; i < iBlockSizeSam; i++ ) for ( i = 0; i < iBlockSizeSam; i++ )
{ {
vecdAudioL[i] = vecdAudioR[i] = vecdNetwData[i]; vecdAudioL[i] = vecdAudioR[i] = vecdNetwData[i];
@ -322,18 +329,18 @@ fflush(pFileDelay);
} }
else else
{ {
/* if not connected, clear data */ // if not connected, clear data
for ( i = 0; i < iBlockSizeSam; i++ ) for ( i = 0; i < iBlockSizeSam; i++ )
{ {
vecdAudioL[i] = vecdAudioR[i] = 0.0; vecdAudioL[i] = vecdAudioR[i] = 0.0;
} }
} }
/* resample data for each channel separately */ // resample data for each channel separately
ResampleObjUpL.Resample ( vecdAudioL, vecdAudioSndCrdL ); ResampleObjUpL.Resample ( vecdAudioL, vecdAudioSndCrdL );
ResampleObjUpR.Resample ( vecdAudioR, vecdAudioSndCrdR ); ResampleObjUpR.Resample ( vecdAudioR, vecdAudioSndCrdR );
/* copy data from one stereo buffer in two separate buffers */ // copy data from one stereo buffer in two separate buffers
iInCnt = 0; iInCnt = 0;
for ( i = 0; i < iSndCrdBlockSizeSam; i++ ) for ( i = 0; i < iSndCrdBlockSizeSam; i++ )
{ {
@ -341,7 +348,7 @@ fflush(pFileDelay);
vecsAudioSndCrd[iInCnt++] = Double2Short ( vecdAudioSndCrdR[i] ); vecsAudioSndCrd[iInCnt++] = Double2Short ( vecdAudioSndCrdR[i] );
} }
/* play the new block */ // play the new block
if ( Sound.Write ( vecsAudioSndCrd ) ) if ( Sound.Write ( vecsAudioSndCrd ) )
{ {
PostWinMessage ( MS_SOUND_OUT, MUL_COL_LED_RED ); PostWinMessage ( MS_SOUND_OUT, MUL_COL_LED_RED );
@ -352,12 +359,12 @@ fflush(pFileDelay);
} }
/* update response time measurement --------------------------------- */ // update response time measurement ------------------------------------
/* add time difference */ // add time difference
const QTime CurTime = QTime::currentTime(); const QTime CurTime = QTime::currentTime();
/* we want to calculate the standard deviation (we assume that the mean // we want to calculate the standard deviation (we assume that the mean
is correct at the block period time) */ // is correct at the block period time)
const double dCurAddVal = const double dCurAddVal =
( (double) TimeLastBlock.msecsTo ( CurTime ) - MIN_BLOCK_DURATION_MS ); ( (double) TimeLastBlock.msecsTo ( CurTime ) - MIN_BLOCK_DURATION_MS );
@ -368,13 +375,13 @@ fprintf(pFileTest, "%e\n", dCurAddVal);
fflush(pFileTest); fflush(pFileTest);
*/ */
RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); /* add squared value */ RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); // add squared value
/* store old time value */ // store old time value
TimeLastBlock = CurTime; TimeLastBlock = CurTime;
} }
/* reset current signal level and LEDs */ // reset current signal level and LEDs
SignalLevelMeterL.Reset(); SignalLevelMeterL.Reset();
SignalLevelMeterR.Reset(); SignalLevelMeterR.Reset();
PostWinMessage ( MS_RESET_ALL, 0 ); PostWinMessage ( MS_RESET_ALL, 0 );
@ -382,9 +389,9 @@ fflush(pFileTest);
bool CClient::Stop() bool CClient::Stop()
{ {
/* set flag so that thread can leave the main loop */ // set flag so that thread can leave the main loop
bRun = false; bRun = false;
/* give thread some time to terminate, return status */ // give thread some time to terminate, return status
return wait ( 5000 ); return wait ( 5000 );
} }

View file

@ -114,9 +114,13 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
/* set radio buttons --- */ /* set radio buttons --- */
// reverb channel // reverb channel
if (pClient->IsReverbOnLeftChan()) if (pClient->IsReverbOnLeftChan())
{
RadioButtonRevSelL->setChecked(true); RadioButtonRevSelL->setChecked(true);
}
else else
{
RadioButtonRevSelR->setChecked(true); RadioButtonRevSelR->setChecked(true);
}
/* Settings menu ------------------------------------------------------- */ /* Settings menu ------------------------------------------------------- */
@ -139,6 +143,18 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
CLlconClientDlgBaseLayout->setMenuBar ( pMenu ); CLlconClientDlgBaseLayout->setMenuBar ( pMenu );
// mixer board -------------------------------------------------------------
// create all mixer controls and make them invisible
vecpChanFader.Init ( MAX_NUM_CHANNELS );
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
vecpChanFader[i] = new CLlconClientDlg::CChannelFader ( FrameAudioFaders,
FrameAudioFadersLayout, "test" );
vecpChanFader[i]->Hide();
}
/* connections ---------------------------------------------------------- */ /* connections ---------------------------------------------------------- */
// push-buttons // push-buttons
QObject::connect(PushButtonConnect, SIGNAL(clicked()), QObject::connect(PushButtonConnect, SIGNAL(clicked()),
@ -222,6 +238,19 @@ void CLlconClientDlg::OnConnectDisconBut ()
/* immediately update status bar */ /* immediately update status bar */
OnTimerStatus (); OnTimerStatus ();
// TEST
/*
// make old controls invisible
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
vecpChanFader[i]->Hide();
}
*/
} }
else else
{ {
@ -294,32 +323,28 @@ void CLlconClientDlg::OnConClientListMesReceived ( CVector<CChannelShortInfo> ve
int i; int i;
//FrameAudioFadersLayout->addWidget(new QLabel ( "test", FrameAudioFaders ));
// TODO // TODO
// remove old controls // make old controls invisible
for ( i = 0; i < vecpChanFader.Size(); i++ ) for ( i = 0; i < MAX_NUM_CHANNELS; i++ )
{ {
delete vecpChanFader[i]; vecpChanFader[i]->Hide();
} }
// TEST add current faders // TEST add current faders
vecpChanFader.Init ( vecChanInfo.Size() );
for ( i = 0; i < vecChanInfo.Size(); i++ ) for ( i = 0; i < vecChanInfo.Size(); i++ )
{ {
QHostAddress addrTest ( vecChanInfo[i].veciIpAddr ); QHostAddress addrTest ( vecChanInfo[i].veciIpAddr );
vecpChanFader[i] = new CLlconClientDlg::CChannelFader ( FrameAudioFaders, vecpChanFader[i]->Show();
FrameAudioFadersLayout, addrTest.toString() ); vecpChanFader[i]->SetText ( addrTest.toString().latin1() );
// vecpChanFader[i] = new CLlconClientDlg::CChannelFader ( FrameAudioFaders,
// FrameAudioFadersLayout, addrTest.toString() );
} }
//FrameAudioFadersLayout->addWidget(new QLabel ( "test", FrameAudioFaders ));
} }
@ -399,3 +424,8 @@ pFader->setEnabled ( FALSE );
pParentLayout->insertLayout ( 0, pMainGrid ); pParentLayout->insertLayout ( 0, pMainGrid );
} }
void CLlconClientDlg::CChannelFader::SetText ( const std::string sText )
{
pLabel->setText ( sText.c_str() );
}

View file

@ -85,6 +85,10 @@ protected:
// TODO get rid of pMainGrid // TODO get rid of pMainGrid
} }
void SetText ( const std::string sText );
void Show() { pLabel->show(); pFader->show(); }
void Hide() { pLabel->hide(); pFader->hide(); }
protected: protected:
QGridLayout* pMainGrid; QGridLayout* pMainGrid;
QSlider* pFader; QSlider* pFader;