| 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 |
|
|---|
| 43 | /** Sample */
|
|---|
| 44 | typedef struct {
|
|---|
| 45 | /** Length in frames */
|
|---|
| 46 | size_t length;
|
|---|
| 47 | /** Sample data */
|
|---|
| 48 | int8_t *data;
|
|---|
| 49 | /** Loop start position in frames */
|
|---|
| 50 | size_t loop_start;
|
|---|
| 51 | /** Loop length in frames or 0 - no looping */
|
|---|
| 52 | size_t loop_len;
|
|---|
| 53 | /** Default volume (0..63) */
|
|---|
| 54 | uint8_t def_vol;
|
|---|
| 55 | } trackmod_sample_t;
|
|---|
| 56 |
|
|---|
| 57 | /** Pattern */
|
|---|
| 58 | typedef struct {
|
|---|
| 59 | /** Number of rows */
|
|---|
| 60 | size_t rows;
|
|---|
| 61 | /** Number of channels */
|
|---|
| 62 | size_t channels;
|
|---|
| 63 | /** Pattern data */
|
|---|
| 64 | uint32_t *data;
|
|---|
| 65 | } trackmod_pattern_t;
|
|---|
| 66 |
|
|---|
| 67 | /** Module. */
|
|---|
| 68 | typedef struct {
|
|---|
| 69 | /** Number of channels */
|
|---|
| 70 | size_t channels;
|
|---|
| 71 | /** Number of samples */
|
|---|
| 72 | size_t samples;
|
|---|
| 73 | /** Samples */
|
|---|
| 74 | trackmod_sample_t *sample;
|
|---|
| 75 | /** Number of patterns */
|
|---|
| 76 | size_t patterns;
|
|---|
| 77 | /** Patterns */
|
|---|
| 78 | trackmod_pattern_t *pattern;
|
|---|
| 79 | /** Order list length */
|
|---|
| 80 | size_t ord_list_len;
|
|---|
| 81 | /** Order list */
|
|---|
| 82 | size_t *ord_list;
|
|---|
| 83 | } trackmod_module_t;
|
|---|
| 84 |
|
|---|
| 85 | /** Channel playback */
|
|---|
| 86 | typedef struct {
|
|---|
| 87 | trackmod_sample_t *sample;
|
|---|
| 88 | /** Value of sample before current position */
|
|---|
| 89 | int8_t lsmp;
|
|---|
| 90 | /** Sample position (in frames) */
|
|---|
| 91 | size_t smp_pos;
|
|---|
| 92 | /** Sample position (clock ticks within frame) */
|
|---|
| 93 | size_t smp_clk;
|
|---|
| 94 | /** Period */
|
|---|
| 95 | unsigned period;
|
|---|
| 96 | /** Volume */
|
|---|
| 97 | uint8_t volume;
|
|---|
| 98 | } trackmod_chan_t;
|
|---|
| 99 |
|
|---|
| 100 | /** Module playback. */
|
|---|
| 101 | typedef struct {
|
|---|
| 102 | /** Module */
|
|---|
| 103 | trackmod_module_t *module;
|
|---|
| 104 | /** Sampling frequency */
|
|---|
| 105 | unsigned smp_freq;
|
|---|
| 106 | /** Frame size (bytes per sample * channels) */
|
|---|
| 107 | size_t frame_size;
|
|---|
| 108 |
|
|---|
| 109 | /** Current position, order list index */
|
|---|
| 110 | size_t ord_idx;
|
|---|
| 111 | /** Current position, row within pattern */
|
|---|
| 112 | size_t row;
|
|---|
| 113 | /** Current position, tick within row */
|
|---|
| 114 | unsigned tick;
|
|---|
| 115 | /** Current position, sample within tick */
|
|---|
| 116 | unsigned smp;
|
|---|
| 117 |
|
|---|
| 118 | /** Channel playback state */
|
|---|
| 119 | trackmod_chan_t *chan;
|
|---|
| 120 |
|
|---|
| 121 | /** BPM (beats per minute) */
|
|---|
| 122 | unsigned bpm;
|
|---|
| 123 | /** TPR (ticks per row) */
|
|---|
| 124 | unsigned tpr;
|
|---|
| 125 |
|
|---|
| 126 | /** If true, break from pattern at end of current row */
|
|---|
| 127 | bool pat_break;
|
|---|
| 128 | /** If @c pat_break is true, row number where to jump in next pattern */
|
|---|
| 129 | size_t pat_break_row;
|
|---|
| 130 | /** Debug mode, print messages to stdout. */
|
|---|
| 131 | bool debug;
|
|---|
| 132 | } trackmod_modplay_t;
|
|---|
| 133 |
|
|---|
| 134 | /** Pattern cell (decoded) */
|
|---|
| 135 | typedef struct {
|
|---|
| 136 | /** Sample period */
|
|---|
| 137 | unsigned period;
|
|---|
| 138 | /** Sample number */
|
|---|
| 139 | unsigned sample;
|
|---|
| 140 | /** Effect */
|
|---|
| 141 | unsigned effect;
|
|---|
| 142 | } trackmod_cell_t;
|
|---|
| 143 |
|
|---|
| 144 | #endif
|
|---|
| 145 |
|
|---|
| 146 | /** @}
|
|---|
| 147 | */
|
|---|