Пример #1
0
//int SoundFile::readN(SoundStream *s,int n)
int SoundFile::readN(int n)
{
    myassert(n >= 0 && n <= bufferSize());
    int ret = blockingRead(stream, tempWindowBuffer, n);
    if(equalLoudness()) ret = blockingRead(filteredStream, tempWindowBufferFiltered, n);
    toChannelBuffers(n);
    return ret;
}
Пример #2
0
HRESULT DirectShowIOReader::SyncRead(LONGLONG llPosition, LONG lLength, BYTE *pBuffer)
{
    if (!pBuffer) {
        return E_POINTER;
    } else {
        if (thread() == QThread::currentThread()) {
            qint64 bytesRead;

            return blockingRead(llPosition, lLength, pBuffer, &bytesRead);
        } else {
            QMutexLocker locker(&m_mutex);

            m_synchronousPosition = llPosition;
            m_synchronousLength = lLength;
            m_synchronousBuffer = pBuffer;

            m_loop->postEvent(this, new QEvent(QEvent::User));

            m_wait.wait(&m_mutex);

            m_synchronousBuffer = 0;

            return m_synchronousResult;
        }
    }
}
Пример #3
0
//int SoundFile::readChunk(int n, SoundStream *s)
int SoundFile::readChunk(int n)
{
    int c;
    //if(!s) s = stream;

    int ret = blockingRead(stream, tempWindowBuffer, n);
    if(equalLoudness()) {
        applyEqualLoudnessFilter(n);
        ret = blockingWrite(filteredStream, tempWindowBufferFiltered, ret);
    }
    if(ret < n) return ret;

    FilterState filterState;

    lock();

    //nextChunk();
    for(c=0; c<numChannels(); c++) {
        channels(c)->shift_left(n);
        //channels(c)->highPassFilter->getState(&filterState);
        toChannelBuffer(c, n);
        channels(c)->processNewChunk(&filterState);
    }
    //incrementChunkNum();
    setCurrentChunk(currentStreamChunk());
    unlock();
    return ret;
}
Пример #4
0
//void SoundFile::initRecordingChunk()
void SoundFile::recordChunk(int n)
{
    //int n = offset();
    int c;
    int ret = blockingRead(gdata->audio_stream, tempWindowBuffer, n);
    if(ret < n) {
        fprintf(stderr, "Data lost in reading from audio device\n");
    }

    /*  if(equalLoudness()) applyEqualLoudnessFilter(n);

      FilterState filterState;

      lock();
      for(c=0; c<numChannels(); c++) {
        channels(c)->shift_left(n);
        //std::copy(tempWindowBuffer[c], tempWindowBuffer[c]+n, channels(c)->end() - n);
        //channels(c)->highPassFilter->getState(&filterState);
        toChannelBuffer(c, n);
        //if(channels(c) == gdata->getActiveChannel())
        channels(c)->processNewChunk(&filterState);
      }
      unlock();

      ret = blockingWrite(stream, tempWindowBuffer, n);
      if(ret < n) fprintf(stderr, "Error writing to disk\n");
      if(equalLoudness()) ret = blockingWrite(filteredStream, tempWindowBufferFiltered, n);
      if(ret < n) fprintf(stderr, "Error writing to disk\n");

      setCurrentChunk(currentStreamChunk());
    */
    finishRecordChunk(n);
}
Пример #5
0
bool SoundFile::setupPlayChunk() {
    int c;
    int n = framesPerChunk();
    int ret = blockingRead(stream, tempWindowBuffer, n);
    if(equalLoudness()) ret = blockingRead(filteredStream, tempWindowBufferFiltered, n);
    if(ret < n) return false;

    lock();
    for(c=0; c<numChannels(); c++) {
        channels(c)->shift_left(n);
        toChannelBuffer(c, n);
        if(gdata->doingActive() && channels(c) == gdata->getActiveChannel()) {
            channels(c)->processChunk(currentChunk()+1);
        }
    }
    setCurrentChunk(currentStreamChunk());
    unlock();
    return true;
}
Пример #6
0
HRESULT DirectShowIOReader::SyncReadAligned(IMediaSample *pSample)
{
    if (!pSample) {
        return E_POINTER;
    } else {
        REFERENCE_TIME startTime = 0;
        REFERENCE_TIME endTime = 0;
        BYTE *buffer;

        if (pSample->GetTime(&startTime, &endTime) != S_OK
                || pSample->GetPointer(&buffer) != S_OK) {
            return VFW_E_SAMPLE_TIME_NOT_SET;
        } else {
            LONGLONG position = startTime / 10000000;
            LONG length = (endTime - startTime) / 10000000;

            QMutexLocker locker(&m_mutex);

            if (thread() == QThread::currentThread()) {
                qint64 bytesRead = 0;

                HRESULT hr = blockingRead(position, length, buffer, &bytesRead);

                if (SUCCEEDED(hr))
                    pSample->SetActualDataLength(bytesRead);
   
                return hr;
            } else {
                m_synchronousPosition = position;
                m_synchronousLength = length;
                m_synchronousBuffer = buffer;

                m_loop->postEvent(this, new QEvent(QEvent::User));

                m_wait.wait(&m_mutex);

                m_synchronousBuffer = 0;

                if (SUCCEEDED(m_synchronousResult))
                    pSample->SetActualDataLength(m_synchronousBytesRead);

                return m_synchronousResult;
            }
        }
    }
}
Пример #7
0
void TCPPipe::initializePipe(TCPPipe::Endianness sEndianness)
	{
	/* Set socket options: */
	TCPSocket::setNoDelay(true);
	
	if(sEndianness==LittleEndian)
		{
		#if __BYTE_ORDER==__BIG_ENDIAN
		readMustSwapEndianness=writeMustSwapEndianness=true;
		#endif
		}
	else if(sEndianness==BigEndian)
		{
		#if __BYTE_ORDER==__LITTLE_ENDIAN
		readMustSwapEndianness=writeMustSwapEndianness=true;
		#endif
		}
	else if(sEndianness==Automatic)
		{
		/* Exchange a magic value to test for endianness on the other end: */
		unsigned int magic=0x12345678U;
		blockingWrite(&magic,sizeof(unsigned int));
		blockingRead(&magic,sizeof(unsigned int));
		if(magic==0x78563412U)
			readMustSwapEndianness=true;
		else if(magic!=0x12345678U)
			Misc::throwStdErr("Comm::TCPPipe: Unable to establish connection with host %s on port %d",getPeerHostname().c_str(),getPeerPortId());
		}
	
	/* Allocate the read and write buffers: */
	int maxSegSize=-1;
	socklen_t maxSegLen=sizeof(int);
	if(getsockopt(getFd(),IPPROTO_TCP,TCP_MAXSEG,&maxSegSize,&maxSegLen)<0)
		Misc::throwStdErr("Comm::TCPPipe: Unable to determine maximum TCP segment size");
	bufferSize=size_t(maxSegSize);
	readBuffer=new char[bufferSize];
	rbPos=readBuffer;
	readSize=0;
	writeBuffer=new char[bufferSize];
	wbPos=writeBuffer;
	writeSize=bufferSize;
	}