/usr/share/sfront/reson/marimba.hs is in sfront 0.99-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | ///////////////////////////////////////////////////////////////////////////////
//
// SAOL Resonator-Based Physical Model Library
// This file: Marimba bars
//
// Copyright (c) 1999-2006, Regents of the University of California
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// Neither the name of the University of California, Berkeley nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Original Author: John Wawrzynek
// Maintainer: John Lazzaro, lazzaro@cs.berkeley.edu
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// To use library in your SAOL program:
//
// [1] If you want to choose a MIDI preset number (say, 30):
//
// #define MARIMBA_MIDIPRESET 30
//
// If MARIMBA_MIDIPRESET is not set, it preset number of 30 is
// chosen. To specify that the instrument is not a MIDI
// instrument, define MARIMBA_NOMIDIPRESET
//
// [2] Include the library, as
//
// #include <reson/marimba.hs>
//
// [3] The instrument marimba_audio generates the audio output for
// the instrument: use this name in route statements.
//
// [4] The instrument marimba_kbd handles new note generation. For
// MIDI control, just set MIDI NoteOn commands to the preset
// selected by MARIMBA_MIDIPRESET. For SASL or dynamic control,
// call this instr:
//
// instr marimba_kbd(pitch, velocity)
//
// Where pitch is a MIDI note numbers, and velocity is a
// MIDI note-on velocity value (range 0-127). This instr
// should be called with duration of -1.
//
// [5] The instr doesn't set a srate or krate, so you can do
// it in your own global block. These parameters are
// recommended for sfront real-time control:
//
// srate 44100;
// krate 1000;
//
//
// [6] Two optional parameters set the real-time polyphonic
// limits of the instrument. If these aren't defined by
// the user, the defaults are set to be good for rendering
// arbitrary polyphony in an accurate way.
//
// MARIMBA_POLYPHONY The maximum number of notes at
// one time. Note that since the
// instrument models the bar itself,
// any number of hits on a single bar
// counts as one note. Typical numbers
// for real-time performance on a 450MHz
// PIII is 2-3.
//
// MARIMBA_INAUDIBLE A constant that codes the softest sound
// that is audible. Higher values release
// slots for new notes sooner, but clip off
// the end of the ringing. A good starting
// point is 1e-4.
//
// There parameter are set in a manner identical to
// MARIMBA_MIDIPRESET as shown in [1].
//
///////////////////////////////////////////////////////////////////////////////
#ifndef RESON_MARIMBA
#define RESON_MARIMBA
#include <Slib/ssm.hs>
#include <Slib/std.hs>
///////////////////////////////////////////////////////////////////////////////
//
//
// Pre-processor defines for user preferences
//
//
// parses user preferences
#if MARIMBA_NOMIDIPRESET
#define RESON_PRESET
#else
#ifdef MARIMBA_MIDIPRESET
#define RESON_PRESET preset MARIMBA_MIDIPRESET
#else
#define RESON_PRESET preset 0
#endif
#endif
// Inaudible rms value
#ifdef MARIMBA_INAUDIBLE
#define RESON_INAUDIBLE MARIMBA_INAUDIBLE
#else
#define RESON_INAUDIBLE 1e-5
#endif
// Number of simultaneous notes
#ifdef MARIMBA_POLYPHONY
#define RESON_POLYPHONY MARIMBA_POLYPHONY
#else
#define RESON_POLYPHONY 128
#endif
//
// Pre-processor defines for internal constants
//
//
// Macros that generates unique global names
#define RESON_SC(x) marimba_ ## x
// Number of resonators in the model
#define RESON_RESNUM 3
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// Distributed global block for scaling prototype bar
//
global {
// hand-tuned version of qscale = 0.0551223*exp(0.0579087*x) for q scaling
table RESON_SC(qscale)(expseg, -1, 0, 0.5*0.0551223,
128, 0.5*0.0551223*exp(0.0579087*128));
// implements gscale = 0.004*(1/223.066)*exp(0.0813501*x) for g scaling
table RESON_SC(gscale)(expseg, -1, 0, 0.004*(1/223.066), 128,
0.004*(1/223.066)*exp(0.0813501*128));
}
///////////////////////////////////////////////////////////////////////////////
//
// The resinit iopcode initializes the resonance model for the thing being
// struck or plucked.
//
iopcode RESON_SC(resinit) (ivar a[RESON_RESNUM], ivar b[RESON_RESNUM],
ivar g[RESON_RESNUM], ivar notenum)
{
ivar r[RESON_RESNUM], freq[RESON_RESNUM], q[RESON_RESNUM];
ivar j, scale, norm;
imports exports table RESON_SC(qscale);
imports exports table RESON_SC(gscale);
// set f/q/g for prototype bar
norm = tableread(RESON_SC(qscale), int(notenum + 12));
scale = cpsmidi(notenum + 12)/CPS_MIDDLEC;
freq[0] = 261.63*scale; q[0] = 240*norm;
freq[1] = 1041.29*scale; q[1] = 200*norm;
freq[2] = 2616.30*scale; q[2] = 150*norm;
norm = tableread(RESON_SC(gscale), int(notenum+12));
g[0] = (freq[0] < s_rate/2) ? norm : 0.0;
g[1] = (freq[1] < s_rate/2) ? norm : 0.0;
g[2] = (freq[2] < s_rate/2) ? norm : 0.0;
// Compute actual resonator coefficients
//
// (Doesn't need changing for new models).
j = 0;
while ( j < RESON_RESNUM)
{
r[j] = exp(-freq[j]/(s_rate*q[j]));
a[j] = 2*r[j]*cos(2*PI*(freq[j]/s_rate));
b[j] = - r[j]*r[j];
j = j + 1;
}
}
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// The strikeinit iopcode initializes the striker model.
iopcode RESON_SC(strikeinit)(ivar aa, ivar ab, ivar sg, ivar vw,
ivar vwn, ivar notenum)
{
ivar ar, afreq;
afreq = 261.63; // attack resonator frequency
// Compute resonator bank coefficients
ar = exp(-2*PI*(afreq/s_rate));
aa = 2*ar;
ab = -ar*ar;
vw = MIDI_SCALE; // keyboard normalization curve
sg = 0.0025; // "signal gain" empirical constant (should not scale).
vwn = 0.01; // velocity scaling for nm
}
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// all code common to the structured resonator family
#include <reson/sreson.hs>
#undef RESON_RESNUM
#undef RESON_INAUDIBLE
#undef RESON_POLYPHONY
#undef RESON_PRESET
#undef RESON_SC
//
///////////////////////////////////////////////////////////////////////////////
#endif
|