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

View file

@ -114,9 +114,13 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
/* set radio buttons --- */
// reverb channel
if (pClient->IsReverbOnLeftChan())
{
RadioButtonRevSelL->setChecked(true);
}
else
{
RadioButtonRevSelR->setChecked(true);
}
/* Settings menu ------------------------------------------------------- */
@ -139,6 +143,18 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
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 ---------------------------------------------------------- */
// push-buttons
QObject::connect(PushButtonConnect, SIGNAL(clicked()),
@ -222,6 +238,19 @@ void CLlconClientDlg::OnConnectDisconBut ()
/* immediately update status bar */
OnTimerStatus ();
// TEST
/*
// make old controls invisible
for ( int i = 0; i < MAX_NUM_CHANNELS; i++ )
{
vecpChanFader[i]->Hide();
}
*/
}
else
{
@ -294,32 +323,28 @@ void CLlconClientDlg::OnConClientListMesReceived ( CVector<CChannelShortInfo> ve
int i;
//FrameAudioFadersLayout->addWidget(new QLabel ( "test", FrameAudioFaders ));
// TODO
// remove old controls
for ( i = 0; i < vecpChanFader.Size(); i++ )
// make old controls invisible
for ( i = 0; i < MAX_NUM_CHANNELS; i++ )
{
delete vecpChanFader[i];
vecpChanFader[i]->Hide();
}
// TEST add current faders
vecpChanFader.Init ( vecChanInfo.Size() );
for ( i = 0; i < vecChanInfo.Size(); i++ )
{
QHostAddress addrTest ( vecChanInfo[i].veciIpAddr );
vecpChanFader[i] = new CLlconClientDlg::CChannelFader ( FrameAudioFaders,
FrameAudioFadersLayout, addrTest.toString() );
vecpChanFader[i]->Show();
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 );
}
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
}
void SetText ( const std::string sText );
void Show() { pLabel->show(); pFader->show(); }
void Hide() { pLabel->hide(); pFader->hide(); }
protected:
QGridLayout* pMainGrid;
QSlider* pFader;