Merge pull request #4461 from Atlante45/fix_recordings

Fix recordings
This commit is contained in:
samcake 2015-03-18 09:52:29 -07:00
commit 948ced81ce
5 changed files with 18 additions and 16 deletions

View file

@ -812,7 +812,7 @@ void AudioClient::handleAudioInput() {
} }
emit inputReceived(QByteArray(reinterpret_cast<const char*>(networkAudioSamples), emit inputReceived(QByteArray(reinterpret_cast<const char*>(networkAudioSamples),
AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL)); AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * sizeof(AudioConstants::AudioSample)));
} else { } else {
// our input loudness is 0, since we're muted // our input loudness is 0, since we're muted

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();
@ -309,7 +311,7 @@ void Player::setCurrentFrame(int currentFrame) {
if (isPlaying()) { if (isPlaying()) {
_timer.start(); _timer.start();
setAudionInjectorPosition(); setAudioInjectorPosition();
} else { } else {
_pausedFrame = _currentFrame; _pausedFrame = _currentFrame;
} }
@ -349,15 +351,7 @@ void Player::setCurrentTime(int currentTime) {
} }
} }
_currentFrame = lowestBound; setCurrentFrame(lowestBound);
_timerOffset = _recording->getFrameTimestamp(lowestBound);
if (isPlaying()) {
_timer.start();
setAudionInjectorPosition();
} else {
_pausedFrame = lowestBound;
}
} }
void Player::setVolume(float volume) { void Player::setVolume(float volume) {
@ -372,11 +366,9 @@ void Player::setAudioOffset(int audioOffset) {
_audioOffset = audioOffset; _audioOffset = audioOffset;
} }
void Player::setAudionInjectorPosition() { 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

@ -61,7 +61,7 @@ private:
void setupAudioThread(); void setupAudioThread();
void cleanupAudioThread(); void cleanupAudioThread();
void loopRecording(); void loopRecording();
void setAudionInjectorPosition(); void setAudioInjectorPosition();
bool computeCurrentFrame(); bool computeCurrentFrame();
AvatarData* _avatar; AvatarData* _avatar;

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);