mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-13 03:33:13 +02:00
have the audio injector return intensity of last frame
This commit is contained in:
parent
33b6ca31b0
commit
28ce4f55c1
3 changed files with 24 additions and 5 deletions
|
@ -20,7 +20,8 @@ AudioInjector::AudioInjector(const char* filename) :
|
|||
_radius(0.0f),
|
||||
_volume(MAX_INJECTOR_VOLUME),
|
||||
_indexOfNextSlot(0),
|
||||
_isInjectingAudio(false)
|
||||
_isInjectingAudio(false),
|
||||
_lastFrameIntensity(0.0f)
|
||||
{
|
||||
loadRandomIdentifier(_streamIdentifier, STREAM_IDENTIFIER_NUM_BYTES);
|
||||
|
||||
|
@ -50,7 +51,8 @@ AudioInjector::AudioInjector(int maxNumSamples) :
|
|||
_radius(0.0f),
|
||||
_volume(MAX_INJECTOR_VOLUME),
|
||||
_indexOfNextSlot(0),
|
||||
_isInjectingAudio(false)
|
||||
_isInjectingAudio(false),
|
||||
_lastFrameIntensity(0.0f)
|
||||
{
|
||||
loadRandomIdentifier(_streamIdentifier, STREAM_IDENTIFIER_NUM_BYTES);
|
||||
|
||||
|
@ -113,6 +115,18 @@ void AudioInjector::injectAudio(UDPSocket* injectorSocket, sockaddr* destination
|
|||
|
||||
injectorSocket->send(destinationSocket, dataPacket, sizeof(dataPacket));
|
||||
|
||||
// calculate the intensity for this frame
|
||||
float lastRMS = 0;
|
||||
|
||||
for (int j = 0; j < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; j++) {
|
||||
lastRMS += _audioSampleArray[i + j] * _audioSampleArray[i + j];
|
||||
}
|
||||
|
||||
lastRMS /= BUFFER_LENGTH_SAMPLES_PER_CHANNEL;
|
||||
lastRMS = sqrtf(lastRMS);
|
||||
|
||||
_lastFrameIntensity = lastRMS / INT16_MAX;
|
||||
|
||||
int usecToSleep = usecTimestamp(&startTime) + (++nextFrame * INJECT_INTERVAL_USECS) - usecTimestampNow();
|
||||
if (usecToSleep > 0) {
|
||||
usleep(usecToSleep);
|
||||
|
|
|
@ -35,6 +35,8 @@ public:
|
|||
unsigned char getVolume() const { return _volume; }
|
||||
void setVolume(unsigned char volume) { _volume = volume; }
|
||||
|
||||
float getLastFrameIntensity() const { return _lastFrameIntensity; }
|
||||
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
void setPosition(const glm::vec3& position) { _position = position; }
|
||||
|
||||
|
@ -56,6 +58,7 @@ private:
|
|||
unsigned char _volume;
|
||||
int _indexOfNextSlot;
|
||||
bool _isInjectingAudio;
|
||||
float _lastFrameIntensity;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__AudioInjector__) */
|
||||
|
|
|
@ -176,9 +176,11 @@ void Operative::renderMovingBug() {
|
|||
_bugDetails[i].y = offsetPartAt.y;
|
||||
_bugDetails[i].z = offsetPartAt.z;
|
||||
|
||||
_bugDetails[i].red = BUG_PARTS[i].partColor[0];
|
||||
_bugDetails[i].green = BUG_PARTS[i].partColor[1];
|
||||
_bugDetails[i].blue = BUG_PARTS[i].partColor[2];
|
||||
float colorRatio = (powf(injector->getLastFrameIntensity(), 0.5) * 0.5f) + 0.5f;
|
||||
|
||||
_bugDetails[i].red = BUG_PARTS[i].partColor[0] * colorRatio;
|
||||
_bugDetails[i].green = BUG_PARTS[i].partColor[1] * colorRatio;
|
||||
_bugDetails[i].blue = BUG_PARTS[i].partColor[2] * colorRatio;
|
||||
}
|
||||
|
||||
// send the "create message" ...
|
||||
|
|
Loading…
Reference in a new issue