Skip to content

Commit

Permalink
sdl: add transport info
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Nov 23, 2024
1 parent a927a91 commit aa77539
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/ossia/audio/sdl_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class sdl_protocol final : public audio_engine

auto& self = *static_cast<sdl_protocol*>(userData);
self.tick_start();
if(!self.m_start)
self.m_start = std::chrono::steady_clock::now();

auto audio_out = reinterpret_cast<float*>(data);
const int out_chan = self.m_obtained.channels;
Expand Down Expand Up @@ -100,21 +102,30 @@ class sdl_protocol final : public audio_engine

// if one day there's input... samples[j++] / 32768.;

// TODO time in seconds !
ossia::audio_tick_state ts{nullptr, float_output, 0,
out_chan, (uint64_t)frames, 0};
auto now = std::chrono::steady_clock::now();
auto nsecs
= std::chrono::duration_cast<std::chrono::nanoseconds>(now - *self.m_start)
.count()
/ 1e9;

ossia::audio_tick_state ts{
nullptr, float_output, 0, out_chan, (uint64_t)frames,
nsecs, self.m_total_frames};
self.audio_tick(ts);

for(int j = 0; j < frames; j++)
for(int c = 0; c < out_chan; c++)
*audio_out++ = float_output[c][j];

self.tick_end();
self.m_total_frames += frames;
}
}

SDL_AudioDeviceID m_deviceId{};
SDL_AudioSpec m_desired, m_obtained;
uint64_t m_total_frames{};
std::optional<std::chrono::steady_clock::time_point> m_start;
};
}

Expand Down

0 comments on commit aa77539

Please sign in to comment.