Mercurial > audlegacy
annotate Plugins/Input/console/Blip_Synth.h @ 108:cde5ca21ddc3 trunk
[svn] Improved latency on the decode loop.
author | nenolod |
---|---|
date | Wed, 02 Nov 2005 21:45:23 -0800 |
parents | 252843aac42f |
children |
rev | line source |
---|---|
90
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
1 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
2 // Blip_Synth and Blip_Wave are waveform transition synthesizers for adding |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
3 // waveforms to a Blip_Buffer. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
4 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
5 // Blip_Buffer 0.3.3. Copyright (C) 2003-2005 Shay Green. GNU LGPL license. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
6 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
7 #ifndef BLIP_SYNTH_H |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
8 #define BLIP_SYNTH_H |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
9 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
10 #ifndef BLIP_BUFFER_H |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
11 #include "Blip_Buffer.h" |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
12 #endif |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
13 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
14 // Quality level. Higher levels are slower, and worse in a few cases. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
15 // Use blip_good_quality as a starting point. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
16 const int blip_low_quality = 1; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
17 const int blip_med_quality = 2; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
18 const int blip_good_quality = 3; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
19 const int blip_high_quality = 4; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
20 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
21 // Blip_Synth is a transition waveform synthesizer which adds band-limited |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
22 // offsets (transitions) into a Blip_Buffer. For a simpler interface, use |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
23 // Blip_Wave (below). |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
24 // |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
25 // Range specifies the greatest expected offset that will occur. For a |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
26 // waveform that goes between +amp and -amp, range should be amp * 2 (half |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
27 // that if it only goes between +amp and 0). When range is large, a higher |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
28 // accuracy scheme is used; to force this even when range is small, pass |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
29 // the negative of range (i.e. -range). |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
30 template<int quality,int range> |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
31 class Blip_Synth { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
32 BOOST_STATIC_ASSERT( 1 <= quality && quality <= 5 ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
33 BOOST_STATIC_ASSERT( -32768 <= range && range <= 32767 ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
34 enum { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
35 abs_range = (range < 0) ? -range : range, |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
36 fine_mode = (range > 512 || range < 0), |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
37 width = (quality < 5 ? quality * 4 : Blip_Buffer::widest_impulse_), |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
38 res = 1 << blip_res_bits_, |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
39 impulse_size = width / 2 * (fine_mode + 1), |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
40 base_impulses_size = width / 2 * (res / 2 + 1), |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
41 fine_bits = (fine_mode ? (abs_range <= 64 ? 2 : abs_range <= 128 ? 3 : |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
42 abs_range <= 256 ? 4 : abs_range <= 512 ? 5 : abs_range <= 1024 ? 6 : |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
43 abs_range <= 2048 ? 7 : 8) : 0) |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
44 }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
45 blip_pair_t_ impulses [impulse_size * res * 2 + base_impulses_size]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
46 Blip_Impulse_ impulse; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
47 public: |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
48 Blip_Synth() { impulse.init( impulses, width, res, fine_bits ); } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
49 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
50 // Configure low-pass filter (see notes.txt). Not optimized for real-time control |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
51 void treble_eq( const blip_eq_t& eq ) { impulse.treble_eq( eq ); } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
52 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
53 // Set volume of a transition at amplitude 'range' by setting volume_unit |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
54 // to v / range |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
55 void volume( double v ) { impulse.volume_unit( v * (1.0 / abs_range) ); } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
56 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
57 // Set base volume unit of transitions, where 1.0 is a full swing between the |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
58 // positive and negative extremes. Not optimized for real-time control. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
59 void volume_unit( double unit ) { impulse.volume_unit( unit ); } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
60 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
61 // Default Blip_Buffer used for output when none is specified for a given call |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
62 Blip_Buffer* output() const { return impulse.buf; } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
63 void output( Blip_Buffer* b ) { impulse.buf = b; } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
64 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
65 // Add an amplitude offset (transition) with an amplitude of delta * volume_unit |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
66 // into the specified buffer (default buffer if none specified) at the |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
67 // specified source time. Amplitude can be positive or negative. To increase |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
68 // performance by inlining code at the call site, use offset_inline(). |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
69 void offset( blip_time_t, int delta, Blip_Buffer* ) const; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
70 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
71 void offset_resampled( blip_resampled_time_t, int delta, Blip_Buffer* ) const; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
72 void offset_resampled( blip_resampled_time_t t, int o ) const { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
73 offset_resampled( t, o, impulse.buf ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
74 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
75 void offset( blip_time_t t, int delta ) const { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
76 offset( t, delta, impulse.buf ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
77 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
78 void offset_inline( blip_time_t time, int delta, Blip_Buffer* buf ) const { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
79 offset_resampled( time * buf->factor_ + buf->offset_, delta, buf ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
80 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
81 void offset_inline( blip_time_t time, int delta ) const { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
82 offset_inline( time, delta, impulse.buf ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
83 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
84 }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
85 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
86 // Blip_Wave is a synthesizer for adding a *single* waveform to a Blip_Buffer. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
87 // A wave is built from a series of delays and new amplitudes. This provides a |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
88 // simpler interface than Blip_Synth. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
89 template<int quality,int range> |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
90 class Blip_Wave { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
91 Blip_Synth<quality,range> synth; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
92 blip_time_t time_; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
93 int last_amp; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
94 public: |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
95 // Start wave at time 0 and amplitude 0 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
96 Blip_Wave() : time_( 0 ), last_amp( 0 ) { } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
97 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
98 // See Blip_Synth for description |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
99 void volume( double v ) { synth.volume( v ); } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
100 void volume_unit( double v ) { synth.volume_unit( v ); } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
101 void treble_eq( const blip_eq_t& eq){ synth.treble_eq( eq ); } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
102 Blip_Buffer* output() const { return synth.output(); } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
103 void output( Blip_Buffer* b ) { synth.output( b ); if ( !b ) time_ = last_amp = 0; } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
104 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
105 // Current time in frame |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
106 blip_time_t time() const { return time_; } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
107 void time( blip_time_t t ) { time_ = t; } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
108 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
109 // Current amplitude of wave |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
110 int amplitude() const { return last_amp; } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
111 void amplitude( int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
112 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
113 // Move forward by 't' time units |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
114 void delay( blip_time_t t ) { time_ += t; } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
115 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
116 // End time frame of specified duration. Localize time to new frame. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
117 void end_frame( blip_time_t duration ) { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
118 assert(( "Blip_Wave::end_frame(): Wave hadn't yet been run for entire frame", |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
119 duration <= time_ )); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
120 time_ -= duration; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
121 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
122 }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
123 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
124 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
125 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
126 // End of public interface |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
127 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
128 template<int quality,int range> |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
129 void Blip_Wave<quality,range>::amplitude( int amp ) { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
130 int delta = amp - last_amp; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
131 last_amp = amp; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
132 synth.offset_inline( time_, delta ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
133 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
134 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
135 template<int quality,int range> |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
136 inline void Blip_Synth<quality,range>::offset_resampled( blip_resampled_time_t time, |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
137 int delta, Blip_Buffer* blip_buf ) const |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
138 { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
139 typedef blip_pair_t_ pair_t; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
140 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
141 unsigned sample_index = (time >> BLIP_BUFFER_ACCURACY) & ~1; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
142 assert(( "Blip_Synth/Blip_wave: Went past end of buffer", |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
143 sample_index < blip_buf->buffer_size_ )); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
144 enum { const_offset = Blip_Buffer::widest_impulse_ / 2 - width / 2 }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
145 pair_t* buf = (pair_t*) &blip_buf->buffer_ [const_offset + sample_index]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
146 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
147 enum { shift = BLIP_BUFFER_ACCURACY - blip_res_bits_ }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
148 enum { mask = res * 2 - 1 }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
149 const pair_t* imp = &impulses [((time >> shift) & mask) * impulse_size]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
150 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
151 pair_t offset = impulse.offset * delta; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
152 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
153 if ( !fine_bits ) |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
154 { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
155 // normal mode |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
156 for ( int n = width / 4; n; --n ) |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
157 { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
158 pair_t t0 = buf [0] - offset; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
159 pair_t t1 = buf [1] - offset; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
160 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
161 t0 += imp [0] * delta; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
162 t1 += imp [1] * delta; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
163 imp += 2; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
164 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
165 buf [0] = t0; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
166 buf [1] = t1; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
167 buf += 2; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
168 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
169 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
170 else |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
171 { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
172 // fine mode |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
173 enum { sub_range = 1 << fine_bits }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
174 delta += sub_range / 2; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
175 int delta2 = (delta & (sub_range - 1)) - sub_range / 2; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
176 delta >>= fine_bits; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
177 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
178 for ( int n = width / 4; n; --n ) |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
179 { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
180 pair_t t0 = buf [0] - offset; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
181 pair_t t1 = buf [1] - offset; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
182 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
183 t0 += imp [0] * delta2; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
184 t0 += imp [1] * delta; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
185 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
186 t1 += imp [2] * delta2; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
187 t1 += imp [3] * delta; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
188 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
189 imp += 4; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
190 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
191 buf [0] = t0; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
192 buf [1] = t1; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
193 buf += 2; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
194 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
195 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
196 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
197 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
198 template<int quality,int range> |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
199 void Blip_Synth<quality,range>::offset( blip_time_t time, int delta, Blip_Buffer* buf ) const { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
200 offset_resampled( time * buf->factor_ + buf->offset_, delta, buf ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
201 } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
202 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
203 #endif |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
204 |