source: mainline/uspace/lib/trackmod/types/trackmod.h

Last change on this file was 7c3fb9b, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix block comment formatting (ccheck).

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * Copyright (c) 2014 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup trackmod
30 * @{
31 */
32/**
33 * @file Tracker module handling library types.
34 */
35
36#ifndef TYPES_TRACKMOD_H
37#define TYPES_TRACKMOD_H
38
39#include <stdbool.h>
40#include <stddef.h>
41#include <stdint.h>
42
43enum {
44 max_key = 96,
45 keyoff_note = 97
46};
47
48typedef enum {
49 /** No loop */
50 tl_no_loop,
51 /** Forward loop */
52 tl_forward_loop,
53 /** Pingpong loop */
54 tl_pingpong_loop
55} trackmod_looptype_t;
56
57/** Sample */
58typedef struct {
59 /** Length in frames */
60 size_t length;
61 /** Bytes per sample */
62 size_t bytes_smp;
63 /** Sample data */
64 void *data;
65 /** Loop type */
66 trackmod_looptype_t loop_type;
67 /** Loop start position in frames */
68 size_t loop_start;
69 /** Loop length in frames (> 0) */
70 size_t loop_len;
71 /** Default volume (0..63) */
72 uint8_t def_vol;
73 /** Relative note */
74 int rel_note;
75 /** Finetune value (-8..7) in 1/8 semitones */
76 int finetune;
77} trackmod_sample_t;
78
79/** Instrument */
80typedef struct {
81 /** Number of samples */
82 size_t samples;
83 /** Samples */
84 trackmod_sample_t *sample;
85 /** Sample index for each key */
86 int key_smp[max_key];
87} trackmod_instr_t;
88
89/** Pattern cell */
90typedef struct {
91 /** Note */
92 unsigned note;
93 /** Sample period */
94 unsigned period;
95 /** Instrument number */
96 unsigned instr;
97 /** Volume */
98 uint8_t volume;
99 /** Effect */
100 uint16_t effect;
101} trackmod_cell_t;
102
103/** Pattern */
104typedef struct {
105 /** Number of rows */
106 size_t rows;
107 /** Number of channels */
108 size_t channels;
109 /** Pattern data */
110 trackmod_cell_t *data;
111} trackmod_pattern_t;
112
113/** Module. */
114typedef struct {
115 /** Number of channels */
116 size_t channels;
117 /** Number of samples */
118 size_t instrs;
119 /** Instruments */
120 trackmod_instr_t *instr;
121 /** Number of patterns */
122 size_t patterns;
123 /** Patterns */
124 trackmod_pattern_t *pattern;
125 /** Order list length */
126 size_t ord_list_len;
127 /** Order list */
128 size_t *ord_list;
129 /** Restart pos */
130 size_t restart_pos;
131 /** Default BPM */
132 unsigned def_bpm;
133 /** Default TPR */
134 unsigned def_tpr;
135} trackmod_module_t;
136
137/** Channel playback */
138typedef struct {
139 trackmod_sample_t *sample;
140 /** Value of sample before current position */
141 int8_t lsmp;
142 /** Sample position (in frames) */
143 size_t smp_pos;
144 /** Sample position (clock ticks within frame) */
145 size_t smp_clk;
146 /** Current period */
147 unsigned period;
148 /** Period after note was processed, zero if no note */
149 unsigned period_new;
150 /** Volume */
151 uint8_t volume;
152 /** Volume slide amount */
153 int vol_slide;
154 /** Portamento amount (positive for tone and up portamento,
155 * negative for down portamento.
156 */
157 int portamento;
158 /** Tone portamento target period. */
159 unsigned period_tgt;
160} trackmod_chan_t;
161
162/** Module playback. */
163typedef struct {
164 /** Module */
165 trackmod_module_t *module;
166 /** Sampling frequency */
167 unsigned smp_freq;
168 /** Frame size (bytes per sample * channels) */
169 size_t frame_size;
170
171 /** Current position, order list index */
172 size_t ord_idx;
173 /** Current position, row within pattern */
174 size_t row;
175 /** Current position, tick within row */
176 unsigned tick;
177 /** Current position, sample within tick */
178 unsigned smp;
179
180 /** Channel playback state */
181 trackmod_chan_t *chan;
182
183 /** BPM (beats per minute) */
184 unsigned bpm;
185 /** TPR (ticks per row) */
186 unsigned tpr;
187
188 /** If true, break from pattern at end of current row */
189 bool pat_break;
190 /** If @c pat_break is true, row number where to jump in next pattern */
191 size_t pat_break_row;
192 /** Debug mode, print messages to stdout. */
193 bool debug;
194} trackmod_modplay_t;
195
196#endif
197
198/** @}
199 */
Note: See TracBrowser for help on using the repository browser.