summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libgme/track_filter.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libgme/track_filter.h')
-rw-r--r--lib/rbcodec/codecs/libgme/track_filter.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/track_filter.h b/lib/rbcodec/codecs/libgme/track_filter.h
new file mode 100644
index 0000000000..3689be9620
--- /dev/null
+++ b/lib/rbcodec/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
10typedef short sample_t;
11typedef int sample_count_t;
12
13enum { indefinite_count = INT_MAX/2 + 1 };
14enum { buf_size = 2048 };
15
16struct 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
22struct 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.
46blargg_err_t track_init( struct Track_Filter* this, void* );
47void track_create( struct Track_Filter* this );
48
49// Gets/sets setup
50static inline struct setup_t const* track_get_setup( struct Track_Filter* this ) { return &this->setup_; }
51static 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
54static 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
57blargg_err_t track_start( struct Track_Filter* this );
58
59// Sets time that fade starts, and how long until track ends.
60void track_set_fade( struct Track_Filter* this, sample_count_t start, sample_count_t length );
61
62// Generates n samples into buf
63blargg_err_t track_play( struct Track_Filter* this, int n, sample_t buf [] );
64
65// Skips n samples
66blargg_err_t track_skip( struct Track_Filter* this, int n );
67
68// Number of samples played/skipped since start_track()
69static 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.
73static inline bool track_ended( struct Track_Filter* this ) { return this->track_ended_; }
74
75// Clears state
76void 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
81static inline void track_set_end( struct Track_Filter* this ) { this->emu_track_ended_ = true; }
82
83// For use by skip_() callback
84blargg_err_t skippy_( struct Track_Filter* this, int count );
85void fill_buf( struct Track_Filter* this );
86
87// Skip and play callbacks
88blargg_err_t skip_( void* emu, int count );
89blargg_err_t play_( void* emu, int count, sample_t out [] );
90#endif