demux: mkv: ProcessNavAction: negate if to prevent nesting
[vlc.git] / modules / visualization / cyclic_buffer.h
blob4fab7fd2c03881c279a0e2f1ee4b49c60cdcc690
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
27 class block_holder
29 public:
30 float data[512]; // data holder
31 vlc_tick_t pts; // machine time when this is to be played
32 block_holder()
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];
42 size_t consumer_pos;
43 size_t insertion_pos;
44 public:
45 cyclic_block_queue()
47 consumer_pos = 0;
48 insertion_pos = 0;
51 block_holder* consume()
53 vlc_tick_t cur_machine_time = vlc_tick_now();
54 size_t steps = 0;
55 while (
56 (cycl_buffer[consumer_pos].pts < cur_machine_time)
58 (steps++ < CYCLIC_BUFFER_SIZE)
61 consumer_pos++;
62 if (consumer_pos == CYCLIC_BUFFER_SIZE)
64 consumer_pos = 0;
67 return &cycl_buffer[consumer_pos];
70 block_holder* get_insertion_object()
72 insertion_pos++;
73 if ( insertion_pos == CYCLIC_BUFFER_SIZE )
75 insertion_pos = 0;
77 return &cycl_buffer[insertion_pos];
80 void reset()
82 for (size_t i = 0; i < CYCLIC_BUFFER_SIZE; i++)
84 cycl_buffer[i].pts = 0;
85 consumer_pos = 0;
86 insertion_pos = 0;
90 #undef CYCLIC_BUFFER_SIZE
92 #endif // CYCLIC_BUFFER_H