mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 14:29:03 +02:00
make pulsate function into a cos
This commit is contained in:
parent
53fb9e9047
commit
125ef0e3e2
2 changed files with 18 additions and 17 deletions
|
@ -54,9 +54,6 @@ static const int APPROXIMATELY_30_SECONDS_OF_AUDIO_PACKETS = (int)(30.0f * 1000.
|
||||||
|
|
||||||
// Mute icon configration
|
// Mute icon configration
|
||||||
static const int MUTE_ICON_SIZE = 24;
|
static const int MUTE_ICON_SIZE = 24;
|
||||||
static const float PULSE_MIN = 0.0f;
|
|
||||||
static const float PULSE_MAX = 1.0f;
|
|
||||||
static const float PULSE_STEP = 0.05f;
|
|
||||||
|
|
||||||
static const int RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES = 100;
|
static const int RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES = 100;
|
||||||
|
|
||||||
|
@ -102,7 +99,7 @@ Audio::Audio(QObject* parent) :
|
||||||
_reverbOptions(&_scriptReverbOptions),
|
_reverbOptions(&_scriptReverbOptions),
|
||||||
_gverb(NULL),
|
_gverb(NULL),
|
||||||
_iconColor(1.0f),
|
_iconColor(1.0f),
|
||||||
_iconPulseFactor(-1),
|
_iconPulseTimeReference(usecTimestampNow()),
|
||||||
_processSpatialAudio(false),
|
_processSpatialAudio(false),
|
||||||
_spatialAudioStart(0),
|
_spatialAudioStart(0),
|
||||||
_spatialAudioFinish(0),
|
_spatialAudioFinish(0),
|
||||||
|
@ -1397,33 +1394,37 @@ void Audio::renderToolBox(int x, int y, bool boxed) {
|
||||||
if (!_muted) {
|
if (!_muted) {
|
||||||
glBindTexture(GL_TEXTURE_2D, _micTextureId);
|
glBindTexture(GL_TEXTURE_2D, _micTextureId);
|
||||||
_iconColor = 1.0f;
|
_iconColor = 1.0f;
|
||||||
_iconPulseFactor = -1;
|
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D, _muteTextureId);
|
glBindTexture(GL_TEXTURE_2D, _muteTextureId);
|
||||||
|
|
||||||
// Make muted icon pulsate
|
// Make muted icon pulsate
|
||||||
_iconColor += _iconPulseFactor * PULSE_STEP;
|
static const float PULSE_MIN = 0.4f;
|
||||||
if (_iconColor >= PULSE_MAX) {
|
static const float PULSE_MAX = 1.0f;
|
||||||
_iconColor = PULSE_MAX;
|
static const float PULSE_FREQUENCY = 1.0f; // in Hz
|
||||||
_iconPulseFactor = -1;
|
qint64 now = usecTimestampNow();
|
||||||
} else if (_iconColor <= PULSE_MIN) {
|
if (now - _iconPulseTimeReference > USECS_PER_SECOND) {
|
||||||
_iconColor = PULSE_MIN;
|
// Prevents t from getting too big, which would diminish glm::cos precision
|
||||||
_iconPulseFactor = 1;
|
_iconPulseTimeReference = now - ((now - _iconPulseTimeReference) % USECS_PER_SECOND);
|
||||||
}
|
}
|
||||||
|
float t = (float)(now - _iconPulseTimeReference) / (float)USECS_PER_SECOND;
|
||||||
|
float pulseFactor = (glm::cos(t * PULSE_FREQUENCY * 2.0f * PI) + 1.0f) / 2.0f;
|
||||||
|
_iconColor = PULSE_MIN + (PULSE_MAX - PULSE_MIN) * pulseFactor;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glColor3f(_iconColor, _iconColor, _iconColor);
|
glColor3f(_iconColor, _iconColor, _iconColor);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
glTexCoord2f(1, 1);
|
glTexCoord2f(1.0f, 1.0f);
|
||||||
glVertex2f(_iconBounds.left(), _iconBounds.top());
|
glVertex2f(_iconBounds.left(), _iconBounds.top());
|
||||||
|
|
||||||
glTexCoord2f(0, 1);
|
glTexCoord2f(0.0f, 1.0f);
|
||||||
glVertex2f(_iconBounds.right(), _iconBounds.top());
|
glVertex2f(_iconBounds.right(), _iconBounds.top());
|
||||||
|
|
||||||
glTexCoord2f(0, 0);
|
glTexCoord2f(0.0f, 0.0f);
|
||||||
glVertex2f(_iconBounds.right(), _iconBounds.bottom());
|
glVertex2f(_iconBounds.right(), _iconBounds.bottom());
|
||||||
|
|
||||||
glTexCoord2f(1, 0);
|
glTexCoord2f(1.0f, 0.0f);
|
||||||
glVertex2f(_iconBounds.left(), _iconBounds.bottom());
|
glVertex2f(_iconBounds.left(), _iconBounds.bottom());
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
|
@ -254,7 +254,7 @@ private:
|
||||||
GLuint _boxTextureId;
|
GLuint _boxTextureId;
|
||||||
QRect _iconBounds;
|
QRect _iconBounds;
|
||||||
float _iconColor;
|
float _iconColor;
|
||||||
int _iconPulseFactor;
|
qint64 _iconPulseTimeReference;
|
||||||
|
|
||||||
/// Audio callback in class context.
|
/// Audio callback in class context.
|
||||||
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
||||||
|
|
Loading…
Reference in a new issue