mirror of
https://github.com/danog/system-bus-radio.git
synced 2024-12-04 17:27:49 +01:00
boost song
This commit is contained in:
parent
9b4a17c757
commit
722414ef44
42
main.cpp
42
main.cpp
@ -8,6 +8,33 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <mutex>
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
|
std::mutex m ;
|
||||||
|
std::condition_variable cv ;
|
||||||
|
std::chrono::high_resolution_clock::time_point mid ;
|
||||||
|
std::chrono::high_resolution_clock::time_point reset ;
|
||||||
|
|
||||||
|
|
||||||
|
void boost_song()
|
||||||
|
{
|
||||||
|
using namespace std::chrono ;
|
||||||
|
|
||||||
|
while( true )
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lk{m} ;
|
||||||
|
cv.wait( lk ) ;
|
||||||
|
|
||||||
|
std::atomic<unsigned> x{0} ;
|
||||||
|
while( high_resolution_clock::now() < mid )
|
||||||
|
{
|
||||||
|
++x ;
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_until( reset ) ;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void square_am_signal(float time, float frequency)
|
void square_am_signal(float time, float frequency)
|
||||||
{
|
{
|
||||||
@ -27,13 +54,11 @@ void square_am_signal(float time, float frequency)
|
|||||||
|
|
||||||
while (high_resolution_clock::now() < end)
|
while (high_resolution_clock::now() < end)
|
||||||
{
|
{
|
||||||
auto mid = start + period / 2 ;
|
mid = start + period / 2 ;
|
||||||
auto reset = start + period ;
|
auto reset = start + period ;
|
||||||
while (high_resolution_clock::now() < mid)
|
|
||||||
{
|
|
||||||
std::atomic<unsigned> x{0} ;
|
std::atomic<unsigned> x{0} ;
|
||||||
++x ;
|
|
||||||
}
|
cv.notify_all() ;
|
||||||
std::this_thread::sleep_until( reset ) ;
|
std::this_thread::sleep_until( reset ) ;
|
||||||
start = reset;
|
start = reset;
|
||||||
}
|
}
|
||||||
@ -41,6 +66,13 @@ void square_am_signal(float time, float frequency)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
for ( unsigned i = 0 ; i < 8 ; ++i )
|
||||||
|
{
|
||||||
|
std::thread t( boost_song ) ;
|
||||||
|
t.detach() ;
|
||||||
|
}
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
square_am_signal(0.400, 2673);
|
square_am_signal(0.400, 2673);
|
||||||
|
Loading…
Reference in New Issue
Block a user