Skip to content
Open
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2a9265d
WIP LFO implementation
rothmichaels Nov 19, 2024
39acaff
Refactor LFO example and get to compile
rothmichaels Dec 19, 2024
f4fe2bd
Add 0-wrapping_unsafe_apis audio example
rothmichaels Dec 19, 2024
aec61bc
Finish LFO example
rothmichaels Dec 20, 2024
fbfecdb
Uncomment unit symbols
rothmichaels Dec 20, 2024
8176bdc
Include <algorithm> in 1-lfo example
rothmichaels Dec 20, 2024
50a323b
Try value_cast<float> to fix int->float conversion warning
rothmichaels Dec 20, 2024
b0a6ac9
Fix reuse of sample_rate name for analysis
rothmichaels Dec 20, 2024
9629004
Try adding more value_cast to fix analysis errors
rothmichaels Dec 20, 2024
8be556f
Rename 1-lfo -> 1-oscillator
rothmichaels Dec 20, 2024
2e0a824
Update example/audio/third_party_audio_api.h
rothmichaels Dec 20, 2024
9fbe556
Update example/audio/wrapped_third_party_audio_api.h
rothmichaels Dec 20, 2024
03775fd
Audio examples 1-oscillator PR feedback
rothmichaels Jan 8, 2025
b790489
Merge remote-tracking branch 'upstream/master' into feature/audio-exa…
rothmichaels Jan 8, 2025
e5a5948
Update audio example for dimensionless changes
rothmichaels Jan 9, 2025
7091c1e
Remove unused header
rothmichaels Jan 9, 2025
8223e15
Merge remote-tracking branch 'origin/feature/audio-examples' into fea…
rothmichaels Jan 9, 2025
607d1ea
Add missing call to update_step in 1-oscillator example
rothmichaels Jan 9, 2025
acf4d8d
1-oscillator example combine set_frequency and set_period into one ov…
rothmichaels Jan 9, 2025
52f7b88
Merge remote-tracking branch 'upstream/master' into feature/audio-exa…
rothmichaels May 6, 2025
afacfb2
Merge remote-tracking branch 'upstream/master' into feature/audio-exa…
rothmichaels Sep 18, 2025
0955170
fix: remove deprecated mp-units/format.h includes from audio examples
rothmichaels Sep 18, 2025
f58981d
Merge remote-tracking branch 'upstream/master' into feature/audio-exa…
rothmichaels Nov 11, 2025
936a414
Merge branch 'master' into feature/audio-examples
mpusz Dec 21, 2025
947fbee
Merge remote-tracking branch 'upstream/master' into feature/audio-exa…
rothmichaels Dec 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions example/audio/1-oscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
import std;
#else
#include <algorithm>
#include <cassert>
#include <iostream>
#include <ranges>
#include <vector>
#endif
#ifdef MP_UNITS_MODULES
import mp_units;
#else
#include <mp-units/format.h>
#include <mp-units/math.h>
#include <mp-units/systems/angular.h>
#include <mp-units/systems/isq.h>
#include <mp-units/systems/si.h>
Expand Down Expand Up @@ -64,7 +66,7 @@ class sine_wave_osc {

void set_period(QuantityOf<isq::time> auto period)
{
m_frequency = 1.f / value_cast<float>(period);
m_frequency = inverse<si::hertz>(period);
std::cout << MP_UNITS_STD_FMT::format("Setting period to {} (i.e. frequency to {})\n", period, m_frequency);
}

Expand Down Expand Up @@ -120,9 +122,10 @@ int main()
// of audio samples. In this example we will create a buffer with
// duration equal to 2 measures of 4/4 music (i.e. 2 whole notes at
// the current tempo):
const auto beats = 2 * audio::whole_note;
const auto buffer_duration = value_cast<float>(beats) / context.current_tempo;
const auto buffer_size = (buffer_duration * context.current_sample_rate).in(audio::sample);
const quantity beats = 2 * audio::whole_note;
const quantity buffer_duration = value_cast<float>(beats) / context.current_tempo;
const quantity buffer_size =
quantity_cast<audio::sample_count>((buffer_duration * context.current_sample_rate).in(one));
Comment on lines +130 to +131

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a quantity_cast required here? I assume that the implicit conversion did not compile? Did you try an explicit conversion?

Suggested change
const quantity buffer_size =
quantity_cast<audio::sample_count>((buffer_duration * context.current_sample_rate).in(one));
const quantity buffer_size =
audio::sample_count((buffer_duration * context.current_sample_rate).in(one));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't audio::sample a good unit here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, audio::sample is a good unit here. This is what I had before the changes to dimensionless quantities:

const quantity buffer_size = (buffer_duration * context.current_sample_rate).in(audio::sample);

Maybe I didn't know the best way to do this after the dimensionless changes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the previous audio example in the paper (https://godbolt.org/z/z7sPqe66e) and improved inverse(). Maybe this will give you some ideas on how to refactor this.


std::cout << MP_UNITS_STD_FMT::format("\nCreating buffer with size:\n\t{}\n\t{}\n\t{}\n\n", beats, buffer_duration,
buffer_size);
Expand All @@ -134,10 +137,9 @@ int main()
std::cout << MP_UNITS_STD_FMT::format("Filling buffer with values from LFO @ {}", sin_gen.get_frequency());
std::generate(begin(buffer_1), end(buffer_1), sin_gen);

assert(buffer_1.size() > 0u);
std::cout << MP_UNITS_STD_FMT::format("\nLFO Values:\n[{}", buffer_1[0u]);
for (std::size_t i = 1u; i < buffer_1.size(); ++i) {
std::cout << MP_UNITS_STD_FMT::format(", {}", buffer_1[i]);
for (const auto sampleValue : std::ranges::subrange(begin(buffer_1) + 1, end(buffer_1))) {
std::cout << MP_UNITS_STD_FMT::format(", {}", sampleValue);
}
std::cout << "]\n\n";

Expand Down