Account for stereo audio in recorder

This commit is contained in:
Atlante45 2015-03-17 16:34:50 +01:00
parent 7121126e6f
commit 3a11ed0574
3 changed files with 14 additions and 12 deletions

View file

@ -169,6 +169,8 @@ void Player::setupAudioThread() {
_audioThread->setObjectName("Player Audio Thread"); _audioThread->setObjectName("Player Audio Thread");
_options.position = _avatar->getPosition(); _options.position = _avatar->getPosition();
_options.orientation = _avatar->getOrientation(); _options.orientation = _avatar->getOrientation();
_options.stereo = _recording->numberAudioChannel() == 2;
_injector.reset(new AudioInjector(_recording->getAudioData(), _options), &QObject::deleteLater); _injector.reset(new AudioInjector(_recording->getAudioData(), _options), &QObject::deleteLater);
_injector->moveToThread(_audioThread); _injector->moveToThread(_audioThread);
_audioThread->start(); _audioThread->start();
@ -349,15 +351,7 @@ void Player::setCurrentTime(int currentTime) {
} }
} }
_currentFrame = lowestBound; setCurrentFrame(lowestBound);
_timerOffset = _recording->getFrameTimestamp(lowestBound);
if (isPlaying()) {
_timer.start();
setAudioInjectorPosition();
} else {
_pausedFrame = lowestBound;
}
} }
void Player::setVolume(float volume) { void Player::setVolume(float volume) {
@ -374,9 +368,7 @@ void Player::setAudioOffset(int audioOffset) {
void Player::setAudioInjectorPosition() { void Player::setAudioInjectorPosition() {
int MSEC_PER_SEC = 1000; int MSEC_PER_SEC = 1000;
int SAMPLE_SIZE = 2; // 16 bits int FRAME_SIZE = sizeof(AudioConstants::AudioSample) * _recording->numberAudioChannel();
int CHANNEL_COUNT = 1;
int FRAME_SIZE = SAMPLE_SIZE * CHANNEL_COUNT;
int currentAudioFrame = elapsed() * FRAME_SIZE * (AudioConstants::SAMPLE_RATE / MSEC_PER_SEC); int currentAudioFrame = elapsed() * FRAME_SIZE * (AudioConstants::SAMPLE_RATE / MSEC_PER_SEC);
_injector->setCurrentSendPosition(currentAudioFrame); _injector->setCurrentSendPosition(currentAudioFrame);
} }

View file

@ -65,6 +65,15 @@ const RecordingFrame& Recording::getFrame(int i) const {
return _frames[i]; return _frames[i];
} }
int Recording::numberAudioChannel() const {
// Check for stereo audio
int MSEC_PER_SEC = 1000;
int channelLength = (getLength() / MSEC_PER_SEC) *
AudioConstants::SAMPLE_RATE * sizeof(AudioConstants::AudioSample);
return glm::round((float)channelLength / (float)getAudioData().size());
}
void Recording::addFrame(int timestamp, RecordingFrame &frame) { void Recording::addFrame(int timestamp, RecordingFrame &frame) {
_timestamps << timestamp; _timestamps << timestamp;
_frames << frame; _frames << frame;

View file

@ -56,6 +56,7 @@ public:
qint32 getFrameTimestamp(int i) const; qint32 getFrameTimestamp(int i) const;
const RecordingFrame& getFrame(int i) const; const RecordingFrame& getFrame(int i) const;
const QByteArray& getAudioData() const { return _audioData; } const QByteArray& getAudioData() const { return _audioData; }
int numberAudioChannel() const;
protected: protected:
void addFrame(int timestamp, RecordingFrame& frame); void addFrame(int timestamp, RecordingFrame& frame);