Replace manual option handling by use of glib
[lcid-xwax.git] / track.h
blob6eff0ff776b9a250b92a6ac0efe82a6929b40d3e
1 /*
2 * Copyright (C) 2008 Mark Hills <mark@pogo.org.uk>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License version 2 for more details.
13 * You should have received a copy of the GNU General Public License
14 * version 2 along with this program; if not, write to the Free
15 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1301, USA.
20 #ifndef TRACK_H
21 #define TRACK_H
23 #include <pthread.h>
24 #include <sys/poll.h>
25 #include <sys/types.h>
26 #include <glib.h>
28 #include "rig.h"
30 struct cached_file;
31 struct cache_read;
33 #define TRACK_CHANNELS 2
34 #define TRACK_RATE 44100
36 #define TRACK_STATUS_UNKNOWN -1
37 #define TRACK_STATUS_VALID 0
38 #define TRACK_STATUS_IMPORTING 1
40 /*#define TRACK_MAX_BLOCKS 64*/
41 #define TRACK_BLOCK_SAMPLES (2048 * 1024)
42 #define TRACK_PPM_RES 64
43 #define TRACK_OVERVIEW_RES 2048
45 #define BYTES_PER_SAMPLE (TRACK_CHANNELS * sizeof(signed short)) /* bytes per sample (all channels) */
47 //pcm elements a track block holds
48 #define TRACK_BLOCK_PCM_LENGTH (TRACK_BLOCK_SAMPLES * TRACK_CHANNELS)
49 #define BYTES_PER_PCM_BLOCK (TRACK_BLOCK_SAMPLES * BYTES_PER_SAMPLE)
50 typedef signed short TRACK_PCM_DATA_TYPE;
51 #define TRACK_PCM_DATA_SIZE sizeof(TRACK_PCM_DATA_TYPE)
53 #define TRACK_PPM_LENGTH TRACK_BLOCK_SAMPLES / TRACK_PPM_RES
54 #define TRACK_OVERVIEW_LENGTH TRACK_BLOCK_SAMPLES / TRACK_OVERVIEW_RES
56 struct track_block_t {
57 TRACK_PCM_DATA_TYPE pcm[TRACK_BLOCK_PCM_LENGTH];
58 unsigned char ppm[TRACK_PPM_LENGTH],
59 overview[TRACK_OVERVIEW_LENGTH];
62 struct track_t {
63 int status, fd, eof;
64 pid_t pid;
65 struct pollfd *pe;
66 pthread_mutex_t mx;
67 struct rig_t *rig;
69 /* pointers to external data */
71 const char *importer, /* path to import script */
72 *artist, *title, *name;
74 size_t bytes; /* loaded in */
75 guint /*length, track length in samples */
76 blocks; /* number of blocks allocated */
77 GPtrArray *block;
79 /* Current value of audio meters when loading */
81 unsigned short ppm;
82 unsigned int overview;
84 struct cached_track* cache;
85 struct cache_read* cache_read;
88 void track_init(struct track_t *tr, const char *importer);
89 int track_clear(struct track_t *tr);
90 int track_import(struct track_t *tr, const char *path);
91 int track_pollfd(struct track_t *tr, struct pollfd *pe);
92 int track_handle(struct track_t *tr);
93 int track_abort(struct track_t *tr);
94 int track_wait(struct track_t *tr);
95 guint track_get_sample_count(const struct track_t* tr);
97 guint track_block_get_used_bytes(const struct track_t* tr, const guint index);
99 /* Macro functions, to force the code inline */
101 #define track_get_block(tr, i) \
102 ((struct track_block_t*)g_ptr_array_index((tr)->block, i))
104 #define track_get_ppm(tr, s) \
105 track_get_block(tr, (s) / TRACK_BLOCK_SAMPLES) \
106 ->ppm[((s) % TRACK_BLOCK_SAMPLES) / TRACK_PPM_RES]
108 #define track_get_overview(tr, s) \
109 track_get_block(tr, (s) / TRACK_BLOCK_SAMPLES) \
110 ->overview[((s) % TRACK_BLOCK_SAMPLES) / TRACK_OVERVIEW_RES]
112 /* Return a pointer to (not value of) the sample data for each channel */
114 #define track_get_sample(tr, s) \
115 &track_get_block(tr, (s) / TRACK_BLOCK_SAMPLES)->pcm[((s) % TRACK_BLOCK_SAMPLES) \
116 * TRACK_CHANNELS]
118 #endif