Skip to content

Commit

Permalink
pulse: add get_time_base()
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Jun 29, 2024
1 parent 823ec7b commit e08cede
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/pulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ bool PulseReader::init()
pa = pa_simple_new(NULL, "wf-recorder3", PA_STREAM_RECORD, params.audio_source,
"wf-recorder3", &sample_spec, &map, &attr, &perr);

struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
this->monotonic_clock_start = ts.tv_sec * 1000000ll + ts.tv_nsec / 1000ll;

int error = 0;
uint64_t latency_audio = pa_simple_get_latency(pa, &error);
if (latency_audio != (pa_usec_t)-1) {
monotonic_clock_start -= latency_audio;
}

if (!pa)
{
std::cerr << "Failed to connect to PulseAudio: " << pa_strerror(perr)
Expand Down Expand Up @@ -70,3 +80,8 @@ PulseReader::~PulseReader()
if (pa)
read_thread.join();
}

uint64_t PulseReader::get_time_base() const
{
return monotonic_clock_start;
}
2 changes: 2 additions & 0 deletions src/pulse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ class PulseReader : public AudioReader

bool loop();
std::thread read_thread;
uint64_t monotonic_clock_start = 0;

public:
~PulseReader();

bool init() override;
void start() override;
uint64_t get_time_base() const override;
};

#endif /* end of include guard: PULSE_HPP */

0 comments on commit e08cede

Please sign in to comment.