comparison plugin/plugins/SamplePlayer.cpp @ 1599:ce185d4dd408 bqaudiostream

Merge from default branch
author Chris Cannam
date Wed, 23 Jan 2019 14:43:43 +0000
parents 70e172e6cc59
children
comparison
equal deleted inserted replaced
1598:d2555df635ec 1599:ce185d4dd408
91 "GPL", // Copyright 91 "GPL", // Copyright
92 PortCount, 92 PortCount,
93 ports, 93 ports,
94 portNames, 94 portNames,
95 hints, 95 hints,
96 0, // Implementation data 96 nullptr, // Implementation data
97 instantiate, 97 instantiate,
98 connectPort, 98 connectPort,
99 activate, 99 activate,
100 run, 100 run,
101 0, // Run adding 101 nullptr, // Run adding
102 0, // Set run adding gain 102 nullptr, // Set run adding gain
103 deactivate, 103 deactivate,
104 cleanup 104 cleanup
105 }; 105 };
106 106
107 const DSSI_Descriptor 107 const DSSI_Descriptor
112 configure, 112 configure,
113 getProgram, 113 getProgram,
114 selectProgram, 114 selectProgram,
115 getMidiController, 115 getMidiController,
116 runSynth, 116 runSynth,
117 0, // Run synth adding 117 nullptr, // Run synth adding
118 0, // Run multiple synths 118 nullptr, // Run multiple synths
119 0, // Run multiple synths adding 119 nullptr, // Run multiple synths adding
120 receiveHostDescriptor 120 receiveHostDescriptor
121 }; 121 };
122 122
123 const DSSI_Host_Descriptor * 123 const DSSI_Host_Descriptor *
124 SamplePlayer::hostDescriptor = 0; 124 SamplePlayer::hostDescriptor = nullptr;
125 125
126 126
127 const DSSI_Descriptor * 127 const DSSI_Descriptor *
128 SamplePlayer::getDescriptor(unsigned long index) 128 SamplePlayer::getDescriptor(unsigned long index)
129 { 129 {
130 if (index == 0) return &dssiDescriptor; 130 if (index == 0) return &dssiDescriptor;
131 return 0; 131 return nullptr;
132 } 132 }
133 133
134 SamplePlayer::SamplePlayer(int sampleRate) : 134 SamplePlayer::SamplePlayer(int sampleRate) :
135 m_output(0), 135 m_output(nullptr),
136 m_retune(0), 136 m_retune(nullptr),
137 m_basePitch(0), 137 m_basePitch(nullptr),
138 m_concertA(0), 138 m_concertA(nullptr),
139 m_sustain(0), 139 m_sustain(nullptr),
140 m_release(0), 140 m_release(nullptr),
141 m_sampleData(0), 141 m_sampleData(nullptr),
142 m_sampleCount(0), 142 m_sampleCount(0),
143 m_sampleRate(sampleRate), 143 m_sampleRate(sampleRate),
144 m_sampleNo(0), 144 m_sampleNo(0),
145 m_sampleDir("samples"), 145 m_sampleDir("samples"),
146 m_sampleSearchComplete(false), 146 m_sampleSearchComplete(false),
156 LADSPA_Handle 156 LADSPA_Handle
157 SamplePlayer::instantiate(const LADSPA_Descriptor *, unsigned long rate) 157 SamplePlayer::instantiate(const LADSPA_Descriptor *, unsigned long rate)
158 { 158 {
159 if (!hostDescriptor || !hostDescriptor->request_non_rt_thread) { 159 if (!hostDescriptor || !hostDescriptor->request_non_rt_thread) {
160 SVDEBUG << "SamplePlayer::instantiate: Host does not provide request_non_rt_thread, not instantiating" << endl; 160 SVDEBUG << "SamplePlayer::instantiate: Host does not provide request_non_rt_thread, not instantiating" << endl;
161 return 0; 161 return nullptr;
162 } 162 }
163 163
164 SamplePlayer *player = new SamplePlayer(int(rate)); 164 SamplePlayer *player = new SamplePlayer(int(rate));
165 // std::cerr << "Instantiated sample player " << std::endl; 165 // std::cerr << "Instantiated sample player " << std::endl;
166 166
167 if (hostDescriptor->request_non_rt_thread(player, workThreadCallback)) { 167 if (hostDescriptor->request_non_rt_thread(player, workThreadCallback)) {
168 SVDEBUG << "SamplePlayer::instantiate: Host rejected request_non_rt_thread call, not instantiating" << endl; 168 SVDEBUG << "SamplePlayer::instantiate: Host rejected request_non_rt_thread call, not instantiating" << endl;
169 delete player; 169 delete player;
170 return 0; 170 return nullptr;
171 } 171 }
172 172
173 return player; 173 return player;
174 } 174 }
175 175
207 } 207 }
208 208
209 void 209 void
210 SamplePlayer::run(LADSPA_Handle handle, unsigned long samples) 210 SamplePlayer::run(LADSPA_Handle handle, unsigned long samples)
211 { 211 {
212 runSynth(handle, samples, 0, 0); 212 runSynth(handle, samples, nullptr, 0);
213 } 213 }
214 214
215 void 215 void
216 SamplePlayer::deactivate(LADSPA_Handle handle) 216 SamplePlayer::deactivate(LADSPA_Handle handle)
217 { 217 {
241 if (player->m_sampleSearchComplete) { 241 if (player->m_sampleSearchComplete) {
242 player->m_sampleSearchComplete = false; 242 player->m_sampleSearchComplete = false;
243 player->searchSamples(); 243 player->searchSamples();
244 } 244 }
245 245
246 return 0; 246 return nullptr;
247 247
248 } else { 248 } else {
249 char *buffer = (char *)malloc(strlen(value) + 80); 249 char *buffer = (char *)malloc(strlen(value) + 80);
250 sprintf(buffer, "Sample directory \"%s\" does not exist, leaving unchanged", value); 250 sprintf(buffer, "Sample directory \"%s\" does not exist, leaving unchanged", value);
251 return buffer; 251 return buffer;
264 QMutexLocker locker(&player->m_mutex); 264 QMutexLocker locker(&player->m_mutex);
265 if (!player->m_sampleSearchComplete) { 265 if (!player->m_sampleSearchComplete) {
266 player->searchSamples(); 266 player->searchSamples();
267 } 267 }
268 } 268 }
269 if (program >= player->m_samples.size()) return 0; 269 if (program >= player->m_samples.size()) return nullptr;
270 270
271 static DSSI_Program_Descriptor descriptor; 271 static DSSI_Program_Descriptor descriptor;
272 static char name[60]; 272 static char name[60];
273 273
274 strncpy(name, player->m_samples[program].first.toLocal8Bit().data(), 59); 274 strncpy(name, player->m_samples[program].first.toLocal8Bit().data(), 59);
417 if (!tmpFrames) return; 417 if (!tmpFrames) return;
418 418
419 sf_readf_float(file, tmpFrames, info.frames); 419 sf_readf_float(file, tmpFrames, info.frames);
420 sf_close(file); 420 sf_close(file);
421 421
422 tmpResamples = 0; 422 tmpResamples = nullptr;
423 423
424 if (info.samplerate != m_sampleRate) { 424 if (info.samplerate != m_sampleRate) {
425 425
426 double ratio = (double)m_sampleRate / (double)info.samplerate; 426 double ratio = (double)m_sampleRate / (double)info.samplerate;
427 size_t target = (size_t)(double(info.frames) * ratio); 427 size_t target = (size_t)(double(info.frames) * ratio);