annotate Plugins/Input/timidity/libtimidity/mix.c @ 285:d1762728ea4b trunk

[svn] Timidity support, via external contractor dai+audacious@cdr.jp.
author nenolod
date Wed, 14 Dec 2005 08:51:51 -0800
parents
children c1dfb4b13be8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
1 /*
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
2
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
3 TiMidity -- Experimental MIDI to WAVE converter
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
4 Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
5
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
6 Suddenly, you realize that this program is free software; you get
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
7 an overwhelming urge to redistribute it and/or modify it under the
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
9 Software Foundation; either version 2 of the License, or (at your
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
10 option) any later version.
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
11
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
12 This program is distributed in the hope that it will be useful,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
15 GNU General Public License for more details.
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
16
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
17 You should have received another copy of the GNU General Public
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
18 License along with this program; if not, write to the Free
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
19 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
20 I bet they'll be amazed.
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
21
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
22 mix.c */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
23
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
24 #if HAVE_CONFIG_H
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
25 # include <config.h>
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
26 #endif
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
27
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
28 #include <math.h>
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
29 #include <stdio.h>
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
30 #include <stdlib.h>
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
31
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
32 #include "timidity.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
33 #include "timidity_internal.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
34 #include "options.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
35 #include "instrum.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
36 #include "playmidi.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
37 #include "output.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
38 #include "tables.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
39 #include "resample.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
40 #include "mix.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
41
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
42 /* Returns 1 if envelope runs out */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
43 int recompute_envelope(MidSong *song, int v)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
44 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
45 int stage;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
46
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
47 stage = song->voice[v].envelope_stage;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
48
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
49 if (stage>5)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
50 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
51 /* Envelope ran out. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
52 song->voice[v].status = VOICE_FREE;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
53 return 1;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
54 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
55
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
56 if (song->voice[v].sample->modes & MODES_ENVELOPE)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
57 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
58 if (song->voice[v].status==VOICE_ON || song->voice[v].status==VOICE_SUSTAINED)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
59 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
60 if (stage>2)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
61 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
62 /* Freeze envelope until note turns off. Trumpets want this. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
63 song->voice[v].envelope_increment=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
64 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
65 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
66 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
67 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
68 song->voice[v].envelope_stage=stage+1;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
69
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
70 if (song->voice[v].envelope_volume==song->voice[v].sample->envelope_offset[stage])
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
71 return recompute_envelope(song, v);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
72 song->voice[v].envelope_target = song->voice[v].sample->envelope_offset[stage];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
73 song->voice[v].envelope_increment = song->voice[v].sample->envelope_rate[stage];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
74 if (song->voice[v].envelope_target < song->voice[v].envelope_volume)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
75 song->voice[v].envelope_increment = -song->voice[v].envelope_increment;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
76 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
77 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
78
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
79 void apply_envelope_to_amp(MidSong *song, int v)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
80 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
81 float lamp = song->voice[v].left_amp, ramp;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
82 sint32 la,ra;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
83 if (song->voice[v].panned == PANNED_MYSTERY)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
84 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
85 ramp = song->voice[v].right_amp;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
86 if (song->voice[v].tremolo_phase_increment)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
87 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
88 lamp *= song->voice[v].tremolo_volume;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
89 ramp *= song->voice[v].tremolo_volume;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
90 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
91 if (song->voice[v].sample->modes & MODES_ENVELOPE)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
92 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
93 lamp *= (float)vol_table[song->voice[v].envelope_volume>>23];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
94 ramp *= (float)vol_table[song->voice[v].envelope_volume>>23];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
95 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
96
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
97 la = (sint32)FSCALE(lamp,AMP_BITS);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
98
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
99 if (la>MAX_AMP_VALUE)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
100 la=MAX_AMP_VALUE;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
101
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
102 ra = (sint32)FSCALE(ramp,AMP_BITS);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
103 if (ra>MAX_AMP_VALUE)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
104 ra=MAX_AMP_VALUE;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
105
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
106 song->voice[v].left_mix = la;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
107 song->voice[v].right_mix = ra;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
108 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
109 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
110 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
111 if (song->voice[v].tremolo_phase_increment)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
112 lamp *= song->voice[v].tremolo_volume;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
113 if (song->voice[v].sample->modes & MODES_ENVELOPE)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
114 lamp *= (float)vol_table[song->voice[v].envelope_volume>>23];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
115
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
116 la = (sint32)FSCALE(lamp,AMP_BITS);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
117
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
118 if (la>MAX_AMP_VALUE)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
119 la=MAX_AMP_VALUE;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
120
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
121 song->voice[v].left_mix = la;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
122 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
123 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
124
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
125 static int update_envelope(MidSong *song, int v)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
126 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
127 song->voice[v].envelope_volume += song->voice[v].envelope_increment;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
128 /* Why is there no ^^ operator?? */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
129 if (((song->voice[v].envelope_increment < 0) &&
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
130 (song->voice[v].envelope_volume <= song->voice[v].envelope_target)) ||
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
131 ((song->voice[v].envelope_increment > 0) &&
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
132 (song->voice[v].envelope_volume >= song->voice[v].envelope_target)))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
133 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
134 song->voice[v].envelope_volume = song->voice[v].envelope_target;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
135 if (recompute_envelope(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
136 return 1;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
137 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
138 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
139 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
140
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
141 static void update_tremolo(MidSong *song, int v)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
142 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
143 sint32 depth = song->voice[v].sample->tremolo_depth << 7;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
144
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
145 if (song->voice[v].tremolo_sweep)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
146 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
147 /* Update sweep position */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
148
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
149 song->voice[v].tremolo_sweep_position += song->voice[v].tremolo_sweep;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
150 if (song->voice[v].tremolo_sweep_position >= (1 << SWEEP_SHIFT))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
151 song->voice[v].tremolo_sweep=0; /* Swept to max amplitude */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
152 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
153 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
154 /* Need to adjust depth */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
155 depth *= song->voice[v].tremolo_sweep_position;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
156 depth >>= SWEEP_SHIFT;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
157 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
158 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
159
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
160 song->voice[v].tremolo_phase += song->voice[v].tremolo_phase_increment;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
161
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
162 /* if (song->voice[v].tremolo_phase >= (SINE_CYCLE_LENGTH<<RATE_SHIFT))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
163 song->voice[v].tremolo_phase -= SINE_CYCLE_LENGTH<<RATE_SHIFT; */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
164
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
165 song->voice[v].tremolo_volume = (float)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
166 (1.0 - FSCALENEG((sine(song->voice[v].tremolo_phase >> RATE_SHIFT) + 1.0)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
167 * depth * TREMOLO_AMPLITUDE_TUNING,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
168 17));
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
169
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
170 /* I'm not sure about the +1.0 there -- it makes tremoloed voices'
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
171 volumes on average the lower the higher the tremolo amplitude. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
172 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
173
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
174 /* Returns 1 if the note died */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
175 static int update_signal(MidSong *song, int v)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
176 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
177 if (song->voice[v].envelope_increment && update_envelope(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
178 return 1;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
179
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
180 if (song->voice[v].tremolo_phase_increment)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
181 update_tremolo(song, v);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
182
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
183 apply_envelope_to_amp(song, v);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
184 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
185 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
186
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
187 #define MIXATION(a) *lp++ += (a)*s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
188
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
189 static void mix_mystery_signal(MidSong *song, sample_t *sp, sint32 *lp, int v,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
190 int count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
191 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
192 MidVoice *vp = song->voice + v;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
193 final_volume_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
194 left=vp->left_mix,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
195 right=vp->right_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
196 int cc;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
197 sample_t s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
198
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
199 if (!(cc = vp->control_counter))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
200 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
201 cc = song->control_ratio;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
202 if (update_signal(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
203 return; /* Envelope ran out */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
204 left = vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
205 right = vp->right_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
206 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
207
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
208 while (count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
209 if (cc < count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
210 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
211 count -= cc;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
212 while (cc--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
213 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
214 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
215 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
216 MIXATION(right);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
217 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
218 cc = song->control_ratio;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
219 if (update_signal(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
220 return; /* Envelope ran out */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
221 left = vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
222 right = vp->right_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
223 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
224 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
225 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
226 vp->control_counter = cc - count;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
227 while (count--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
228 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
229 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
230 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
231 MIXATION(right);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
232 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
233 return;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
234 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
235 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
236
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
237 static void mix_center_signal(MidSong *song, sample_t *sp, sint32 *lp, int v,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
238 int count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
239 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
240 MidVoice *vp = song->voice + v;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
241 final_volume_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
242 left=vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
243 int cc;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
244 sample_t s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
245
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
246 if (!(cc = vp->control_counter))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
247 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
248 cc = song->control_ratio;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
249 if (update_signal(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
250 return; /* Envelope ran out */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
251 left = vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
252 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
253
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
254 while (count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
255 if (cc < count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
256 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
257 count -= cc;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
258 while (cc--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
259 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
260 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
261 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
262 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
263 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
264 cc = song->control_ratio;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
265 if (update_signal(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
266 return; /* Envelope ran out */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
267 left = vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
268 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
269 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
270 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
271 vp->control_counter = cc - count;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
272 while (count--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
273 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
274 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
275 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
276 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
277 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
278 return;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
279 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
280 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
281
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
282 static void mix_single_signal(MidSong *song, sample_t *sp, sint32 *lp, int v,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
283 int count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
284 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
285 MidVoice *vp = song->voice + v;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
286 final_volume_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
287 left=vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
288 int cc;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
289 sample_t s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
290
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
291 if (!(cc = vp->control_counter))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
292 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
293 cc = song->control_ratio;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
294 if (update_signal(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
295 return; /* Envelope ran out */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
296 left = vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
297 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
298
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
299 while (count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
300 if (cc < count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
301 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
302 count -= cc;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
303 while (cc--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
304 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
305 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
306 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
307 lp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
308 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
309 cc = song->control_ratio;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
310 if (update_signal(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
311 return; /* Envelope ran out */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
312 left = vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
313 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
314 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
315 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
316 vp->control_counter = cc - count;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
317 while (count--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
318 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
319 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
320 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
321 lp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
322 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
323 return;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
324 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
325 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
326
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
327 static void mix_mono_signal(MidSong *song, sample_t *sp, sint32 *lp, int v,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
328 int count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
329 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
330 MidVoice *vp = song->voice + v;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
331 final_volume_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
332 left=vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
333 int cc;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
334 sample_t s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
335
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
336 if (!(cc = vp->control_counter))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
337 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
338 cc = song->control_ratio;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
339 if (update_signal(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
340 return; /* Envelope ran out */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
341 left = vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
342 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
343
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
344 while (count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
345 if (cc < count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
346 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
347 count -= cc;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
348 while (cc--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
349 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
350 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
351 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
352 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
353 cc = song->control_ratio;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
354 if (update_signal(song, v))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
355 return; /* Envelope ran out */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
356 left = vp->left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
357 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
358 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
359 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
360 vp->control_counter = cc - count;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
361 while (count--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
362 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
363 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
364 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
365 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
366 return;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
367 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
368 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
369
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
370 static void mix_mystery(MidSong *song, sample_t *sp, sint32 *lp, int v, int count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
371 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
372 final_volume_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
373 left = song->voice[v].left_mix,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
374 right = song->voice[v].right_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
375 sample_t s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
376
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
377 while (count--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
378 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
379 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
380 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
381 MIXATION(right);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
382 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
383 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
384
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
385 static void mix_center(MidSong *song, sample_t *sp, sint32 *lp, int v, int count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
386 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
387 final_volume_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
388 left = song->voice[v].left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
389 sample_t s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
390
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
391 while (count--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
392 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
393 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
394 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
395 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
396 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
397 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
398
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
399 static void mix_single(MidSong *song, sample_t *sp, sint32 *lp, int v, int count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
400 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
401 final_volume_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
402 left = song->voice[v].left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
403 sample_t s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
404
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
405 while (count--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
406 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
407 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
408 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
409 lp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
410 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
411 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
412
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
413 static void mix_mono(MidSong *song, sample_t *sp, sint32 *lp, int v, int count)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
414 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
415 final_volume_t
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
416 left = song->voice[v].left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
417 sample_t s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
418
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
419 while (count--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
420 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
421 s = *sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
422 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
423 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
424 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
425
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
426 /* Ramp a note out in c samples */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
427 static void ramp_out(MidSong *song, sample_t *sp, sint32 *lp, int v, sint32 c)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
428 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
429
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
430 /* should be final_volume_t, but uint8 gives trouble. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
431 sint32 left, right, li, ri;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
432
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
433 sample_t s=0; /* silly warning about uninitialized s */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
434
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
435 /* Fix by James Caldwell */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
436 if ( c == 0 ) c = 1;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
437
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
438 left=song->voice[v].left_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
439 li=-(left/c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
440 if (!li) li=-1;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
441
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
442 /* printf("Ramping out: left=%d, c=%d, li=%d\n", left, c, li); */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
443
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
444 if (!(song->encoding & PE_MONO))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
445 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
446 if (song->voice[v].panned==PANNED_MYSTERY)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
447 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
448 right=song->voice[v].right_mix;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
449 ri=-(right/c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
450 while (c--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
451 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
452 left += li;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
453 if (left<0)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
454 left=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
455 right += ri;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
456 if (right<0)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
457 right=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
458 s=*sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
459 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
460 MIXATION(right);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
461 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
462 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
463 else if (song->voice[v].panned==PANNED_CENTER)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
464 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
465 while (c--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
466 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
467 left += li;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
468 if (left<0)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
469 return;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
470 s=*sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
471 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
472 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
473 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
474 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
475 else if (song->voice[v].panned==PANNED_LEFT)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
476 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
477 while (c--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
478 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
479 left += li;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
480 if (left<0)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
481 return;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
482 s=*sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
483 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
484 lp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
485 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
486 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
487 else if (song->voice[v].panned==PANNED_RIGHT)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
488 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
489 while (c--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
490 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
491 left += li;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
492 if (left<0)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
493 return;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
494 s=*sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
495 lp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
496 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
497 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
498 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
499 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
500 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
501 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
502 /* Mono output. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
503 while (c--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
504 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
505 left += li;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
506 if (left<0)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
507 return;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
508 s=*sp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
509 MIXATION(left);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
510 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
511 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
512 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
513
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
514
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
515 /**************** interface function ******************/
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
516
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
517 void mix_voice(MidSong *song, sint32 *buf, int v, sint32 c)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
518 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
519 MidVoice *vp = song->voice + v;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
520 sample_t *sp;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
521 if (vp->status==VOICE_DIE)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
522 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
523 if (c>=MAX_DIE_TIME)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
524 c=MAX_DIE_TIME;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
525 sp=resample_voice(song, v, &c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
526 ramp_out(song, sp, buf, v, c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
527 vp->status=VOICE_FREE;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
528 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
529 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
530 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
531 sp=resample_voice(song, v, &c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
532 if (song->encoding & PE_MONO)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
533 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
534 /* Mono output. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
535 if (vp->envelope_increment || vp->tremolo_phase_increment)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
536 mix_mono_signal(song, sp, buf, v, c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
537 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
538 mix_mono(song, sp, buf, v, c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
539 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
540 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
541 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
542 if (vp->panned == PANNED_MYSTERY)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
543 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
544 if (vp->envelope_increment || vp->tremolo_phase_increment)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
545 mix_mystery_signal(song, sp, buf, v, c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
546 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
547 mix_mystery(song, sp, buf, v, c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
548 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
549 else if (vp->panned == PANNED_CENTER)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
550 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
551 if (vp->envelope_increment || vp->tremolo_phase_increment)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
552 mix_center_signal(song, sp, buf, v, c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
553 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
554 mix_center(song, sp, buf, v, c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
555 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
556 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
557 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
558 /* It's either full left or full right. In either case,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
559 every other sample is 0. Just get the offset right: */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
560 if (vp->panned == PANNED_RIGHT) buf++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
561
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
562 if (vp->envelope_increment || vp->tremolo_phase_increment)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
563 mix_single_signal(song, sp, buf, v, c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
564 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
565 mix_single(song, sp, buf, v, c);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
566 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
567 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
568 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
569 }