diff options
Diffstat (limited to 'apps/codecs/libgme/track_filter.h')
-rw-r--r-- | apps/codecs/libgme/track_filter.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/apps/codecs/libgme/track_filter.h b/apps/codecs/libgme/track_filter.h new file mode 100644 index 0000000000..35049b91bb --- /dev/null +++ b/apps/codecs/libgme/track_filter.h | |||
@@ -0,0 +1,90 @@ | |||
1 | // Removes silence from beginning of track, fades end of track. Also looks ahead | ||
2 | // for excessive silence, and if found, ends track. | ||
3 | |||
4 | // Game_Music_Emu 0.6-pre | ||
5 | #ifndef TRACK_FILTER_H | ||
6 | #define TRACK_FILTER_H | ||
7 | |||
8 | #include "blargg_common.h" | ||
9 | |||
10 | typedef short sample_t; | ||
11 | typedef int sample_count_t; | ||
12 | |||
13 | enum { indefinite_count = INT_MAX/2 + 1 }; | ||
14 | enum { buf_size = 2048 }; | ||
15 | |||
16 | struct setup_t { | ||
17 | sample_count_t max_initial; // maximum silence to strip from beginning of track | ||
18 | sample_count_t max_silence; // maximum silence in middle of track without it ending | ||
19 | int lookahead; // internal speed when looking ahead for silence (2=200% etc.) | ||
20 | }; | ||
21 | |||
22 | struct Track_Filter { | ||
23 | void* emu_; | ||
24 | struct setup_t setup_; | ||
25 | const char* emu_error; | ||
26 | bool silence_ignored_; | ||
27 | |||
28 | // Timing | ||
29 | int out_time; // number of samples played since start of track | ||
30 | int emu_time; // number of samples emulator has generated since start of track | ||
31 | int emu_track_ended_; // emulator has reached end of track | ||
32 | volatile int track_ended_; | ||
33 | |||
34 | // Fading | ||
35 | int fade_start; | ||
36 | int fade_step; | ||
37 | |||
38 | // Silence detection | ||
39 | int silence_time; // absolute number of samples where most recent silence began | ||
40 | int silence_count; // number of samples of silence to play before using buf | ||
41 | int buf_remain; // number of samples left in silence buffer | ||
42 | sample_t buf [buf_size]; | ||
43 | }; | ||
44 | |||
45 | // Initializes filter. Must be done once before using object. | ||
46 | blargg_err_t track_init( struct Track_Filter* this, void* ); | ||
47 | void track_create( struct Track_Filter* this ); | ||
48 | |||
49 | // Gets/sets setup | ||
50 | static inline struct setup_t const* track_get_setup( struct Track_Filter* this ) { return &this->setup_; } | ||
51 | static inline void track_setup( struct Track_Filter* this, struct setup_t const* s ) { this->setup_ = *s; } | ||
52 | |||
53 | // Disables automatic end-of-track detection and skipping of silence at beginning | ||
54 | static inline void track_ignore_silence( struct Track_Filter* this, bool disable ) { this->silence_ignored_ = disable; } | ||
55 | |||
56 | // Clears state and skips initial silence in track | ||
57 | blargg_err_t track_start( struct Track_Filter* this ); | ||
58 | |||
59 | // Sets time that fade starts, and how long until track ends. | ||
60 | void track_set_fade( struct Track_Filter* this, sample_count_t start, sample_count_t length ); | ||
61 | |||
62 | // Generates n samples into buf | ||
63 | blargg_err_t track_play( struct Track_Filter* this, int n, sample_t buf [] ); | ||
64 | |||
65 | // Skips n samples | ||
66 | blargg_err_t track_skip( struct Track_Filter* this, int n ); | ||
67 | |||
68 | // Number of samples played/skipped since start_track() | ||
69 | static inline int track_sample_count( struct Track_Filter* this ) { return this->out_time; } | ||
70 | |||
71 | // True if track ended. Causes are end of source samples, end of fade, | ||
72 | // or excessive silence. | ||
73 | static inline bool track_ended( struct Track_Filter* this ) { return this->track_ended_; } | ||
74 | |||
75 | // Clears state | ||
76 | void track_stop( struct Track_Filter* this ); | ||
77 | |||
78 | // For use by callbacks | ||
79 | |||
80 | // Sets internal "track ended" flag and stops generation of further source samples | ||
81 | static inline void track_set_end( struct Track_Filter* this ) { this->emu_track_ended_ = true; } | ||
82 | |||
83 | // For use by skip_() callback | ||
84 | blargg_err_t skippy_( struct Track_Filter* this, int count ); | ||
85 | void fill_buf( struct Track_Filter* this ); | ||
86 | |||
87 | // Skip and play callbacks | ||
88 | blargg_err_t skip_( void* emu, int count ); | ||
89 | blargg_err_t play_( void* emu, int count, sample_t out [] ); | ||
90 | #endif | ||