mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-02 08:51:12 +02:00
Merge pull request #16240 from ctrlaltdavid/BUGZ-577
BUGZ-577: Implement Recording.setPlayerVolume()
This commit is contained in:
commit
068fb0e177
5 changed files with 23 additions and 5 deletions
|
@ -433,7 +433,7 @@ void Agent::executeScript() {
|
||||||
|
|
||||||
using namespace recording;
|
using namespace recording;
|
||||||
static const FrameType AUDIO_FRAME_TYPE = Frame::registerFrameType(AudioConstants::getAudioFrameName());
|
static const FrameType AUDIO_FRAME_TYPE = Frame::registerFrameType(AudioConstants::getAudioFrameName());
|
||||||
Frame::registerFrameHandler(AUDIO_FRAME_TYPE, [this, &scriptedAvatar](Frame::ConstPointer frame) {
|
Frame::registerFrameHandler(AUDIO_FRAME_TYPE, [this, &player, &scriptedAvatar](Frame::ConstPointer frame) {
|
||||||
if (_shouldMuteRecordingAudio) {
|
if (_shouldMuteRecordingAudio) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -442,9 +442,18 @@ void Agent::executeScript() {
|
||||||
|
|
||||||
QByteArray audio(frame->data);
|
QByteArray audio(frame->data);
|
||||||
|
|
||||||
|
int16_t* samples = reinterpret_cast<int16_t*>(audio.data());
|
||||||
|
int numSamples = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL;
|
||||||
|
|
||||||
|
auto volume = player->getVolume();
|
||||||
|
if (volume >= 0.0f && volume < 1.0f) {
|
||||||
|
int32_t fract = (int32_t)(volume * (float)(1 << 16)); // Q16
|
||||||
|
for (int i = 0; i < numSamples; i++) {
|
||||||
|
samples[i] = (fract * (int32_t)samples[i]) >> 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_isNoiseGateEnabled) {
|
if (_isNoiseGateEnabled) {
|
||||||
int16_t* samples = reinterpret_cast<int16_t*>(audio.data());
|
|
||||||
int numSamples = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL;
|
|
||||||
_audioGate.render(samples, samples, numSamples);
|
_audioGate.render(samples, samples, numSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,10 @@ float Deck::position() const {
|
||||||
return Frame::frameTimeToSeconds(currentPosition);
|
return Frame::frameTimeToSeconds(currentPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Deck::setVolume(float volume) {
|
||||||
|
_volume = std::min(std::max(volume, 0.0f), 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
static const Frame::Time MIN_FRAME_WAIT_INTERVAL = Frame::secondsToFrameTime(0.001f);
|
static const Frame::Time MIN_FRAME_WAIT_INTERVAL = Frame::secondsToFrameTime(0.001f);
|
||||||
static const Frame::Time MAX_FRAME_PROCESSING_TIME = Frame::secondsToFrameTime(0.004f);
|
static const Frame::Time MAX_FRAME_PROCESSING_TIME = Frame::secondsToFrameTime(0.004f);
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,9 @@ public:
|
||||||
float position() const;
|
float position() const;
|
||||||
void seek(float position);
|
void seek(float position);
|
||||||
|
|
||||||
|
float getVolume() const { return _volume; }
|
||||||
|
void setVolume(float volume);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void playbackStateChanged();
|
void playbackStateChanged();
|
||||||
void looped();
|
void looped();
|
||||||
|
@ -76,6 +79,7 @@ private:
|
||||||
bool _pause { true };
|
bool _pause { true };
|
||||||
bool _loop { false };
|
bool _loop { false };
|
||||||
float _length { 0 };
|
float _length { 0 };
|
||||||
|
float _volume { 1.0f };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ void RecordingScriptingInterface::startPlaying() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordingScriptingInterface::setPlayerVolume(float volume) {
|
void RecordingScriptingInterface::setPlayerVolume(float volume) {
|
||||||
// FIXME
|
_player->setVolume(std::min(std::max(volume, 0.0f), 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordingScriptingInterface::setPlayerAudioOffset(float audioOffset) {
|
void RecordingScriptingInterface::setPlayerAudioOffset(float audioOffset) {
|
||||||
|
|
|
@ -95,8 +95,9 @@ public slots:
|
||||||
|
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
|
* Sets the playback audio volume.
|
||||||
* @function Recording.setPlayerVolume
|
* @function Recording.setPlayerVolume
|
||||||
* @param {number} volume
|
* @param {number} volume - The playback audio volume, range <code>0.0</code> – <code>1.0</code>.
|
||||||
*/
|
*/
|
||||||
void setPlayerVolume(float volume);
|
void setPlayerVolume(float volume);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue