Skip to content
Snippets Groups Projects
Commit 100ffbae authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

fix vr

parent d5db9e5d
No related branches found
No related tags found
No related merge requests found
......@@ -876,7 +876,8 @@ RECURSIVE = YES
EXCLUDE = "components/common/cpp/include/nlohmann/json.hpp" \
"components/common/cpp/include/loguru.hpp" \
"components/common/cpp/include/ctpl_stl.h" \
"build/"
"build/" \
"ext/"
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
......
......@@ -406,7 +406,7 @@ bool ftl::gui::Camera::setVR(bool on) {
else {
vr_mode_ = false;
setChannel(Channel::Left); // reset to left channel
// todo restore camera params
// todo restore camera params<
}
return vr_mode_;
......@@ -415,7 +415,7 @@ bool ftl::gui::Camera::setVR(bool on) {
void ftl::gui::Camera::setChannel(Channel c) {
#ifdef HAVE_OPENVR
if (isVR()) {
if (isVR() && (c != Channel::Right)) {
LOG(ERROR) << "Changing channel in VR mode is not possible.";
return;
}
......
......@@ -13,49 +13,49 @@ using ftl::codecs::Channel;
/* Portaudio callback to receive audio data. */
static int pa_speaker_callback(const void *input, void *output,
unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo,
PaStreamCallbackFlags statusFlags, void *userData) {
unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo,
PaStreamCallbackFlags statusFlags, void *userData) {
auto *buffer = (ftl::audio::StereoBuffer16<2000>*)userData;
short *out = (short*)output;
auto *buffer = (ftl::audio::StereoBuffer16<2000>*)userData;
short *out = (short*)output;
buffer->readFrame(out);
return 0;
return 0;
}
#endif
Speaker::Speaker(nlohmann::json &config) : ftl::Configurable(config), buffer_(48000) {
#ifdef HAVE_PORTAUDIO
ftl::audio::pa_init();
auto err = Pa_OpenDefaultStream(
&stream_,
0,
2,
paInt16,
48000, // Sample rate
256, // Size of single frame
pa_speaker_callback,
&this->buffer_
);
if (err != paNoError) {
LOG(ERROR) << "Portaudio open stream error: " << Pa_GetErrorText(err);
active_ = false;
ftl::audio::pa_init();
auto err = Pa_OpenDefaultStream(
&stream_,
0,
2,
paInt16,
48000, // Sample rate
256, // Size of single frame
pa_speaker_callback,
&this->buffer_
);
if (err != paNoError) {
LOG(ERROR) << "Portaudio open stream error: " << Pa_GetErrorText(err);
active_ = false;
return;
} else {
active_ = true;
}
} else {
active_ = true;
}
err = Pa_StartStream(stream_);
err = Pa_StartStream(stream_);
if (err != paNoError) {
LOG(ERROR) << "Portaudio start stream error: " << Pa_GetErrorText(err);
//active_ = false;
if (err != paNoError) {
LOG(ERROR) << "Portaudio start stream error: " << Pa_GetErrorText(err);
//active_ = false;
return;
}
}
#else // No portaudio
......@@ -71,40 +71,40 @@ Speaker::Speaker(nlohmann::json &config) : ftl::Configurable(config), buffer_(48
}
Speaker::~Speaker() {
if (active_) {
active_ = false;
if (active_) {
active_ = false;
#ifdef HAVE_PORTAUDIO
auto err = Pa_StopStream(stream_);
auto err = Pa_StopStream(stream_);
if (err != paNoError) {
LOG(ERROR) << "Portaudio stop stream error: " << Pa_GetErrorText(err);
//active_ = false;
}
if (err != paNoError) {
LOG(ERROR) << "Portaudio stop stream error: " << Pa_GetErrorText(err);
//active_ = false;
}
err = Pa_CloseStream(stream_);
err = Pa_CloseStream(stream_);
if (err != paNoError) {
LOG(ERROR) << "Portaudio close stream error: " << Pa_GetErrorText(err);
}
if (err != paNoError) {
LOG(ERROR) << "Portaudio close stream error: " << Pa_GetErrorText(err);
}
#endif
}
}
#ifdef HAVE_PORTAUDIO
ftl::audio::pa_final();
ftl::audio::pa_final();
#endif
}
void Speaker::queue(int64_t ts, ftl::audio::Frame &frame) {
auto &audio = frame.get<ftl::audio::Audio>(Channel::Audio);
auto &audio = frame.get<ftl::audio::Audio>(Channel::Audio);
LOG(INFO) << "Buffer Fullness (" << ts << "): " << buffer_.size();
//LOG(INFO) << "Buffer Fullness (" << ts << "): " << buffer_.size();
buffer_.write(audio.data());
LOG(INFO) << "Audio delay: " << buffer_.delay() << "s";
//LOG(INFO) << "Audio delay: " << buffer_.delay() << "s";
}
void Speaker::setDelay(int64_t ms) {
float d = static_cast<float>(ms) / 1000.0f + extra_delay_;
if (d < 0.0f) d = 0.0f; // Clamp to 0 delay (not ideal to be exactly 0)
buffer_.setDelay(d);
float d = static_cast<float>(ms) / 1000.0f + extra_delay_;
if (d < 0.0f) d = 0.0f; // Clamp to 0 delay (not ideal to be exactly 0)
buffer_.setDelay(d);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment