void SoundInput::intervalNotify() { m_callbackData.monitoring = m_monitoring; // update monitoring // status qint64 ms = QDateTime::currentMSecsSinceEpoch(); ms=ms % 86400000; int nsec = ms/1000; // Time according to this computer int ntr = nsec % m_TRperiod; int k=m_callbackData.kin; // get a copy of kin to mitigate the // potential race condition with the // callback handler when a buffer // reset is requested below // Reset buffer pointer and symbol number at start of minute if(ntr < m_ntr0 or !m_monitoring or m_nsps!=m_nsps0) { m_nstep0=0; m_nsps0=m_nsps; m_callbackData.bzero = true; // request callback to reset buffer pointer } if(m_monitoring) { int kstep=m_nsps/2; // m_step=k/kstep; m_step=(k-1)/kstep; if(m_step != m_nstep0) { emit readyForFFT(k-1); //Signal to compute new FFTs m_nstep0=m_step; } } m_ntr0=ntr; }
void SoundInput::intervalNotify() { m_callbackData.monitoring=m_monitoring; qint64 ms = QDateTime::currentMSecsSinceEpoch(); ms=ms % 86400000; int nsec = ms/1000; // Time according to this computer int ntr = nsec % m_TRperiod; static int k=0; // qDebug() << "a" << ms << nsec; // Reset buffer pointer and symbol number at start of minute if(ntr < m_ntr0 or !m_monitoring or m_nsps!=m_nsps0) { m_nstep0=0; m_nsps0=m_nsps; m_callbackData.bzero=true; k=0; } // int k=m_callbackData.kin; // How many new samples are available? const qint32 bytesReady = audioInput->bytesReady(); // qDebug() << "b" << bytesReady; Q_ASSERT(bytesReady >= 0); Q_ASSERT(bytesReady % 2 == 0); if (bytesReady == 0) { return; } qint32 bytesRead; bytesRead = stream->read((char*)&jt9com_.d2[k], bytesReady); // Get the new samples k += bytesRead/2; // qDebug() << "c" << bytesReady << bytesRead; Q_ASSERT(bytesRead <= bytesReady); if (bytesRead < 0) { emit error(tr("audio stream QIODevice::read returned -1.")); return; } Q_ASSERT(bytesRead % 2 == 0); if(m_monitoring) { int kstep=m_nsps/2; m_step=(k-1)/kstep; if(m_step != m_nstep0) { if(m_dataSinkBusy) { m_nBusy++; } else { emit readyForFFT(k-1); //Signal to compute new FFTs } m_nstep0=m_step; } } m_ntr0=ntr; }
void SoundInThread::run() //SoundInThread::run() { quitExecution = false; //---------------------------------------------------- Soundcard Setup PaError paerr; PaStreamParameters inParam; PaStream *inStream; paUserData udata; udata.kin=0; //Buffer pointer udata.bzero=false; //Flag to request reset of kin inParam.device=m_nDevIn; //### Input Device Number ### inParam.channelCount=1; //Number of analog channels inParam.sampleFormat=paInt16; //Get i*2 from Portaudio inParam.suggestedLatency=0.05; inParam.hostApiSpecificStreamInfo=NULL; paerr=Pa_IsFormatSupported(&inParam,NULL,48000.0); if(paerr<0) { emit error("PortAudio says requested soundcard format not supported."); // return; } paerr=Pa_OpenStream(&inStream, //Input stream &inParam, //Input parameters NULL, //No output parameters 48000.0, //Sample rate FRAMES_PER_BUFFER, //Frames per buffer // paClipOff+paDitherOff, //No clipping or dithering paClipOff, //No clipping a2dCallback, //Input callbeck routine &udata); //userdata paerr=Pa_StartStream(inStream); if(paerr<0) { emit error("Failed to start audio input stream."); return; } bool qe = quitExecution; int n30z=99; int k=0; int nsec; int n30; int nBusy=0; int nstep0=0; //---------------------------------------------- Soundcard input loop while (!qe) { qe = quitExecution; if (qe) break; qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000; nsec = ms/1000; // Time according to this computer n30 = nsec % 30; // Reset buffer pointer and symbol number at start of minute if(n30 < n30z or !m_monitoring) { nstep0=0; udata.bzero=true; } k=udata.kin; if(m_monitoring) { m_step=k/2048; if(m_step != nstep0) { if(m_dataSinkBusy) { nBusy++; } else { // m_dataSinkBusy=true; emit readyForFFT(k); //Signal to compute new FFTs } nstep0=m_step; } } msleep(10); n30z=n30; } Pa_StopStream(inStream); Pa_CloseStream(inStream); }