comparison plugin/plugins/SamplePlayer.cpp @ 1039:b14064bd1f97 cxx11

This code now compiles. Main problem: sample rate types
author Chris Cannam
date Tue, 03 Mar 2015 17:09:19 +0000
parents 2d53205f70cd
children 63b73a21bccd
comparison
equal deleted inserted replaced
1038:cc27f35aa75c 1039:b14064bd1f97
67 { LADSPA_HINT_DEFAULT_440 | LADSPA_HINT_LOGARITHMIC | 67 { LADSPA_HINT_DEFAULT_440 | LADSPA_HINT_LOGARITHMIC |
68 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 400, 499 }, 68 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 400, 499 },
69 { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_INTEGER | 69 { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_INTEGER |
70 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 1 }, 70 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 1 },
71 { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_LOGARITHMIC | 71 { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_LOGARITHMIC |
72 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0.001, 2.0 } 72 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0.001f, 2.0f }
73 }; 73 };
74 74
75 const LADSPA_Properties 75 const LADSPA_Properties
76 SamplePlayer::properties = LADSPA_PROPERTY_HARD_RT_CAPABLE; 76 SamplePlayer::properties = LADSPA_PROPERTY_HARD_RT_CAPABLE;
77 77
154 if (!hostDescriptor || !hostDescriptor->request_non_rt_thread) { 154 if (!hostDescriptor || !hostDescriptor->request_non_rt_thread) {
155 SVDEBUG << "SamplePlayer::instantiate: Host does not provide request_non_rt_thread, not instantiating" << endl; 155 SVDEBUG << "SamplePlayer::instantiate: Host does not provide request_non_rt_thread, not instantiating" << endl;
156 return 0; 156 return 0;
157 } 157 }
158 158
159 SamplePlayer *player = new SamplePlayer(rate); 159 SamplePlayer *player = new SamplePlayer(int(rate));
160 // std::cerr << "Instantiated sample player " << std::endl; 160 // std::cerr << "Instantiated sample player " << std::endl;
161 161
162 if (hostDescriptor->request_non_rt_thread(player, workThreadCallback)) { 162 if (hostDescriptor->request_non_rt_thread(player, workThreadCallback)) {
163 SVDEBUG << "SamplePlayer::instantiate: Host rejected request_non_rt_thread call, not instantiating" << endl; 163 SVDEBUG << "SamplePlayer::instantiate: Host rejected request_non_rt_thread call, not instantiating" << endl;
164 delete player; 164 delete player;
280 SamplePlayer::selectProgram(LADSPA_Handle handle, 280 SamplePlayer::selectProgram(LADSPA_Handle handle,
281 unsigned long, 281 unsigned long,
282 unsigned long program) 282 unsigned long program)
283 { 283 {
284 SamplePlayer *player = (SamplePlayer *)handle; 284 SamplePlayer *player = (SamplePlayer *)handle;
285 player->m_pendingProgramChange = program; 285 player->m_pendingProgramChange = (int)program;
286 } 286 }
287 287
288 int 288 int
289 SamplePlayer::getMidiController(LADSPA_Handle, unsigned long port) 289 SamplePlayer::getMidiController(LADSPA_Handle, unsigned long port)
290 { 290 {
413 tmpResamples = 0; 413 tmpResamples = 0;
414 414
415 if (info.samplerate != m_sampleRate) { 415 if (info.samplerate != m_sampleRate) {
416 416
417 double ratio = (double)m_sampleRate / (double)info.samplerate; 417 double ratio = (double)m_sampleRate / (double)info.samplerate;
418 size_t target = (size_t)(info.frames * ratio); 418 size_t target = (size_t)(double(info.frames) * ratio);
419 SRC_DATA data; 419 SRC_DATA data;
420 420
421 tmpResamples = (float *)malloc(target * info.channels * sizeof(float)); 421 tmpResamples = (float *)malloc(target * info.channels * sizeof(float));
422 if (!tmpResamples) { 422 if (!tmpResamples) {
423 free(tmpFrames); 423 free(tmpFrames);
570 if (m_retune && *m_retune) { 570 if (m_retune && *m_retune) {
571 if (m_concertA) { 571 if (m_concertA) {
572 ratio *= *m_concertA / 440.f; 572 ratio *= *m_concertA / 440.f;
573 } 573 }
574 if (m_basePitch && n != *m_basePitch) { 574 if (m_basePitch && n != *m_basePitch) {
575 ratio *= powf(1.059463094f, n - *m_basePitch); 575 ratio *= powf(1.059463094f, float(n) - *m_basePitch);
576 } 576 }
577 } 577 }
578 578
579 if (long(pos + m_sampleNo) < m_ons[n]) return; 579 if (long(pos + m_sampleNo) < m_ons[n]) return;
580 580
583 for (i = 0, s = pos + m_sampleNo - m_ons[n]; 583 for (i = 0, s = pos + m_sampleNo - m_ons[n];
584 i < count; 584 i < count;
585 ++i, ++s) { 585 ++i, ++s) {
586 586
587 float lgain = gain; 587 float lgain = gain;
588 float rs = s * ratio; 588 float rs = float(s) * ratio;
589 unsigned long rsi = lrintf(floor(rs)); 589 unsigned long rsi = lrintf(floorf(rs));
590 590
591 if (rsi >= m_sampleCount) { 591 if (rsi >= m_sampleCount) {
592 #ifdef DEBUG_SAMPLE_PLAYER 592 #ifdef DEBUG_SAMPLE_PLAYER
593 cerr << "Note " << n << " has run out of samples (were " << m_sampleCount << " available at ratio " << ratio << "), ending" << endl; 593 cerr << "Note " << n << " has run out of samples (were " << m_sampleCount << " available at ratio " << ratio << "), ending" << endl;
594 #endif 594 #endif
602 unsigned long dist = 602 unsigned long dist =
603 pos + i + m_sampleNo - m_offs[n]; 603 pos + i + m_sampleNo - m_offs[n];
604 604
605 unsigned long releaseFrames = 200; 605 unsigned long releaseFrames = 200;
606 if (m_release) { 606 if (m_release) {
607 releaseFrames = long(*m_release * m_sampleRate + 0.0001); 607 releaseFrames = long(*m_release * float(m_sampleRate) + 0.0001f);
608 } 608 }
609 609
610 if (dist > releaseFrames) { 610 if (dist > releaseFrames) {
611 #ifdef DEBUG_SAMPLE_PLAYER 611 #ifdef DEBUG_SAMPLE_PLAYER
612 cerr << "Note " << n << " has expired its release time (" << releaseFrames << " frames), ending" << endl; 612 cerr << "Note " << n << " has expired its release time (" << releaseFrames << " frames), ending" << endl;