Got seek_ppqn/seek_samples the other way around :-)
[calfbox.git] / prefetch_pipe.h
blob0fc0d0b8c7de74dfd505d3033d990a47920d2a0c
1 /*
2 Calf Box, an open source musical instrument.
3 Copyright (C) 2010-2013 Krzysztof Foltman
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CBOX_PREFETCH_PIPE_H
20 #define CBOX_PREFETCH_PIPE_H
22 #include <assert.h>
23 #include <glib.h>
24 #include <pthread.h>
25 #include <sndfile.h>
26 #include <stdint.h>
28 struct cbox_waveform;
30 enum cbox_prefetch_pipe_state
32 pps_free,
33 pps_opening,
34 pps_active,
35 pps_finished,
36 pps_error,
37 pps_closing,
38 pps_closed,
41 struct cbox_prefetch_pipe
43 enum cbox_prefetch_pipe_state state;
44 int next_free_pipe;
45 struct cbox_waveform *waveform;
46 int16_t *data;
47 uint32_t buffer_size;
48 SF_INFO info;
49 SNDFILE *sndfile;
50 uint32_t file_pos_frame;
51 uint32_t file_loop_start;
52 uint32_t file_loop_end;
53 uint32_t buffer_loop_end;
54 uint32_t play_count, loop_count;
55 size_t write_ptr;
56 size_t produced;
57 size_t consumed;
58 gboolean finished;
59 gboolean returned;
62 extern void cbox_prefetch_pipe_init(struct cbox_prefetch_pipe *pipe, uint32_t buffer_size);
63 extern void cbox_prefetch_pipe_consumed(struct cbox_prefetch_pipe *pipe, uint32_t frames);
64 extern void cbox_prefetch_pipe_close(struct cbox_prefetch_pipe *pipe);
66 static inline uint32_t cbox_prefetch_pipe_get_remaining(struct cbox_prefetch_pipe *pipe)
68 assert(pipe->consumed <= pipe->produced);
69 return pipe->produced - pipe->consumed;
72 struct cbox_prefetch_stack
74 struct cbox_prefetch_pipe *pipes;
75 int pipe_count;
76 pthread_t thr_prefetch;
77 int last_free_pipe;
78 gboolean finished;
81 extern struct cbox_prefetch_stack *cbox_prefetch_stack_new(int npipes, uint32_t buffer_size);
82 extern struct cbox_prefetch_pipe *cbox_prefetch_stack_pop(struct cbox_prefetch_stack *stack, struct cbox_waveform *waveform, uint32_t file_loop_start, uint32_t file_loop_end, uint32_t loop_count);
83 extern void cbox_prefetch_stack_push(struct cbox_prefetch_stack *stack, struct cbox_prefetch_pipe *pipe);
84 extern int cbox_prefetch_stack_get_active_pipe_count(struct cbox_prefetch_stack *stack);
85 extern void cbox_prefetch_stack_destroy(struct cbox_prefetch_stack *stack);
87 #endif