Skip to content

Commit

Permalink
refactor(examples/volume): use new as / write overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Oct 13, 2024
1 parent 9e4f288 commit ac2c2a1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/volume/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ int main()

// pipewire uses cubic volumes! (that's why we use std::cbrt, and std::pow)

auto channels = prop->value().as<std::vector<void *>>();
auto cubic_volume = std::powf(volume / 100, 3);
auto channels = prop->value().as<std::vector<float>>();
auto cubic_volumes = channels | std::views::transform([volume](auto &&) {
return std::powf(volume / 100, 3);
});

*reinterpret_cast<float *>(channels[0]) = cubic_volume;
*reinterpret_cast<float *>(channels[1]) = cubic_volume;
std::cout << std::format("Updating volume from {}% to {}%", std::cbrt(channels[0]) * 100, volume) << std::endl;

prop->value().write<std::vector<float>>({cubic_volumes.begin(), cubic_volumes.end()});
device.set_param(pod_id, 0, pod);
core->update();

Expand Down

0 comments on commit ac2c2a1

Please sign in to comment.