void Serial::Go() { ResetSamples(); _lastChunkTime = _lastChunkSamples = 0; _unpacked = 0; DWORD chunkStartTime = ::GetTickCount(); int chunkSamples = 0; const int sampleSize = sizeof(Sample::value_t); while (!_abort) { DWORD bytesRead = 0; ReadFile(_file, _buffer, BufferSize, &bytesRead, nullptr); if (bytesRead) { chunkSamples += ReadSamples(bytesRead); DWORD now = ::GetTickCount(); if (now > chunkStartTime + 250) { std::lock_guard<std::mutex> lock(_chunkMutex); _lastChunkSamples = chunkSamples; _lastChunkTime = now - chunkStartTime; chunkSamples = 0; chunkStartTime = now; } } } }
vector_sample* ImageManager::GetYesSamples() { if (samplesYes != nullptr) { delete samplesYes; } samplesYes = new vector_sample(); ReadSamples(Parameter::pathToYes, samplesYes); return samplesYes; }
vector_sample* ImageManager::GetMaybeSamples() { if (samplesMaybe != nullptr) { delete samplesMaybe; } samplesMaybe = new vector_sample(); ReadSamples(Parameter::pathToMaybe, samplesMaybe); return samplesMaybe; };
vector_sample* ImageManager::GetNoSamples() { if (samplesNo != nullptr) { delete samplesNo; } samplesNo = new vector_sample(); ReadSamples(Parameter::pathToNo, samplesNo); return samplesNo; };
static void ReadWAVE( char *filename, Wave *wave ) { int fd = open( filename, O_RDWR ); RIFFHeader riff_header = ReadRIFFHeader( fd ); FmtHeader fmt_header = ReadFmtHeader( fd ); read( fd, &wave->Subchunk2ID, sizeof(uint32_t)); read( fd, &wave->Subchunk2Size, sizeof(uint32_t)); fix_endian( &riff_header, &fmt_header, wave ); ReadSamples( fd, wave ); close( fd ); }
// load all data specified in control file ------------------------------------ // void LoadData( char *cfn, int dispinfo ) { ASSERT( cfn != NULL ); ctrl_file_name = cfn; display_info = FALSE; //dispinfo; //NOTE: // we currently disable loader message output // at all times, since most data is now loaded // via console scripts and these messages would // just be irritating. ParseCtrlFile( PARSE_EVERYTHING ); ReadPalettes(); ReadTextures(); ReadSamples(); LoadObjectData(); ReadBitmapsAndCharsets(); }
size_t MultiFormatReader::ReadSamples(void* buffer, size_t len, MultiFormatReader::FormatT format, MachineEndianness::EndiannessT end) { return ReadSamples(buffer, len, 1, format, end); }
void nuiAudioTrack::Process(uint32 SampleFrames, std::vector<float*>& rOutputBuffer) { float *rbuf; uint32 nbRead=0; uint32 nbRead2=0; uint32 totalRead=0; float l_volume = mVolume; uint32 ch, i; // // we don't want to buffer the audio // if (!mBufferingEnabled) { // read directly from the samples source to the AudioFifo buffer. Don't use ringbufer ReadSamples (SampleFrames, rOutputBuffer); // set the volume for (ch = 0; ch < rOutputBuffer.size(); ch++) { for (i=0; i < SampleFrames; i++) { rOutputBuffer[ch][i] = rOutputBuffer[ch][i] * l_volume; } } // event callback ProcessedSamples(SampleFrames, 0, 0); return; } // // we do want to stream the audio // //******************************************************* // // first pass reading from ringBuffer // nbRead = mpRingBuf->GetReadableToEnd(); // read what you need. maybe less, but not more! if (nbRead > SampleFrames) nbRead = SampleFrames; for (ch = 0; ch < mNbChannels; ch++) { rbuf = (float*)mpRingBuf->GetReadPointer(ch); for (i=0; i < nbRead; i++) { rOutputBuffer[ch][i] = rbuf[i] * l_volume; } } mpRingBuf->AdvanceReadIndex (nbRead); // NGL_LOG(_T("nuiAudioTrack"), NGL_LOG_DEBUG, _T("\n\t\t\t\tRead %d\n"), nbRead); //******************************************************* // // second pass reading from ringBuffer // // do you need some more ? if (nbRead >= SampleFrames) { totalRead += nbRead; // NGL_LOG(_T("nuiAudioTrack"), NGL_LOG_DEBUG, _T("\n\t\t\t\tReadTh : %d samples read"), totalRead); // event callback ProcessedSamples(nbRead, mBufSize, mpRingBuf->GetReadable()); return; } // yes, I do nbRead2 = mpRingBuf->GetReadableToEnd(); if (nbRead2 > (SampleFrames - nbRead)) nbRead2 = (SampleFrames - nbRead); for (ch = 0; ch < mNbChannels; ch++) { rbuf = (float*)mpRingBuf->GetReadPointer(ch); for (i=0; i < nbRead; i++) { rOutputBuffer[ch][i] = rbuf[i] * l_volume; } } mpRingBuf->AdvanceReadIndex(nbRead2); // NGL_LOG(_T("nuiAudioTrack"), NGL_LOG_DEBUG, _T("\n\t\t\t\tRead %d\n"), nbRead2); totalRead += (nbRead + nbRead2); // NGL_LOG(_T("nuiAudioTrack"), NGL_LOG_DEBUG, _T("\n\t\t\t\tReadTh : %d samples read"), totalRead); // event callback ProcessedSamples(totalRead, mBufSize, mpRingBuf->GetReadable ()); }
void nuiAudioTrack::Read(uint32 sampleFrames) { NGL_ASSERT(mpRingBuf); uint32 nbRead=sampleFrames; uint32 nbWrite=0; uint32 nbWrite2=0; std::vector<float*> rbuf(mNbChannels); uint32 c; //NGL_LOG(_T("nuiAudioFifo"), NGL_LOG_DEBUG, _T("\nWrite : read %d from source\n"), nbRead); //******************************************* // // first pass writing in ringBuffer // nbWrite = mpRingBuf->GetWritableToEnd (); // the writable space may have grown since the last call of GetWritable, check that nbWrite = (nbWrite > nbRead) ? nbRead : nbWrite; for (c=0; c<mNbChannels; c++) rbuf[c] = (float*)mpRingBuf->GetWritePointer(c); //NGL_LOG(_T("nuiAudioFifo"), NGL_LOG_DEBUG, _T("\nBEFORE BUFFERING %d\n"), nbWrite); // read audio samples from the source uint32 nbReadSamples = ReadSamples(nbWrite, rbuf/*ref for output*/); if (!nbReadSamples) return; //NGL_LOG(_T("nuiAudioFifo"), NGL_LOG_DEBUG, _T("\nAFTER BUFFERING %d\n"), nbWrite); mpRingBuf->AdvanceWriteIndex(nbWrite); //NGL_LOG(_T("nuiAudioFifo"), NGL_LOG_DEBUG, _T("\nWrite %d\n"), nbWrite); // everything has been written. no need of 2nd pass if (nbWrite == nbRead) return; //******************************************* // // second pass writing in ringBuffer // nbWrite2 = mpRingBuf->GetWritableToEnd(); if (nbWrite2 < (nbRead - nbWrite)) { NGL_LOG(_T("nuiAudioTrack"), NGL_LOG_ERROR, _T("ERROR : ringbuffer could not locked enough space to write data (%d requested, %d provided!)"), (nbRead-nbWrite), nbWrite2); NGL_ASSERT(0); return; } nbWrite2 = nbRead - nbWrite; for (c=0; c<mNbChannels; c++) rbuf[c] = (float*)mpRingBuf->GetWritePointer(c); // read audio samples from the source nbReadSamples = ReadSamples(nbWrite2, rbuf/*ref for output*/); if (!nbReadSamples) return; mpRingBuf->AdvanceWriteIndex (nbWrite2); //NGL_LOG(_T("nuiAudioTrack"), NGL_LOG_DEBUG, _T("\nWrite %d\n"), nbWrite); }
void Manager_Impl_OpenAL::ThreadFuncInternal() { Sample bufs[queueSize][bufferSize]; int32_t targetBuf = 0; while (m_threading) { // バッファにデータを読み込みソースに追加 ALint queue; alGetSourceiv(m_source, AL_BUFFERS_QUEUED, &queue); if (!queue) { for (auto b : m_buffers) { ReadSamples(bufs[targetBuf], bufferSize); alBufferData(b, format, bufs[targetBuf], bufferBytes, freq); alSourceQueueBuffers(m_source, 1, &b); targetBuf = (targetBuf + 1) % 4; } } // 再生状態にする ALint state; alGetSourcei(m_source, AL_SOURCE_STATE, &state); if (state != AL_PLAYING) { alSourcePlay(m_source); } // 再生終了したバッファにデータを読み込み ALint processed; alGetSourceiv(m_source, AL_BUFFERS_PROCESSED, &processed); while (processed > 0) { ALuint unqueued; alSourceUnqueueBuffers(m_source, 1, &unqueued); ReadSamples(bufs[targetBuf], bufferSize); alBufferData(unqueued, format, bufs[targetBuf], bufferBytes, freq); alSourceQueueBuffers(m_source, 1, &unqueued); targetBuf = (targetBuf + 1) % 4; --processed; } Sleep(10); } // 終わりまで待つ while (true) { ALint queued; alGetSourceiv(m_source, AL_BUFFERS_QUEUED, &queued); if (!queued) { break; } ALint processed; alGetSourceiv(m_source, AL_BUFFERS_PROCESSED, &processed); while (processed > 0) { ALuint unqueued; alSourceUnqueueBuffers(m_source, 1, &unqueued); --processed; } Sleep(10); } }