Advertisement
GreenSeaCow

Wwise Plugin Test Tone

Jan 25th, 2024
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | Source Code | 0 0
  1. void SynthezzitoSource::Execute(AkAudioBuffer* out_pBuffer)
  2. {
  3.     m_durationHandler.SetDuration(m_pParams->RTPC.fDuration);
  4.     m_durationHandler.ProduceBuffer(out_pBuffer);
  5.  
  6.     const AkUInt32 uNumChannels = out_pBuffer->NumChannels();
  7.  
  8.     AkUInt16 uFramesProduced;
  9.  
  10.     //CUSTOM CODE---------------------------------------------------------------
  11.  
  12.     static float phase = 0.0f;  // Phase of the sine wave, static to maintain value between calls
  13.     float twoPi = 2.0f * 3.1415f;  // Constant for 2*pi
  14.     float freq = 440.0f;
  15.     float sampleRate = 48000;
  16.  
  17.     for (AkUInt32 i = 0; i < uNumChannels; ++i)
  18.     {
  19.         AkReal32* AK_RESTRICT pBuf = (AkReal32* AK_RESTRICT)out_pBuffer->GetChannel(i);
  20.        
  21.         uFramesProduced = 0;
  22.  
  23.         while (uFramesProduced < out_pBuffer->uValidFrames)
  24.         {
  25.             // Generate output here
  26.             *pBuf++ = 0.7f * sin(phase);
  27.             phase += twoPi * freq / sampleRate;
  28.  
  29.             // Wrap the phase to avoid precision issues
  30.             if (phase > twoPi)
  31.             {
  32.                 phase -= twoPi;
  33.             }
  34.             ++uFramesProduced;
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement