comparison audioio/AudioGenerator.cpp @ 382:2484e6f95c06

Small fixes: avoid static etc
author Chris Cannam
date Thu, 17 Jul 2014 16:22:54 +0100
parents 0876ea394902
children f747be6743ab
comparison
equal deleted inserted replaced
381:71090a49d487 382:2484e6f95c06
47 47
48 AudioGenerator::AudioGenerator() : 48 AudioGenerator::AudioGenerator() :
49 m_sourceSampleRate(0), 49 m_sourceSampleRate(0),
50 m_targetChannelCount(1), 50 m_targetChannelCount(1),
51 m_waveType(0), 51 m_waveType(0),
52 m_soloing(false) 52 m_soloing(false),
53 m_channelBuffer(0),
54 m_channelBufSiz(0),
55 m_channelBufCount(0)
53 { 56 {
54 initialiseSampleDir(); 57 initialiseSampleDir();
55 58
56 connect(PlayParameterRepository::getInstance(), 59 connect(PlayParameterRepository::getInstance(),
57 SIGNAL(playClipIdChanged(const Playable *, QString)), 60 SIGNAL(playClipIdChanged(const Playable *, QString)),
392 AudioGenerator::mixDenseTimeValueModel(DenseTimeValueModel *dtvm, 395 AudioGenerator::mixDenseTimeValueModel(DenseTimeValueModel *dtvm,
393 int startFrame, int frames, 396 int startFrame, int frames,
394 float **buffer, float gain, float pan, 397 float **buffer, float gain, float pan,
395 int fadeIn, int fadeOut) 398 int fadeIn, int fadeOut)
396 { 399 {
397 static float **channelBuffer = 0; 400 int maxFrames = frames + std::max(fadeIn, fadeOut);
398 static int channelBufSiz = 0;
399 static int channelBufCount = 0;
400
401 int totalFrames = frames + fadeIn/2 + fadeOut/2;
402 401
403 int modelChannels = dtvm->getChannelCount(); 402 int modelChannels = dtvm->getChannelCount();
404 403
405 if (channelBufSiz < totalFrames || channelBufCount < modelChannels) { 404 if (m_channelBufSiz < maxFrames || m_channelBufCount < modelChannels) {
406 405
407 for (int c = 0; c < channelBufCount; ++c) { 406 for (int c = 0; c < m_channelBufCount; ++c) {
408 delete[] channelBuffer[c]; 407 delete[] m_channelBuffer[c];
409 } 408 }
410 409
411 delete[] channelBuffer; 410 delete[] m_channelBuffer;
412 channelBuffer = new float *[modelChannels]; 411 m_channelBuffer = new float *[modelChannels];
413 412
414 for (int c = 0; c < modelChannels; ++c) { 413 for (int c = 0; c < modelChannels; ++c) {
415 channelBuffer[c] = new float[totalFrames]; 414 m_channelBuffer[c] = new float[maxFrames];
416 } 415 }
417 416
418 channelBufCount = modelChannels; 417 m_channelBufCount = modelChannels;
419 channelBufSiz = totalFrames; 418 m_channelBufSiz = maxFrames;
420 } 419 }
421 420
422 int got = 0; 421 int got = 0;
423 422
424 if (startFrame >= fadeIn/2) { 423 if (startFrame >= fadeIn/2) {
425 got = dtvm->getData(0, modelChannels - 1, 424 got = dtvm->getData(0, modelChannels - 1,
426 startFrame - fadeIn/2, 425 startFrame - fadeIn/2,
427 frames + fadeOut/2 + fadeIn/2, 426 frames + fadeOut/2 + fadeIn/2,
428 channelBuffer); 427 m_channelBuffer);
429 } else { 428 } else {
430 int missing = fadeIn/2 - startFrame; 429 int missing = fadeIn/2 - startFrame;
431 430
432 for (int c = 0; c < modelChannels; ++c) { 431 for (int c = 0; c < modelChannels; ++c) {
433 channelBuffer[c] += missing; 432 m_channelBuffer[c] += missing;
433 }
434
435 if (missing > 0) {
436 cerr << "note: channelBufSiz = " << m_channelBufSiz
437 << ", frames + fadeOut/2 = " << frames + fadeOut/2
438 << ", startFrame = " << startFrame
439 << ", missing = " << missing << endl;
434 } 440 }
435 441
436 got = dtvm->getData(0, modelChannels - 1, 442 got = dtvm->getData(0, modelChannels - 1,
437 startFrame, 443 startFrame,
438 frames + fadeOut/2, 444 frames + fadeOut/2,
439 channelBuffer); 445 m_channelBuffer);
440 446
441 for (int c = 0; c < modelChannels; ++c) { 447 for (int c = 0; c < modelChannels; ++c) {
442 channelBuffer[c] -= missing; 448 m_channelBuffer[c] -= missing;
443 } 449 }
444 450
445 got += missing; 451 got += missing;
446 } 452 }
447 453
461 } 467 }
462 468
463 for (int i = 0; i < fadeIn/2; ++i) { 469 for (int i = 0; i < fadeIn/2; ++i) {
464 float *back = buffer[c]; 470 float *back = buffer[c];
465 back -= fadeIn/2; 471 back -= fadeIn/2;
466 back[i] += (channelGain * channelBuffer[sourceChannel][i] * i) / fadeIn; 472 back[i] += (channelGain * m_channelBuffer[sourceChannel][i] * i) / fadeIn;
467 } 473 }
468 474
469 for (int i = 0; i < frames + fadeOut/2; ++i) { 475 for (int i = 0; i < frames + fadeOut/2; ++i) {
470 float mult = channelGain; 476 float mult = channelGain;
471 if (i < fadeIn/2) { 477 if (i < fadeIn/2) {
472 mult = (mult * i) / fadeIn; 478 mult = (mult * i) / fadeIn;
473 } 479 }
474 if (i > frames - fadeOut/2) { 480 if (i > frames - fadeOut/2) {
475 mult = (mult * ((frames + fadeOut/2) - i)) / fadeOut; 481 mult = (mult * ((frames + fadeOut/2) - i)) / fadeOut;
476 } 482 }
477 float val = channelBuffer[sourceChannel][i]; 483 float val = m_channelBuffer[sourceChannel][i];
478 if (i >= got) val = 0.f; 484 if (i >= got) val = 0.f;
479 buffer[c][i] += mult * val; 485 buffer[c][i] += mult * val;
480 } 486 }
481 } 487 }
482 488