Mercurial > hg > svcore
comparison plugin/plugins/SamplePlayer.cpp @ 847:2d53205f70cd tonioni
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 26 Nov 2013 14:37:01 +0000 |
parents | 2fa49f5caac5 a299c4cec0f8 |
children | b14064bd1f97 |
comparison
equal
deleted
inserted
replaced
841:226733f3cf3f | 847:2d53205f70cd |
---|---|
364 | 364 |
365 m_samples.clear(); | 365 m_samples.clear(); |
366 | 366 |
367 #ifdef DEBUG_SAMPLE_PLAYER | 367 #ifdef DEBUG_SAMPLE_PLAYER |
368 SVDEBUG << "SamplePlayer::searchSamples: Directory is \"" | 368 SVDEBUG << "SamplePlayer::searchSamples: Directory is \"" |
369 << m_sampleDir.toLocal8Bit().data() << "\"" << endl; | 369 << m_sampleDir << "\"" << endl; |
370 #endif | 370 #endif |
371 | 371 |
372 QDir dir(m_sampleDir, "*.wav"); | 372 QDir dir(m_sampleDir, "*.wav"); |
373 | 373 |
374 for (unsigned int i = 0; i < dir.count(); ++i) { | 374 for (unsigned int i = 0; i < dir.count(); ++i) { |
375 QFileInfo file(dir.filePath(dir[i])); | 375 QFileInfo file(dir.filePath(dir[i])); |
376 if (file.isReadable()) { | 376 if (file.isReadable()) { |
377 m_samples.push_back(std::pair<QString, QString> | 377 m_samples.push_back(std::pair<QString, QString> |
378 (file.baseName(), file.filePath())); | 378 (file.baseName(), file.filePath())); |
379 #ifdef DEBUG_SAMPLE_PLAYER | 379 #ifdef DEBUG_SAMPLE_PLAYER |
380 std::cerr << "Found: " << dir[i].toLocal8Bit().data() << std::endl; | 380 cerr << "Found: " << dir[i] << endl; |
381 #endif | 381 #endif |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
385 m_sampleSearchComplete = true; | 385 m_sampleSearchComplete = true; |
395 size_t i; | 395 size_t i; |
396 | 396 |
397 info.format = 0; | 397 info.format = 0; |
398 file = sf_open(path.toLocal8Bit().data(), SFM_READ, &info); | 398 file = sf_open(path.toLocal8Bit().data(), SFM_READ, &info); |
399 if (!file) { | 399 if (!file) { |
400 std::cerr << "SamplePlayer::loadSampleData: Failed to open file " | 400 cerr << "SamplePlayer::loadSampleData: Failed to open file " |
401 << path.toLocal8Bit().data() << ": " | 401 << path << ": " |
402 << sf_strerror(file) << std::endl; | 402 << sf_strerror(file) << endl; |
403 return; | 403 return; |
404 } | 404 } |
405 | 405 |
406 samples = info.frames; | 406 samples = info.frames; |
407 tmpFrames = (float *)malloc(info.frames * info.channels * sizeof(float)); | 407 tmpFrames = (float *)malloc(info.frames * info.channels * sizeof(float)); |
503 while (event_pos < eventCount | 503 while (event_pos < eventCount |
504 && pos >= events[event_pos].time.tick) { | 504 && pos >= events[event_pos].time.tick) { |
505 | 505 |
506 if (events[event_pos].type == SND_SEQ_EVENT_NOTEON) { | 506 if (events[event_pos].type == SND_SEQ_EVENT_NOTEON) { |
507 #ifdef DEBUG_SAMPLE_PLAYER | 507 #ifdef DEBUG_SAMPLE_PLAYER |
508 std::cerr << "SamplePlayer: found NOTEON at time " | 508 cerr << "SamplePlayer: found NOTEON at time " |
509 << events[event_pos].time.tick << std::endl; | 509 << events[event_pos].time.tick << endl; |
510 #endif | 510 #endif |
511 snd_seq_ev_note_t n = events[event_pos].data.note; | 511 snd_seq_ev_note_t n = events[event_pos].data.note; |
512 if (n.velocity > 0) { | 512 if (n.velocity > 0) { |
513 m_ons[n.note] = | 513 m_ons[n.note] = |
514 m_sampleNo + events[event_pos].time.tick; | 514 m_sampleNo + events[event_pos].time.tick; |
521 } | 521 } |
522 } | 522 } |
523 } else if (events[event_pos].type == SND_SEQ_EVENT_NOTEOFF && | 523 } else if (events[event_pos].type == SND_SEQ_EVENT_NOTEOFF && |
524 (!m_sustain || (*m_sustain < 0.001))) { | 524 (!m_sustain || (*m_sustain < 0.001))) { |
525 #ifdef DEBUG_SAMPLE_PLAYER | 525 #ifdef DEBUG_SAMPLE_PLAYER |
526 std::cerr << "SamplePlayer: found NOTEOFF at time " | 526 cerr << "SamplePlayer: found NOTEOFF at time " |
527 << events[event_pos].time.tick << std::endl; | 527 << events[event_pos].time.tick << endl; |
528 #endif | 528 #endif |
529 snd_seq_ev_note_t n = events[event_pos].data.note; | 529 snd_seq_ev_note_t n = events[event_pos].data.note; |
530 m_offs[n.note] = | 530 m_offs[n.note] = |
531 m_sampleNo + events[event_pos].time.tick; | 531 m_sampleNo + events[event_pos].time.tick; |
532 } | 532 } |
548 addSample(i, pos, count); | 548 addSample(i, pos, count); |
549 } | 549 } |
550 } | 550 } |
551 | 551 |
552 #ifdef DEBUG_SAMPLE_PLAYER | 552 #ifdef DEBUG_SAMPLE_PLAYER |
553 std::cerr << "SamplePlayer: have " << notecount << " note(s) sounding currently" << std::endl; | 553 cerr << "SamplePlayer: have " << notecount << " note(s) sounding currently" << endl; |
554 #endif | 554 #endif |
555 | 555 |
556 pos += count; | 556 pos += count; |
557 } | 557 } |
558 | 558 |
588 float rs = s * ratio; | 588 float rs = s * ratio; |
589 unsigned long rsi = lrintf(floor(rs)); | 589 unsigned long rsi = lrintf(floor(rs)); |
590 | 590 |
591 if (rsi >= m_sampleCount) { | 591 if (rsi >= m_sampleCount) { |
592 #ifdef DEBUG_SAMPLE_PLAYER | 592 #ifdef DEBUG_SAMPLE_PLAYER |
593 std::cerr << "Note " << n << " has run out of samples (were " << m_sampleCount << " available at ratio " << ratio << "), ending" << std::endl; | 593 cerr << "Note " << n << " has run out of samples (were " << m_sampleCount << " available at ratio " << ratio << "), ending" << endl; |
594 #endif | 594 #endif |
595 m_ons[n] = -1; | 595 m_ons[n] = -1; |
596 break; | 596 break; |
597 } | 597 } |
598 | 598 |
607 releaseFrames = long(*m_release * m_sampleRate + 0.0001); | 607 releaseFrames = long(*m_release * m_sampleRate + 0.0001); |
608 } | 608 } |
609 | 609 |
610 if (dist > releaseFrames) { | 610 if (dist > releaseFrames) { |
611 #ifdef DEBUG_SAMPLE_PLAYER | 611 #ifdef DEBUG_SAMPLE_PLAYER |
612 std::cerr << "Note " << n << " has expired its release time (" << releaseFrames << " frames), ending" << std::endl; | 612 cerr << "Note " << n << " has expired its release time (" << releaseFrames << " frames), ending" << endl; |
613 #endif | 613 #endif |
614 m_ons[n] = -1; | 614 m_ons[n] = -1; |
615 break; | 615 break; |
616 } else { | 616 } else { |
617 lgain = lgain * (float)(releaseFrames - dist) / | 617 lgain = lgain * (float)(releaseFrames - dist) / |