void FVlcMediaAudioHandler::HandleAudioPlay(void* Opaque, void* Samples, uint32 Count, int64 Timestamp) { auto Handler = (FVlcMediaAudioHandler*)Opaque; if (Handler != nullptr) { auto CurrentAudioTrack = Handler->CurrentAudioTrack.Pin(); if (CurrentAudioTrack.IsValid()) { CurrentAudioTrack->ProcessSamples(Samples, Count); } } }
void EffectNoiseRemoval::FinishTrack() { // Keep flushing empty input buffers through the history // windows until we've output exactly as many samples as // were input. // Well, not exactly, but not more than mWindowSize/2 extra samples at the end. // We'll delete them later in ProcessOne. float *empty = new float[mWindowSize / 2]; int i; for(i = 0; i < mWindowSize / 2; i++) empty[i] = 0.0; while (mOutSampleCount < mInSampleCount) { ProcessSamples(mWindowSize / 2, empty); } }
/*---------------------------------------------------------------------- | ProcessMoof +---------------------------------------------------------------------*/ static int ProcessMoof(AP4_Movie* movie, AP4_ContainerAtom* moof, AP4_ByteStream* sample_stream, AP4_Position moof_offset, AP4_Position mdat_payload_offset) { AP4_Result result; AP4_MovieFragment* fragment = new AP4_MovieFragment(moof); printf("fragment sequence number=%d\n", fragment->GetSequenceNumber()); AP4_FragmentSampleTable* sample_table = NULL; // get all track IDs in this fragment AP4_Array<AP4_UI32> ids; fragment->GetTrackIds(ids); printf("Found %d tracks in fragment: ", ids.ItemCount()); for (unsigned int i=0; i<ids.ItemCount(); i++) { printf("%d ", ids[i]); } printf("\n"); for (unsigned int i=0; i<ids.ItemCount(); i++) { AP4_Track* track = NULL; if (movie) { track = movie->GetTrack(ids[i]); } AP4_ContainerAtom* traf = NULL; fragment->GetTrafAtom(ids[i], traf); printf("processing moof for track id %d\n", ids[i]); result = fragment->CreateSampleTable(movie, ids[i], sample_stream, moof_offset, mdat_payload_offset, sample_table); CHECK(result == AP4_SUCCESS || result == AP4_ERROR_NO_SUCH_ITEM); if (AP4_SUCCEEDED(result) ) { ProcessSamples(track, traf, sample_table); delete sample_table; } else { printf("no sample table for this track\n"); } } delete fragment; return 0; }
//////////////////////////////////////////////////////////// /// Get available captured samples and process them //////////////////////////////////////////////////////////// void SoundRecorder::ProcessCapturedSamples() { // Get the number of samples available ALCint SamplesAvailable; alcGetIntegerv(CaptureDevice, ALC_CAPTURE_SAMPLES, 1, &SamplesAvailable); if (SamplesAvailable > 0) { // Get the recorded samples mySamples.resize(SamplesAvailable); alcCaptureSamples(CaptureDevice, &mySamples[0], SamplesAvailable); // Forward them to the derived class if (!ProcessSamples(&mySamples[0], mySamples.size())) { // The user wants to stop the capture myIsCapturing = false; } } }
void spp_AudioManager::LoadWAVSound(string fileName, string tag) { //source http://www.youtube.com/watch?v=V83Ja4FmrqE //information needed to play the file DWORD chunkSize; DWORD fileSize; short formatType; short channels; DWORD sampleRate; DWORD averageBytesPerSecond; DWORD dataSize; short bytesPerSample; short bitsPerSample; char typeInfo[4]; ALenum format=0; //opining the file FILE *wavFile = NULL; fopen_s(&wavFile, fileName.c_str(), "rb"); if(wavFile == NULL) { Log("WAV file not found: ", fileName, "LoadWAVFile in spp_AudioManager."); return; } //the next three chunks do error checking. When the error output is implemented, they will // tell the user what went wrong, but for now they just return fread(typeInfo, sizeof(char),4,wavFile); if(typeInfo[0]!='R' || typeInfo[1]!='I' || typeInfo[2] != 'F' || typeInfo[3] != 'F') { Log("File did not have RIFF: ", fileName, "LoadWAVFile in spp_AudioManager."); return; } fread(&fileSize, sizeof(DWORD), 1, wavFile); fread(typeInfo, sizeof(char), 4, wavFile); if(typeInfo[0]!='W' || typeInfo[1]!='A' || typeInfo[2] != 'V' || typeInfo[3] != 'E') { Log("File is not a WAV file: ", fileName, "LoadWAVFile in spp_AudioManager."); return; } fread(typeInfo, sizeof(char), 4, wavFile); if(typeInfo[0]!='f' || typeInfo[1]!='m' || typeInfo[2] != 't' || typeInfo[3] != ' ') { Log("WAV did not have fmt header: ", fileName, "LoadWAVFile in spp_AudioManager."); return; } //reading data about the sound contained in the wave file fread(&chunkSize, sizeof(DWORD), 1, wavFile); fread(&formatType, sizeof(short), 1, wavFile); fread(&channels, sizeof(short), 1, wavFile); fread(&sampleRate, sizeof(DWORD), 1, wavFile); fread(&averageBytesPerSecond, sizeof(DWORD), 1, wavFile); fread(&bytesPerSample, sizeof(short), 1, wavFile); fread(&bitsPerSample, sizeof(short), 1, wavFile); //validating that data is present fread(typeInfo, sizeof(char),4,wavFile); if(typeInfo[0]!='d' || typeInfo[1]!='a' || typeInfo[2] != 't' || typeInfo[3] != 'a') { Log("WAV did not have data: ", fileName, "LoadWAVFile in spp_AudioManager."); return; } //getting the size of the data fread(&dataSize, sizeof(DWORD), 1,wavFile); //reading the audio data into a form that can be played in an OpenAL buffer unsigned char* audioData = new unsigned char[dataSize]; fread(audioData,sizeof(BYTE), dataSize, wavFile); vector<char> dataVector; dataVector.insert(dataVector.end(), audioData, audioData + dataSize); //setting for format, stereo or mono if(bitsPerSample == 8) { if(channels = 1) { format = AL_FORMAT_MONO8; } else if(channels == 2) { format = AL_FORMAT_STEREO8; Log("Stereo sound loaded: 3D audio will not work with this file: ", fileName, "LoadWAVFile in spp_AudioManager."); } } else if(bitsPerSample == 16) { if(channels == 1) { format = AL_FORMAT_MONO16; } else if(channels == 2) { format = AL_FORMAT_STEREO16; Log("Stereo sound loaded: 3D audio will not work with this file: ", fileName, "LoadWAVFile in spp_AudioManager."); } } ProcessSamples(dataVector); //creating the OpenAL buffer to hold the data ALuint buffer; alGenBuffers(1, &buffer); Log("LoadWAVSound in spp_AudioManager."); //assigning the data to the buffer alBufferData(buffer, format, &dataVector[0], dataSize, sampleRate); Log("LoadWAVSound in spp_AudioManager."); //adding it to the manager's list of buffers mBufferList.insert(pair<string, ALuint>(tag, buffer)); //closing the WAV file fclose(wavFile); }
void spp_AudioManager::LoadOGGSound(string fileName, string tag) { //source http://www.gamedev.net/page/resources/_/technical/game-programming/introduction-to-ogg-vorbis-r2031 //information needed to open file int endian = 0; int bitStream; long dataReadFromFile; char bufferInformation[SPP_OGG_SIZE_TO_READ]; ALenum format; ALsizei freqency; DWORD dataSize; ALuint buffer; FILE *file; vector < char > dataForBuffer; vorbis_info *oggInformation; OggVorbis_File oggFile; //opening the file fopen_s(&file, fileName.c_str(), "rb"); //this is needed to properly open an ogg file on windows ov_callbacks OV_CALLBACKS_DEFAULT = { (size_t (*)(void *, size_t, size_t, void *)) fread, (int (*)(void *, ogg_int64_t, int)) _ov_header_fseek_wrap, (int (*)(void *)) fclose, (long (*)(void *)) ftell }; //This is what actually opens the file int fileError = ov_open_callbacks(file, &oggFile, NULL, 0, OV_CALLBACKS_DEFAULT); if(fileError < 0) { Log("OGG file could not be opened: ", fileName, "LoadOGGFile in spp_AudioManager."); return; } //format information about the OGG file oggInformation = ov_info(&oggFile, -1); //information on channels if(oggInformation->channels == 1) { format = AL_FORMAT_MONO16; } else { format = AL_FORMAT_STEREO16; Log("Stereo sound loaded: 3D audio will not work with this file: ", fileName, "LoadOGGFile in spp_AudioManager."); } freqency = oggInformation->rate; //while data is still found in the file, add it to the buffer do { dataReadFromFile = ov_read(&oggFile, bufferInformation, SPP_OGG_SIZE_TO_READ, endian, 2, 1, &bitStream); dataForBuffer.insert(dataForBuffer.end(), bufferInformation, bufferInformation + dataReadFromFile); }while(dataReadFromFile > 0); //close the OGG file ov_clear(&oggFile); dataSize = static_cast<ALsizei>(dataForBuffer.size()); ProcessSamples(dataForBuffer); //creating the OpenAL buffer alGenBuffers(1, &buffer); Log("LoadOGGFile in spp_AudioManager."); alBufferData(buffer, format, &dataForBuffer[0], dataSize, freqency); Log("LoadOGGFile in spp_AudioManager."); //adding the buffer to the list mBufferList.insert(pair<string, ALuint>(tag, buffer)); }
bool EffectNoiseRemoval::ProcessOne(int count, WaveTrack * track, sampleCount start, sampleCount len) { if (track == NULL) return false; StartNewTrack(); if (!mDoProfile) mOutputTrack = mFactory->NewWaveTrack(track->GetSampleFormat(), track->GetRate()); sampleCount bufferSize = track->GetMaxBlockSize(); float *buffer = new float[bufferSize]; bool bLoopSuccess = true; sampleCount blockSize; sampleCount samplePos = start; while (samplePos < start + len) { //Get a blockSize of samples (smaller than the size of the buffer) blockSize = track->GetBestBlockSize(samplePos); //Adjust the block size if it is the final block in the track if (samplePos + blockSize > start + len) blockSize = start + len - samplePos; //Get the samples from the track and put them in the buffer track->Get((samplePtr)buffer, floatSample, samplePos, blockSize); mInSampleCount += blockSize; ProcessSamples(blockSize, buffer); samplePos += blockSize; // Update the Progress meter if (TrackProgress(count, (samplePos - start) / (double)len)) { bLoopSuccess = false; break; } } FinishTrack(); delete [] buffer; if (!mDoProfile) { // Flush the output WaveTrack (since it's buffered) mOutputTrack->Flush(); // Take the output track and insert it in place of the original // sample data if (bLoopSuccess) { track->HandleClear(mT0, mT1, false, false); // Filtering effects always end up with more data than they started with. Delete this 'tail'. mOutputTrack->HandleClear(mT1 - mT0, mOutputTrack->GetEndTime(), false, false); track->HandlePaste(mT0, mOutputTrack); } // Delete the outputTrack now that its data is inserted in place delete mOutputTrack; mOutputTrack = NULL; } return bLoopSuccess; }