1 /*****************************************************************************
2 * cyclic_buffer.h cyclic buffer helper class for vlc's audio visualizations
3 *****************************************************************************
4 * Copyright © 2012 Vovoid Media Technologies
6 * Authors: Jonatan "jaw" Wallmander
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifndef CYCLIC_BUFFER_H
24 #define CYCLIC_BUFFER_H
30 float data
[512]; // data holder
31 mtime_t pts
; // machine time when this is to be played
34 pts
= 0; // max_int 64-bit
38 #define CYCLIC_BUFFER_SIZE 128
39 class cyclic_block_queue
41 block_holder cycl_buffer
[CYCLIC_BUFFER_SIZE
];
51 block_holder
* consume()
53 mtime_t cur_machine_time
= mdate();
56 (cycl_buffer
[consumer_pos
].pts
< cur_machine_time
)
58 (steps
++ < CYCLIC_BUFFER_SIZE
)
62 if (consumer_pos
== CYCLIC_BUFFER_SIZE
)
67 return &cycl_buffer
[consumer_pos
];
70 block_holder
* get_insertion_object()
73 if ( insertion_pos
== CYCLIC_BUFFER_SIZE
)
77 return &cycl_buffer
[insertion_pos
];
82 for (size_t i
= 0; i
< CYCLIC_BUFFER_SIZE
; i
++)
84 cycl_buffer
[i
].pts
= 0;
90 #undef CYCLIC_BUFFER_SIZE
92 #endif // CYCLIC_BUFFER_H