Add audio::literals to represent durations like 100_ms or 0.5_s
This commit is contained in:
parent
20fbb9c5ac
commit
748035c514
1 changed files with 31 additions and 0 deletions
31
libs/audio/include/psemek/audio/literals.hpp
Normal file
31
libs/audio/include/psemek/audio/literals.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/audio/duration.hpp>
|
||||
#include <psemek/audio/constants.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace psemek::audio::literals
|
||||
{
|
||||
|
||||
duration operator ""_s (unsigned long long value)
|
||||
{
|
||||
return duration::from_frames(value * frequency);
|
||||
}
|
||||
|
||||
duration operator ""_ms (unsigned long long value)
|
||||
{
|
||||
return duration::from_frames((value * frequency) / 1000);
|
||||
}
|
||||
|
||||
duration operator ""_s (long double value)
|
||||
{
|
||||
return duration::from_frames(std::round(value * frequency));
|
||||
}
|
||||
|
||||
duration operator ""_ms (long double value)
|
||||
{
|
||||
return duration::from_frames(std::round(value * frequency / 1000.0));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue