annotate Plugins/Input/timidity/libtimidity/instrum.c @ 480:c1dfb4b13be8 trunk

[svn] Use the VFS layer.
author chainsaw
date Sat, 21 Jan 2006 07:12:02 -0800
parents d1762728ea4b
children d539e5c5f730
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 This program is free software; you can redistribute it and/or modify
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
9 (at your option) any later version.
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
10
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
11 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
12 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
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
14 GNU General Public License for more details.
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
15
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
17 along with this program; if not, write to the Free Software
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
19
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
20 instrum.c
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 Code to load and unload GUS-compatible instrument patches.
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 */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
25
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
26 #if HAVE_CONFIG_H
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
27 # include <config.h>
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
28 #endif
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
29
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
30 #include "libaudacious/vfs.h"
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
31 #include <string.h>
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
32 #include <stdlib.h>
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
33
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
34 #include "timidity.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
35 #include "timidity_internal.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
36 #include "options.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
37 #include "common.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
38 #include "instrum.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
39 #include "instrum_dls.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
40 #include "resample.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
41 #include "tables.h"
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
42
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
43 static void free_instrument(MidInstrument *ip)
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 MidSample *sp;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
46 int i;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
47 if (!ip) return;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
48 for (i=0; i<ip->samples; i++)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
49 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
50 sp=&(ip->sample[i]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
51 free(sp->data);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
52 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
53 free(ip->sample);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
54 free(ip);
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
57 static void free_bank(MidSong *song, int dr, int b)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
58 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
59 int i;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
60 MidToneBank *bank=((dr) ? song->drumset[b] : song->tonebank[b]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
61 for (i=0; i<128; i++)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
62 if (bank->instrument[i])
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
63 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
64 /* Not that this could ever happen, of course */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
65 if (bank->instrument[i] != MAGIC_LOAD_INSTRUMENT)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
66 free_instrument(bank->instrument[i]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
67 bank->instrument[i]=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
68 }
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
71 static sint32 convert_envelope_rate(MidSong *song, uint8 rate)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
72 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
73 sint32 r;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
74
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
75 r = 3 - ((rate >> 6) & 0x3);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
76 r *= 3;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
77 r = (sint32) (rate & 0x3f) << r; /* 6.9 fixed point */
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 /* 15.15 fixed point. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
80 r = ((r * 44100) / song->rate) * song->control_ratio;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
81
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
82 #ifdef FAST_DECAY
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
83 return r << 10;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
84 #else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
85 return r << 9;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
86 #endif
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
89 static sint32 convert_envelope_offset(uint8 offset)
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 /* This is not too good... Can anyone tell me what these values mean?
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
92 Are they GUS-style "exponential" volumes? And what does that mean? */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
93
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
94 /* 15.15 fixed point */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
95 return offset << (7+15);
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
98 static sint32 convert_tremolo_sweep(MidSong *song, uint8 sweep)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
99 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
100 if (!sweep)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
101 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
102
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
103 return
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
104 ((song->control_ratio * SWEEP_TUNING) << SWEEP_SHIFT) /
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
105 (song->rate * sweep);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
106 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
107
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
108 static sint32 convert_vibrato_sweep(MidSong *song, uint8 sweep,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
109 sint32 vib_control_ratio)
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 (!sweep)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
112 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
113
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
114 return
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
115 (sint32) (FSCALE((double) (vib_control_ratio) * SWEEP_TUNING, SWEEP_SHIFT)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
116 / (double)(song->rate * sweep));
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 /* this was overflowing with seashore.pat
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
119
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
120 ((vib_control_ratio * SWEEP_TUNING) << SWEEP_SHIFT) /
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
121 (song->rate * sweep); */
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 static sint32 convert_tremolo_rate(MidSong *song, uint8 rate)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
125 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
126 return
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
127 ((SINE_CYCLE_LENGTH * song->control_ratio * rate) << RATE_SHIFT) /
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
128 (TREMOLO_RATE_TUNING * song->rate);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
129 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
130
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
131 static sint32 convert_vibrato_rate(MidSong *song, uint8 rate)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
132 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
133 /* Return a suitable vibrato_control_ratio value */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
134 return
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
135 (VIBRATO_RATE_TUNING * song->rate) /
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
136 (rate * 2 * MID_VIBRATO_SAMPLE_INCREMENTS);
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
139 static void reverse_data(sint16 *sp, sint32 ls, sint32 le)
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 sint16 s, *ep=sp+le;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
142 sp+=ls;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
143 le-=ls;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
144 le/=2;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
145 while (le--)
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 s=*sp;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
148 *sp++=*ep;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
149 *ep--=s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
150 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
151 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
152
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 If panning or note_to_use != -1, it will be used for all samples,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
155 instead of the sample-specific values in the instrument file.
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
156
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
157 For note_to_use, any value <0 or >127 will be forced to 0.
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 For other parameters, 1 means yes, 0 means no, other values are
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
160 undefined.
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 TODO: do reverse loops right */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
163 static MidInstrument *load_instrument(MidSong *song, char *name, int percussion,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
164 int panning, int amp, int note_to_use,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
165 int strip_loop, int strip_envelope,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
166 int strip_tail)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
167 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
168 MidInstrument *ip;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
169 MidSample *sp;
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
170 VFSFile *fp;
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
171 char tmp[1024];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
172 int i,j,noluck=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
173 static char *patch_ext[] = PATCH_EXT_LIST;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
174
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
175 if (!name) return 0;
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 /* Open patch file */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
178 if ((fp=open_file(name)) == NULL)
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 noluck=1;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
181 /* Try with various extensions */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
182 for (i=0; patch_ext[i]; i++)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
183 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
184 if (strlen(name)+strlen(patch_ext[i])<1024)
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 strcpy(tmp, name);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
187 strcat(tmp, patch_ext[i]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
188 if ((fp=open_file(tmp)) != NULL)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
189 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
190 noluck=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
191 break;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
192 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
193 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
194 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
195 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
196
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
197 if (noluck)
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 DEBUG_MSG("Instrument `%s' can't be found.\n", name);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
200 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
201 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
202
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
203 DEBUG_MSG("Loading instrument %s\n", tmp);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
204
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
205 /* Read some headers and do cursory sanity checks. There are loads
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
206 of magic offsets. This could be rewritten... */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
207
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
208 if ((239 != vfs_fread(tmp, 1, 239, fp)) ||
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
209 (memcmp(tmp, "GF1PATCH110\0ID#000002", 22) &&
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
210 memcmp(tmp, "GF1PATCH100\0ID#000002", 22))) /* don't know what the
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
211 differences are */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
212 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
213 DEBUG_MSG("%s: not an instrument\n", name);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
214 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
215 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
216
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
217 if (tmp[82] != 1 && tmp[82] != 0) /* instruments. To some patch makers,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
218 0 means 1 */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
219 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
220 DEBUG_MSG("Can't handle patches with %d instruments\n", tmp[82]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
221 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
222 }
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 if (tmp[151] != 1 && tmp[151] != 0) /* layers. What's a layer? */
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 DEBUG_MSG("Can't handle instruments with %d layers\n", tmp[151]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
227 return 0;
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
230 ip=safe_malloc(sizeof(MidInstrument));
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
231 ip->samples = tmp[198];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
232 ip->sample = safe_malloc(sizeof(MidSample) * ip->samples);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
233 for (i=0; i<ip->samples; i++)
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 uint8 fractions;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
237 sint32 tmplong;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
238 uint16 tmpshort;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
239 uint8 tmpchar;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
240
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
241 #define READ_CHAR(thing) \
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
242 if (1 != vfs_fread(&tmpchar, 1, 1, fp)) goto fail; \
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
243 thing = tmpchar;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
244 #define READ_SHORT(thing) \
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
245 if (1 != vfs_fread(&tmpshort, 2, 1, fp)) goto fail; \
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
246 thing = SWAPLE16(tmpshort);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
247 #define READ_LONG(thing) \
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
248 if (1 != vfs_fread(&tmplong, 4, 1, fp)) goto fail; \
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
249 thing = SWAPLE32(tmplong);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
250
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
251 vfs_fseek(fp, 7, SEEK_CUR); /* Skip the wave name */
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
252
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
253 if (1 != vfs_fread(&fractions, 1, 1, fp))
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
254 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
255 fail:
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
256 DEBUG_MSG("Error reading sample %d\n", i);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
257 for (j=0; j<i; j++)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
258 free(ip->sample[j].data);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
259 free(ip->sample);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
260 free(ip);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
261 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
262 }
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 sp=&(ip->sample[i]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
265
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
266 READ_LONG(sp->data_length);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
267 READ_LONG(sp->loop_start);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
268 READ_LONG(sp->loop_end);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
269 READ_SHORT(sp->sample_rate);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
270 READ_LONG(sp->low_freq);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
271 READ_LONG(sp->high_freq);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
272 READ_LONG(sp->root_freq);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
273 sp->low_vel = 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
274 sp->high_vel = 127;
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
275 vfs_fseek(fp, 2, SEEK_CUR); /* Why have a "root frequency" and then
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
276 * "tuning"?? */
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 READ_CHAR(tmp[0]);
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 if (panning==-1)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
281 sp->panning = (tmp[0] * 8 + 4) & 0x7f;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
282 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
283 sp->panning=(uint8)(panning & 0x7F);
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 /* envelope, tremolo, and vibrato */
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
286 if (18 != vfs_fread(tmp, 1, 18, fp)) goto fail;
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
287
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
288 if (!tmp[13] || !tmp[14])
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
289 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
290 sp->tremolo_sweep_increment=
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
291 sp->tremolo_phase_increment=sp->tremolo_depth=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
292 DEBUG_MSG(" * no tremolo\n");
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
293 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
294 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
295 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
296 sp->tremolo_sweep_increment=convert_tremolo_sweep(song, tmp[12]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
297 sp->tremolo_phase_increment=convert_tremolo_rate(song, tmp[13]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
298 sp->tremolo_depth=tmp[14];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
299 DEBUG_MSG(" * tremolo: sweep %d, phase %d, depth %d\n",
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
300 sp->tremolo_sweep_increment, sp->tremolo_phase_increment,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
301 sp->tremolo_depth);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
302 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
303
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
304 if (!tmp[16] || !tmp[17])
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
305 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
306 sp->vibrato_sweep_increment=
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
307 sp->vibrato_control_ratio=sp->vibrato_depth=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
308 DEBUG_MSG(" * no vibrato\n");
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
309 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
310 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
311 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
312 sp->vibrato_control_ratio=convert_vibrato_rate(song, tmp[16]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
313 sp->vibrato_sweep_increment=
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
314 convert_vibrato_sweep(song, tmp[15], sp->vibrato_control_ratio);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
315 sp->vibrato_depth=tmp[17];
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
316 DEBUG_MSG(" * vibrato: sweep %d, ctl %d, depth %d\n",
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
317 sp->vibrato_sweep_increment, sp->vibrato_control_ratio,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
318 sp->vibrato_depth);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
319
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
320 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
321
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
322 READ_CHAR(sp->modes);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
323
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
324 vfs_fseek(fp, 40, SEEK_CUR); /* skip the useless scale frequency, scale
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
325 factor (what's it mean?), and reserved
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
326 space */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
327
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
328 /* Mark this as a fixed-pitch instrument if such a deed is desired. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
329 if (note_to_use!=-1)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
330 sp->note_to_use=(uint8)(note_to_use);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
331 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
332 sp->note_to_use=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
333
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
334 /* seashore.pat in the Midia patch set has no Sustain. I don't
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
335 understand why, and fixing it by adding the Sustain flag to
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
336 all looped patches probably breaks something else. We do it
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
337 anyway. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
338
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
339 if (sp->modes & MODES_LOOPING)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
340 sp->modes |= MODES_SUSTAIN;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
341
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
342 /* Strip any loops and envelopes we're permitted to */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
343 if ((strip_loop==1) &&
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
344 (sp->modes & (MODES_SUSTAIN | MODES_LOOPING |
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
345 MODES_PINGPONG | MODES_REVERSE)))
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 DEBUG_MSG(" - Removing loop and/or sustain\n");
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
348 sp->modes &=~(MODES_SUSTAIN | MODES_LOOPING |
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
349 MODES_PINGPONG | MODES_REVERSE);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
350 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
351
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
352 if (strip_envelope==1)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
353 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
354 if (sp->modes & MODES_ENVELOPE)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
355 DEBUG_MSG(" - Removing envelope\n");
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
356 sp->modes &= ~MODES_ENVELOPE;
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 if (strip_envelope != 0)
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 /* Have to make a guess. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
361 if (!(sp->modes & (MODES_LOOPING | MODES_PINGPONG | MODES_REVERSE)))
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 /* No loop? Then what's there to sustain? No envelope needed
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
364 either... */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
365 sp->modes &= ~(MODES_SUSTAIN|MODES_ENVELOPE);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
366 DEBUG_MSG(" - No loop, removing sustain and envelope\n");
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 else if (!memcmp(tmp, "??????", 6) || tmp[11] >= 100)
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 /* Envelope rates all maxed out? Envelope end at a high "offset"?
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
371 That's a weird envelope. Take it out. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
372 sp->modes &= ~MODES_ENVELOPE;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
373 DEBUG_MSG(" - Weirdness, removing envelope\n");
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
374 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
375 else if (!(sp->modes & MODES_SUSTAIN))
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 /* No sustain? Then no envelope. I don't know if this is
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
378 justified, but patches without sustain usually don't need the
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
379 envelope either... at least the Gravis ones. They're mostly
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
380 drums. I think. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
381 sp->modes &= ~MODES_ENVELOPE;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
382 DEBUG_MSG(" - No sustain, removing envelope\n");
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
386 for (j=0; j<6; j++)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
387 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
388 sp->envelope_rate[j]=
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
389 convert_envelope_rate(song, tmp[j]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
390 sp->envelope_offset[j]=
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
391 convert_envelope_offset(tmp[6+j]);
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
394 /* Then read the sample data */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
395 sp->data = safe_malloc(sp->data_length);
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
396 if (1 != vfs_fread(sp->data, sp->data_length, 1, fp))
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
397 goto fail;
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 if (!(sp->modes & MODES_16BIT)) /* convert to 16-bit data */
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 sint32 i=sp->data_length;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
402 uint8 *cp=(uint8 *)(sp->data);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
403 uint16 *tmp,*new;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
404 tmp=new=safe_malloc(sp->data_length*2);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
405 while (i--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
406 *tmp++ = (uint16)(*cp++) << 8;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
407 cp=(uint8 *)(sp->data);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
408 sp->data = (sample_t *)new;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
409 free(cp);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
410 sp->data_length *= 2;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
411 sp->loop_start *= 2;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
412 sp->loop_end *= 2;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
413 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
414 #ifndef LITTLE_ENDIAN
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
415 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
416 /* convert to machine byte order */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
417 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
418 sint32 i=sp->data_length/2;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
419 sint16 *tmp=(sint16 *)sp->data,s;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
420 while (i--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
421 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
422 s=SWAPLE16(*tmp);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
423 *tmp++=s;
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 #endif
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
427
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
428 if (sp->modes & MODES_UNSIGNED) /* convert to signed data */
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 sint32 i=sp->data_length/2;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
431 sint16 *tmp=(sint16 *)sp->data;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
432 while (i--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
433 *tmp++ ^= 0x8000;
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
436 /* Reverse reverse loops and pass them off as normal loops */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
437 if (sp->modes & MODES_REVERSE)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
438 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
439 sint32 t;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
440 /* The GUS apparently plays reverse loops by reversing the
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
441 whole sample. We do the same because the GUS does not SUCK. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
442
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
443 DEBUG_MSG("Reverse loop in %s\n", name);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
444 reverse_data((sint16 *)sp->data, 0, sp->data_length/2);
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 t=sp->loop_start;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
447 sp->loop_start=sp->data_length - sp->loop_end;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
448 sp->loop_end=sp->data_length - t;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
449
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
450 sp->modes &= ~MODES_REVERSE;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
451 sp->modes |= MODES_LOOPING; /* just in case */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
452 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
453
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
454 #ifdef ADJUST_SAMPLE_VOLUMES
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
455 if (amp!=-1)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
456 sp->volume=(float)((amp) / 100.0);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
457 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
458 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
459 /* Try to determine a volume scaling factor for the sample.
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
460 This is a very crude adjustment, but things sound more
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
461 balanced with it. Still, this should be a runtime option. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
462 sint32 i=sp->data_length/2;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
463 sint16 maxamp=0,a;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
464 sint16 *tmp=(sint16 *)sp->data;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
465 while (i--)
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 a=*tmp++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
468 if (a<0) a=-a;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
469 if (a>maxamp)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
470 maxamp=a;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
471 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
472 sp->volume=(float)(32768.0 / maxamp);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
473 DEBUG_MSG(" * volume comp: %f\n", sp->volume);
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
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
476 if (amp!=-1)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
477 sp->volume=(double)(amp) / 100.0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
478 else
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
479 sp->volume=1.0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
480 #endif
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
481
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
482 sp->data_length /= 2; /* These are in bytes. Convert into samples. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
483 sp->loop_start /= 2;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
484 sp->loop_end /= 2;
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 /* Then fractional samples */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
487 sp->data_length <<= FRACTION_BITS;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
488 sp->loop_start <<= FRACTION_BITS;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
489 sp->loop_end <<= FRACTION_BITS;
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 /* Adjust for fractional loop points. This is a guess. Does anyone
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
492 know what "fractions" really stands for? */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
493 sp->loop_start |=
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
494 (fractions & 0x0F) << (FRACTION_BITS-4);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
495 sp->loop_end |=
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
496 ((fractions>>4) & 0x0F) << (FRACTION_BITS-4);
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 /* If this instrument will always be played on the same note,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
499 and it's not looped, we can resample it now. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
500 if (sp->note_to_use && !(sp->modes & MODES_LOOPING))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
501 pre_resample(song, sp);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
502
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
503 if (strip_tail==1)
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 /* Let's not really, just say we did. */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
506 DEBUG_MSG(" - Stripping tail\n");
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
507 sp->data_length = sp->loop_end;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
508 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
509 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
510
480
c1dfb4b13be8 [svn] Use the VFS layer.
chainsaw
parents: 285
diff changeset
511 vfs_fclose(fp);
285
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
512 return ip;
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 static int fill_bank(MidSong *song, int dr, int b)
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 int i, errors=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
518 MidToneBank *bank=((dr) ? song->drumset[b] : song->tonebank[b]);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
519 if (!bank)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
520 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
521 DEBUG_MSG("Huh. Tried to load instruments in non-existent %s %d\n",
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
522 (dr) ? "drumset" : "tone bank", b);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
523 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
524 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
525 for (i=0; i<128; i++)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
526 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
527 if (bank->instrument[i]==MAGIC_LOAD_INSTRUMENT)
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 bank->instrument[i]=load_instrument_dls(song, dr, b, i);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
530 if (bank->instrument[i])
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
531 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
532 continue;
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 if (!(bank->tone[i].name))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
535 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
536 DEBUG_MSG("No instrument mapped to %s %d, program %d%s\n",
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
537 (dr)? "drum set" : "tone bank", b, i,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
538 (b!=0) ? "" : " - this instrument will not be heard");
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
539 if (b!=0)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
540 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
541 /* Mark the corresponding instrument in the default
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
542 bank / drumset for loading (if it isn't already) */
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
543 if (!dr)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
544 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
545 if (!(song->tonebank[0]->instrument[i]))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
546 song->tonebank[0]->instrument[i] =
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
547 MAGIC_LOAD_INSTRUMENT;
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
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 (!(song->drumset[0]->instrument[i]))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
552 song->drumset[0]->instrument[i] =
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
553 MAGIC_LOAD_INSTRUMENT;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
554 }
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 bank->instrument[i] = 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
557 errors++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
558 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
559 else if (!(bank->instrument[i] =
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
560 load_instrument(song,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
561 bank->tone[i].name,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
562 (dr) ? 1 : 0,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
563 bank->tone[i].pan,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
564 bank->tone[i].amp,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
565 (bank->tone[i].note!=-1) ?
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
566 bank->tone[i].note :
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
567 ((dr) ? i : -1),
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
568 (bank->tone[i].strip_loop!=-1) ?
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
569 bank->tone[i].strip_loop :
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
570 ((dr) ? 1 : -1),
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
571 (bank->tone[i].strip_envelope != -1) ?
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
572 bank->tone[i].strip_envelope :
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
573 ((dr) ? 1 : -1),
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
574 bank->tone[i].strip_tail )))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
575 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
576 DEBUG_MSG("Couldn't load instrument %s (%s %d, program %d)\n",
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
577 bank->tone[i].name,
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
578 (dr)? "drum set" : "tone bank", b, i);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
579 errors++;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
580 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
581 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
582 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
583 return errors;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
584 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
585
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
586 int load_missing_instruments(MidSong *song)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
587 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
588 int i=128,errors=0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
589 while (i--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
590 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
591 if (song->tonebank[i])
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
592 errors+=fill_bank(song,0,i);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
593 if (song->drumset[i])
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
594 errors+=fill_bank(song,1,i);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
595 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
596 return errors;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
597 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
598
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
599 void free_instruments(MidSong *song)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
600 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
601 int i=128;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
602 while(i--)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
603 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
604 if (song->tonebank[i])
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
605 free_bank(song, 0, i);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
606 if (song->drumset[i])
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
607 free_bank(song, 1, i);
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
608 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
609 }
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
610
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
611 int set_default_instrument(MidSong *song, char *name)
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
612 {
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
613 MidInstrument *ip;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
614 if (!(ip=load_instrument(song, name, 0, -1, -1, -1, 0, 0, 0)))
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
615 return -1;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
616 song->default_instrument = ip;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
617 song->default_program = SPECIAL_PROGRAM;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
618 return 0;
d1762728ea4b [svn] Timidity support, via external contractor dai+audacious@cdr.jp.
nenolod
parents:
diff changeset
619 }