Advertisement
Guest User

Untitled

a guest
Nov 17th, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. //Error checking code and lots of other misc code not related to audio stripped out.
  2. bool Video::Load(SDL_Renderer* pNewRenderer, std::string strFileToLoad, AudioSystem* pNewAudioSystem)
  3. {
  4. this->strFileName = strFileToLoad;
  5.  
  6. pDecoder = THEORAPLAY_startDecodeFile(strFileToLoad.c_str(), 60, THEORAPLAY_VIDFMT_IYUV);
  7.  
  8. while (!pAudio || !pVideo)
  9. {
  10. if (!pAudio)
  11. pAudio = THEORAPLAY_getAudio(pDecoder);
  12. if (!pVideo)
  13. pVideo = THEORAPLAY_getVideo(pDecoder);
  14. }
  15.  
  16. int width = pVideo->width;
  17. int height = pVideo->height;
  18.  
  19.  
  20. fFrameMS = (pVideo->fps == 0.0) ? 0 : ((1000.0 / pVideo->fps));
  21. fPassedMS = 0.0f;
  22.  
  23. if (pTexture != 0)
  24. SDL_DestroyTexture(pTexture);
  25.  
  26. pTexture = SDL_CreateTexture(pNewRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, pVideo->width, pVideo->height);
  27.  
  28. this->bIsVideoDone = false;
  29. return true;
  30. }
  31.  
  32. bool Video::Render(SDL_Renderer* pRenderer, double dTicks)
  33. {
  34. if(bIsActive)
  35. {
  36. if (!bIsPaused)
  37. {
  38. fPassedMS += (dTicks);
  39.  
  40. //Code that parsed video removed since it was working perfectly and didn't want to clutter things too much
  41.  
  42. if(!pAudio)
  43. this->pAudio = THEORAPLAY_getAudio(pDecoder);
  44.  
  45. if (pAudio && (pAudio->playms <= (unsigned int)fPassedMS))
  46. {
  47. if (fFrameMS && (fPassedMS - (double)(pAudio->playms) >= fFrameMS))
  48. {
  49. const THEORAPLAY_AudioPacket* last = pAudio;
  50. while ((pAudio = THEORAPLAY_getAudio(pDecoder)) != NULL)
  51. {
  52. THEORAPLAY_freeAudio(last);
  53. last = pAudio;
  54. if ((fPassedMS - (double)pAudio->playms) < fFrameMS)
  55. break;
  56. }
  57.  
  58. if (!pAudio)
  59. pAudio = last;
  60.  
  61. //This section is sending a audio Packet over to FMOD
  62. RawSound* pNewSoundPacket = new RawSound;
  63. pNewSoundPacket->nID = this->nRenderID; //
  64. pNewSoundPacket->dRemainingMS = (double)(pAudio->playms) - fPassedMS;
  65. pNewSoundPacket->pRawAudio = (this->pAudio);
  66. this->pMessageSystem->CreateMessage(ENUMMESSAGETYPE::ePLAYRAWAUDIO, (void*)(pNewSoundPacket));
  67. }
  68. }
  69. }
  70. }
  71.  
  72. void AudioSystem::RawAudio(RawSound* pAudio)
  73. {
  74. FMOD::Sound* pNewFSound = 0;
  75. FMOD_RESULT resError;
  76.  
  77. //Using the same size equasion as the Theoraplay wrapper uses to allocate space
  78. unsigned int nSampleSize = sizeof(float) * (pAudio->pRawAudio->frames) * (pAudio->pRawAudio->channels);
  79.  
  80. FMOD_CREATESOUNDEXINFO fExtra;
  81. memset(&fExtra, 0, sizeof(FMOD_CREATESOUNDEXINFO));
  82.  
  83. fExtra.length = nSampleSize;
  84. fExtra.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
  85. fExtra.defaultfrequency = pAudio->pRawAudio->freq;
  86. fExtra.numchannels = pAudio->pRawAudio->channels;
  87. fExtra.format = FMOD_SOUND_FORMAT_PCMFLOAT;
  88.  
  89. resError = m_pSystem->createSound((const char*)(pAudio->pRawAudio->samples), FMOD_OPENMEMORY | FMOD_CREATESAMPLE | FMOD_OPENRAW | FMOD_LOOP_OFF, &fExtra, &pNewFSound);
  90.  
  91.  
  92. vecSoundsAndChannels[ENUMSOUNDTYPE::eVIDEOAUDIO]->pChannelGroupData->stop();
  93.  
  94. resError = m_pSystem->playSound(pNewFSound, vecSoundsAndChannels[ENUMSOUNDTYPE::eVIDEOAUDIO]->pChannelGroupData, false, 0);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement