-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprefetch_pipe.h
95 lines (81 loc) · 2.88 KB
/
prefetch_pipe.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
Calf Box, an open source musical instrument.
Copyright (C) 2010-2013 Krzysztof Foltman
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CBOX_PREFETCH_PIPE_H
#define CBOX_PREFETCH_PIPE_H
#include <assert.h>
#include <glib.h>
#include <pthread.h>
#include <sndfile.h>
#include <stdint.h>
#include "tarfile.h"
#define PIPE_MIN_PREFETCH_SIZE_FRAMES 2048
struct cbox_waveform;
enum cbox_prefetch_pipe_state
{
pps_free,
pps_opening,
pps_active,
pps_finished,
pps_error,
pps_closing,
pps_closed,
};
struct cbox_prefetch_pipe
{
union {
volatile enum cbox_prefetch_pipe_state state;
uint64_t atomic1;
};
struct cbox_waveform *waveform;
struct cbox_tarfile_sndstream sndstream;
int16_t *data;
uint32_t buffer_size;
uint32_t min_buffer_frames;
SF_INFO info;
SNDFILE *sndfile;
uint32_t file_pos_frame;
uint32_t file_loop_start;
uint32_t file_loop_end;
uint32_t buffer_loop_end;
uint32_t play_count, loop_count;
size_t write_ptr;
size_t produced;
size_t consumed;
gboolean finished;
gboolean returned;
};
extern void cbox_prefetch_pipe_init(struct cbox_prefetch_pipe *pipe, uint32_t buffer_size, uint32_t min_buffer_frames);
extern void cbox_prefetch_pipe_consumed(struct cbox_prefetch_pipe *pipe, uint32_t frames);
extern void cbox_prefetch_pipe_close(struct cbox_prefetch_pipe *pipe);
static inline uint32_t cbox_prefetch_pipe_get_remaining(struct cbox_prefetch_pipe *pipe)
{
assert(pipe->consumed <= pipe->produced);
return pipe->produced - pipe->consumed;
}
struct cbox_prefetch_stack
{
struct cbox_prefetch_pipe *pipes;
int *next_free_pipe;
int pipe_count;
pthread_t thr_prefetch;
int last_free_pipe;
gboolean finished;
};
extern struct cbox_prefetch_stack *cbox_prefetch_stack_new(int npipes, uint32_t buffer_size, uint32_t min_buffer_frames);
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);
extern void cbox_prefetch_stack_push(struct cbox_prefetch_stack *stack, struct cbox_prefetch_pipe *pipe);
extern int cbox_prefetch_stack_get_active_pipe_count(struct cbox_prefetch_stack *stack);
extern void cbox_prefetch_stack_destroy(struct cbox_prefetch_stack *stack);
#endif