comparison plugin/plugins/SamplePlayer.cpp @ 143:0f0c9cf65d5e

* Add Hz tuning dial to sample player plugin. Need to figure out the best way to get this passed through from the main program's configuration. * Add ConfigFile class to deal with configuration load/save * Add an organ sample (it's a bit big, though)
author Chris Cannam
date Wed, 26 Jul 2006 15:32:10 +0000
parents c30728d5625c
children a9c3ba1777e1
comparison
equal deleted inserted replaced
142:0ba66b160a02 143:0f0c9cf65d5e
34 SamplePlayer::portNames[PortCount] = 34 SamplePlayer::portNames[PortCount] =
35 { 35 {
36 "Output", 36 "Output",
37 "Tuned (on/off)", 37 "Tuned (on/off)",
38 "Base Pitch (MIDI)", 38 "Base Pitch (MIDI)",
39 "Tuning of A (Hz)",
39 "Sustain (on/off)", 40 "Sustain (on/off)",
40 "Release time (s)" 41 "Release time (s)"
41 }; 42 };
42 43
43 const LADSPA_PortDescriptor 44 const LADSPA_PortDescriptor
56 { 0, 0, 0 }, 57 { 0, 0, 0 },
57 { LADSPA_HINT_DEFAULT_MAXIMUM | LADSPA_HINT_INTEGER | 58 { LADSPA_HINT_DEFAULT_MAXIMUM | LADSPA_HINT_INTEGER |
58 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 1 }, 59 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 1 },
59 { LADSPA_HINT_DEFAULT_MIDDLE | LADSPA_HINT_INTEGER | 60 { LADSPA_HINT_DEFAULT_MIDDLE | LADSPA_HINT_INTEGER |
60 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 120 }, 61 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 120 },
62 { LADSPA_HINT_DEFAULT_440 | LADSPA_HINT_LOGARITHMIC |
63 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 220, 880 },
61 { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_INTEGER | 64 { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_INTEGER |
62 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 1 }, 65 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 1 },
63 { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_LOGARITHMIC | 66 { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_LOGARITHMIC |
64 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0.001, 2.0 } 67 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0.001, 2.0 }
65 }; 68 };
120 123
121 SamplePlayer::SamplePlayer(int sampleRate) : 124 SamplePlayer::SamplePlayer(int sampleRate) :
122 m_output(0), 125 m_output(0),
123 m_retune(0), 126 m_retune(0),
124 m_basePitch(0), 127 m_basePitch(0),
128 m_concertA(0),
125 m_sustain(0), 129 m_sustain(0),
126 m_release(0), 130 m_release(0),
127 m_sampleData(0), 131 m_sampleData(0),
128 m_sampleCount(0), 132 m_sampleCount(0),
129 m_sampleRate(sampleRate), 133 m_sampleRate(sampleRate),
166 170
167 float **ports[PortCount] = { 171 float **ports[PortCount] = {
168 &player->m_output, 172 &player->m_output,
169 &player->m_retune, 173 &player->m_retune,
170 &player->m_basePitch, 174 &player->m_basePitch,
175 &player->m_concertA,
171 &player->m_sustain, 176 &player->m_sustain,
172 &player->m_release 177 &player->m_release
173 }; 178 };
174 179
175 *ports[port] = (float *)location; 180 *ports[port] = (float *)location;
527 } 532 }
528 533
529 void 534 void
530 SamplePlayer::addSample(int n, unsigned long pos, unsigned long count) 535 SamplePlayer::addSample(int n, unsigned long pos, unsigned long count)
531 { 536 {
532 float ratio = 1.0; 537 float ratio = 1.f;
533 float gain = 1.0; 538 float gain = 1.f;
534 unsigned long i, s; 539 unsigned long i, s;
535 540
536 if (m_retune && *m_retune) { 541 if (m_retune && *m_retune) {
542 if (m_concertA) {
543 ratio *= *m_concertA / 440.f;
544 }
537 if (m_basePitch && n != *m_basePitch) { 545 if (m_basePitch && n != *m_basePitch) {
538 ratio = powf(1.059463094, n - *m_basePitch); 546 ratio *= powf(1.059463094f, n - *m_basePitch);
539 } 547 }
540 } 548 }
541 549
542 if (long(pos + m_sampleNo) < m_ons[n]) return; 550 if (long(pos + m_sampleNo) < m_ons[n]) return;
543 551