Ejemplo n.º 1
0
Archivo: main.cpp Proyecto: CCJY/coliru
int main()
{
    std::size_t M = 5 ;

    // http://www.boost.org/doc/libs/1_57_0/doc/html/circular_buffer.html
    boost::circular_buffer< std::vector<double> > ring_buffer(M) ; // keeps the last 'M' vectors

    double v = 0.1 ;
    std::size_t n = 2 ;
    for( std::size_t i = 0 ; i < M*2 ; ++i )
    {
        std::vector<double> next( n, v ) ;
        double incr = 0 ;
        for( double& d : next ) { d += incr ; incr += 0.1 ; }
        ring_buffer.push_back( std::move(next) ) ;

        for( const auto& vec : ring_buffer )
        {
            std::cout << "[ " ;
            for( double d : vec ) std::cout << d << ' ' ;
            std::cout << "] " ;
        }
        std::cout << '\n' ;

        if( i%2 ) ++n ;
        v += 0.1 ;
    }
}
Ejemplo n.º 2
0
int main(int argc, char const *argv[])
{
    fa_set_log_tool();
    fa_with_faudio() {

        BUFFER = ring_buffer((8L * 44100L * BUFFER_SIZE_MILLIS) / 1000L);

        // fa_signal_t left = fa_multiply(fa_signal_play_stream(BUFFER), constant(0.8));
        fa_signal_t left = fa_multiply(fa_signal_random(), fa_signal_constant(0.0));
        fa_signal_t right = fa_multiply(fa_signal_random(), fa_signal_constant(0.0));

        fa_with_session_(session) {
            fa_with_default_devices(input, output, session) {
                fa_audio_set_parameter(fa_string("sample-rate"), fa_f64(44100), session);
                fa_audio_stream_t stream;

                if (fa_check(stream = fa_audio_open_output(input, output, list(left, right)))) {
                    fa_error_log(stream, NULL);
                } else {
                    request_audio();
                    // TODO some way to delay or toggle DSP thread reading from stream (give it a rate argument?)
                    fa_thread_sleep(300 * 1000);
                }
            }
        }
    }