Remove module from future :)
[calfbox.git] / prefetch_pipe.h
blob714e5714773e177daae1334591c0225b56e49b38
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>
27 #include <tarfile.h>
29 struct cbox_waveform;
31 enum cbox_prefetch_pipe_state
33 pps_free,
34 pps_opening,
35 pps_active,
36 pps_finished,
37 pps_error,
38 pps_closing,
39 pps_closed,
42 struct cbox_prefetch_pipe
44 enum cbox_prefetch_pipe_state state;
45 int next_free_pipe;
46 struct cbox_waveform *waveform;
47 struct cbox_tarfile_sndstream sndstream;
48 int16_t *data;
49 uint32_t buffer_size;
50 SF_INFO info;
51 SNDFILE *sndfile;
52 uint32_t file_pos_frame;
53 uint32_t file_loop_start;
54 uint32_t file_loop_end;
55 uint32_t buffer_loop_end;
56 uint32_t play_count, loop_count;
57 size_t write_ptr;
58 size_t produced;
59 size_t consumed;
60 gboolean finished;
61 gboolean returned;
64 extern void cbox_prefetch_pipe_init(struct cbox_prefetch_pipe *pipe, uint32_t buffer_size);
65 extern void cbox_prefetch_pipe_consumed(struct cbox_prefetch_pipe *pipe, uint32_t frames);
66 extern void cbox_prefetch_pipe_close(struct cbox_prefetch_pipe *pipe);
68 static inline uint32_t cbox_prefetch_pipe_get_remaining(struct cbox_prefetch_pipe *pipe)
70 assert(pipe->consumed <= pipe->produced);
71 return pipe->produced - pipe->consumed;
74 struct cbox_prefetch_stack
76 struct cbox_prefetch_pipe *pipes;
77 int pipe_count;
78 pthread_t thr_prefetch;
79 int last_free_pipe;
80 gboolean finished;
83 extern struct cbox_prefetch_stack *cbox_prefetch_stack_new(int npipes, uint32_t buffer_size);
84 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);
85 extern void cbox_prefetch_stack_push(struct cbox_prefetch_stack *stack, struct cbox_prefetch_pipe *pipe);
86 extern int cbox_prefetch_stack_get_active_pipe_count(struct cbox_prefetch_stack *stack);
87 extern void cbox_prefetch_stack_destroy(struct cbox_prefetch_stack *stack);
89 #endif