-
Notifications
You must be signed in to change notification settings - Fork 0
/
track.h
119 lines (90 loc) · 3.15 KB
/
track.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (C) 2018 Mark Hills <mark@xwax.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2, as published by the Free Software Foundation.
*
* 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 version 2 for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#ifndef TRACK_H
#define TRACK_H
#include <stdbool.h>
#include <sys/poll.h>
#include <sys/types.h>
#include "list.h"
#define TRACK_CHANNELS 2
#define TRACK_MAX_BLOCKS 64
#define TRACK_BLOCK_SAMPLES (2048 * 1024)
#define TRACK_PPM_RES 64
#define TRACK_OVERVIEW_RES 2048
struct track_block {
signed short pcm[TRACK_BLOCK_SAMPLES * TRACK_CHANNELS];
unsigned char ppm[TRACK_BLOCK_SAMPLES / TRACK_PPM_RES],
overview[TRACK_BLOCK_SAMPLES / TRACK_OVERVIEW_RES];
};
struct track {
struct list tracks;
unsigned int refcount;
int rate;
/* pointers to external data */
const char *importer, *path;
size_t bytes; /* loaded in */
unsigned int length, /* track length in samples */
blocks; /* number of blocks allocated */
struct track_block *block[TRACK_MAX_BLOCKS];
/* State of audio import */
struct list rig;
pid_t pid;
int fd;
struct pollfd *pe;
bool terminated;
/* Current value of audio meters when loading */
unsigned short ppm;
unsigned int overview;
};
void track_use_mlock(void);
/* Tracks are dynamically allocated and reference counted */
struct track* track_acquire_by_import(const char *importer, const char *path);
struct track* track_acquire_empty(void);
void track_acquire(struct track *t);
void track_release(struct track *t);
/* Functions used by the rig and main thread */
void track_pollfd(struct track *tr, struct pollfd *pe);
void track_handle(struct track *tr);
/* Return true if the track importer is running, otherwise false */
static inline bool track_is_importing(struct track *tr)
{
return tr->pid != 0;
}
/* Return the pseudo-PPM meter value for the given sample */
static inline unsigned char track_get_ppm(struct track *tr, int s)
{
struct track_block *b;
b = tr->block[s / TRACK_BLOCK_SAMPLES];
return b->ppm[(s % TRACK_BLOCK_SAMPLES) / TRACK_PPM_RES];
}
/* Return the overview meter value for the given sample */
static inline unsigned char track_get_overview(struct track *tr, int s)
{
struct track_block *b;
b = tr->block[s / TRACK_BLOCK_SAMPLES];
return b->overview[(s % TRACK_BLOCK_SAMPLES) / TRACK_OVERVIEW_RES];
}
/* Return a pointer to (not value of) the sample data for each channel */
static inline signed short* track_get_sample(struct track *tr, int s)
{
struct track_block *b;
b = tr->block[s / TRACK_BLOCK_SAMPLES];
return &b->pcm[(s % TRACK_BLOCK_SAMPLES) * TRACK_CHANNELS];
}
#endif