Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Error checking code and lots of other misc code not related to audio stripped out.
- bool Video::Load(SDL_Renderer* pNewRenderer, std::string strFileToLoad, AudioSystem* pNewAudioSystem)
- {
- this->strFileName = strFileToLoad;
- pDecoder = THEORAPLAY_startDecodeFile(strFileToLoad.c_str(), 60, THEORAPLAY_VIDFMT_IYUV);
- while (!pAudio || !pVideo)
- {
- if (!pAudio)
- pAudio = THEORAPLAY_getAudio(pDecoder);
- if (!pVideo)
- pVideo = THEORAPLAY_getVideo(pDecoder);
- }
- int width = pVideo->width;
- int height = pVideo->height;
- fFrameMS = (pVideo->fps == 0.0) ? 0 : ((1000.0 / pVideo->fps));
- fPassedMS = 0.0f;
- if (pTexture != 0)
- SDL_DestroyTexture(pTexture);
- pTexture = SDL_CreateTexture(pNewRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, pVideo->width, pVideo->height);
- this->bIsVideoDone = false;
- return true;
- }
- bool Video::Render(SDL_Renderer* pRenderer, double dTicks)
- {
- if(bIsActive)
- {
- if (!bIsPaused)
- {
- fPassedMS += (dTicks);
- //Code that parsed video removed since it was working perfectly and didn't want to clutter things too much
- if(!pAudio)
- this->pAudio = THEORAPLAY_getAudio(pDecoder);
- if (pAudio && (pAudio->playms <= (unsigned int)fPassedMS))
- {
- if (fFrameMS && (fPassedMS - (double)(pAudio->playms) >= fFrameMS))
- {
- const THEORAPLAY_AudioPacket* last = pAudio;
- while ((pAudio = THEORAPLAY_getAudio(pDecoder)) != NULL)
- {
- THEORAPLAY_freeAudio(last);
- last = pAudio;
- if ((fPassedMS - (double)pAudio->playms) < fFrameMS)
- break;
- }
- if (!pAudio)
- pAudio = last;
- //This section is sending a audio Packet over to FMOD
- RawSound* pNewSoundPacket = new RawSound;
- pNewSoundPacket->nID = this->nRenderID; //
- pNewSoundPacket->dRemainingMS = (double)(pAudio->playms) - fPassedMS;
- pNewSoundPacket->pRawAudio = (this->pAudio);
- this->pMessageSystem->CreateMessage(ENUMMESSAGETYPE::ePLAYRAWAUDIO, (void*)(pNewSoundPacket));
- }
- }
- }
- }
- void AudioSystem::RawAudio(RawSound* pAudio)
- {
- FMOD::Sound* pNewFSound = 0;
- FMOD_RESULT resError;
- //Using the same size equasion as the Theoraplay wrapper uses to allocate space
- unsigned int nSampleSize = sizeof(float) * (pAudio->pRawAudio->frames) * (pAudio->pRawAudio->channels);
- FMOD_CREATESOUNDEXINFO fExtra;
- memset(&fExtra, 0, sizeof(FMOD_CREATESOUNDEXINFO));
- fExtra.length = nSampleSize;
- fExtra.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
- fExtra.defaultfrequency = pAudio->pRawAudio->freq;
- fExtra.numchannels = pAudio->pRawAudio->channels;
- fExtra.format = FMOD_SOUND_FORMAT_PCMFLOAT;
- resError = m_pSystem->createSound((const char*)(pAudio->pRawAudio->samples), FMOD_OPENMEMORY | FMOD_CREATESAMPLE | FMOD_OPENRAW | FMOD_LOOP_OFF, &fExtra, &pNewFSound);
- vecSoundsAndChannels[ENUMSOUNDTYPE::eVIDEOAUDIO]->pChannelGroupData->stop();
- resError = m_pSystem->playSound(pNewFSound, vecSoundsAndChannels[ENUMSOUNDTYPE::eVIDEOAUDIO]->pChannelGroupData, false, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement