Mercurial > hg > svapp
diff audioio/AudioGenerator.cpp @ 450:d9d132c0e240 alignment_view
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:21:32 +0100 |
parents | c48bc6ddfe17 |
children | 3485d324c172 |
line wrap: on
line diff
--- a/audioio/AudioGenerator.cpp Fri Nov 28 10:33:25 2014 +0000 +++ b/audioio/AudioGenerator.cpp Mon Apr 20 09:21:32 2015 +0100 @@ -37,7 +37,7 @@ #include <QDir> #include <QFile> -const int +const sv_frame_t AudioGenerator::m_processingBlockSize = 1024; QString @@ -124,12 +124,20 @@ } } + const Playable *playable = model; + if (!playable || !playable->canPlay()) return 0; + + PlayParameters *parameters = + PlayParameterRepository::getInstance()->getPlayParameters(playable); + + bool willPlay = !parameters->isPlayMuted(); + if (usesClipMixer(model)) { ClipMixer *mixer = makeClipMixerFor(model); if (mixer) { QMutexLocker locker(&m_mutex); m_clipMixerMap[model] = mixer; - return true; + return willPlay; } } @@ -138,7 +146,7 @@ if (synth) { QMutexLocker locker(&m_mutex); m_continuousSynthMap[model] = synth; - return true; + return willPlay; } } @@ -209,7 +217,9 @@ clipId = parameters->getPlayClipId(); } +#ifdef DEBUG_AUDIO_GENERATOR std::cerr << "AudioGenerator::makeClipMixerFor(" << model << "): sample id = " << clipId << std::endl; +#endif if (clipId == "") { SVDEBUG << "AudioGenerator::makeClipMixerFor(" << model << "): no sample, skipping" << endl; @@ -220,17 +230,19 @@ m_sourceSampleRate, m_processingBlockSize); - float clipF0 = Pitch::getFrequencyForPitch(60, 0, 440.0f); // required + double clipF0 = Pitch::getFrequencyForPitch(60, 0, 440.0); // required QString clipPath = QString("%1/%2.wav").arg(m_sampleDir).arg(clipId); - float level = wantsQuieterClips(model) ? 0.5 : 1.0; + double level = wantsQuieterClips(model) ? 0.5 : 1.0; if (!mixer->loadClipData(clipPath, clipF0, level)) { delete mixer; return 0; } +#ifdef DEBUG_AUDIO_GENERATOR std::cerr << "AudioGenerator::makeClipMixerFor(" << model << "): loaded clip " << clipId << std::endl; +#endif return mixer; } @@ -246,7 +258,9 @@ m_processingBlockSize, m_waveType); +#ifdef DEBUG_AUDIO_GENERATOR std::cerr << "AudioGenerator::makeSynthFor(" << model << "): created synth" << std::endl; +#endif return synth; } @@ -284,7 +298,9 @@ { QMutexLocker locker(&m_mutex); +#ifdef DEBUG_AUDIO_GENERATOR cerr << "AudioGenerator::reset()" << endl; +#endif for (ClipMixerMap::iterator i = m_clipMixerMap.begin(); i != m_clipMixerMap.end(); ++i) { if (i->second) { @@ -310,7 +326,7 @@ } } -int +sv_frame_t AudioGenerator::getBlockSize() const { return m_processingBlockSize; @@ -334,9 +350,9 @@ m_soloing = false; } -int -AudioGenerator::mixModel(Model *model, int startFrame, int frameCount, - float **buffer, int fadeIn, int fadeOut) +sv_frame_t +AudioGenerator::mixModel(Model *model, sv_frame_t startFrame, sv_frame_t frameCount, + float **buffer, sv_frame_t fadeIn, sv_frame_t fadeOut) { if (m_sourceSampleRate == 0) { cerr << "WARNING: AudioGenerator::mixModel: No base source sample rate available" << endl; @@ -393,13 +409,13 @@ return frameCount; } -int +sv_frame_t AudioGenerator::mixDenseTimeValueModel(DenseTimeValueModel *dtvm, - int startFrame, int frames, + sv_frame_t startFrame, sv_frame_t frames, float **buffer, float gain, float pan, - int fadeIn, int fadeOut) + sv_frame_t fadeIn, sv_frame_t fadeOut) { - int maxFrames = frames + std::max(fadeIn, fadeOut); + sv_frame_t maxFrames = frames + std::max(fadeIn, fadeOut); int modelChannels = dtvm->getChannelCount(); @@ -420,7 +436,7 @@ m_channelBufSiz = maxFrames; } - int got = 0; + sv_frame_t got = 0; if (startFrame >= fadeIn/2) { got = dtvm->getData(0, modelChannels - 1, @@ -428,7 +444,7 @@ frames + fadeOut/2 + fadeIn/2, m_channelBuffer); } else { - int missing = fadeIn/2 - startFrame; + sv_frame_t missing = fadeIn/2 - startFrame; for (int c = 0; c < modelChannels; ++c) { m_channelBuffer[c] += missing; @@ -462,25 +478,27 @@ float channelGain = gain; if (pan != 0.0) { if (c == 0) { - if (pan > 0.0) channelGain *= 1.0 - pan; + if (pan > 0.0) channelGain *= 1.0f - pan; } else { - if (pan < 0.0) channelGain *= pan + 1.0; + if (pan < 0.0) channelGain *= pan + 1.0f; } } - for (int i = 0; i < fadeIn/2; ++i) { + for (sv_frame_t i = 0; i < fadeIn/2; ++i) { float *back = buffer[c]; back -= fadeIn/2; - back[i] += (channelGain * m_channelBuffer[sourceChannel][i] * i) / fadeIn; + back[i] += + (channelGain * m_channelBuffer[sourceChannel][i] * float(i)) + / float(fadeIn); } - for (int i = 0; i < frames + fadeOut/2; ++i) { + for (sv_frame_t i = 0; i < frames + fadeOut/2; ++i) { float mult = channelGain; if (i < fadeIn/2) { - mult = (mult * i) / fadeIn; + mult = (mult * float(i)) / float(fadeIn); } if (i > frames - fadeOut/2) { - mult = (mult * ((frames + fadeOut/2) - i)) / fadeOut; + mult = (mult * float((frames + fadeOut/2) - i)) / float(fadeOut); } float val = m_channelBuffer[sourceChannel][i]; if (i >= got) val = 0.f; @@ -491,15 +509,15 @@ return got; } -int +sv_frame_t AudioGenerator::mixClipModel(Model *model, - int startFrame, int frames, + sv_frame_t startFrame, sv_frame_t frames, float **buffer, float gain, float pan) { ClipMixer *clipMixer = m_clipMixerMap[model]; if (!clipMixer) return 0; - int blocks = frames / m_processingBlockSize; + int blocks = int(frames / m_processingBlockSize); //!!! todo: the below -- it matters @@ -513,11 +531,12 @@ //callback play source has to use that as a multiple for all the //calls to mixModel - int got = blocks * m_processingBlockSize; + sv_frame_t got = blocks * m_processingBlockSize; #ifdef DEBUG_AUDIO_GENERATOR - cout << "mixModel [clip]: frames " << frames - << ", blocks " << blocks << endl; + cout << "mixModel [clip]: start " << startFrame << ", frames " << frames + << ", blocks " << blocks << ", have " << m_noteOffs.size() + << " note-offs" << endl; #endif ClipMixer::NoteStart on; @@ -529,7 +548,7 @@ for (int i = 0; i < blocks; ++i) { - int reqStart = startFrame + i * m_processingBlockSize; + sv_frame_t reqStart = startFrame + i * m_processingBlockSize; NoteList notes; NoteExportable *exportable = dynamic_cast<NoteExportable *>(model); @@ -544,7 +563,7 @@ for (NoteList::const_iterator ni = notes.begin(); ni != notes.end(); ++ni) { - int noteFrame = ni->start; + sv_frame_t noteFrame = ni->start; if (noteFrame < reqStart || noteFrame >= reqStart + m_processingBlockSize) continue; @@ -552,7 +571,7 @@ while (noteOffs.begin() != noteOffs.end() && noteOffs.begin()->frame <= noteFrame) { - int eventFrame = noteOffs.begin()->frame; + sv_frame_t eventFrame = noteOffs.begin()->frame; if (eventFrame < reqStart) eventFrame = reqStart; off.frameOffset = eventFrame - reqStart; @@ -568,7 +587,7 @@ on.frameOffset = noteFrame - reqStart; on.frequency = ni->getFrequency(); - on.level = float(ni->velocity) / 127.0; + on.level = float(ni->velocity) / 127.0f; on.pan = pan; #ifdef DEBUG_AUDIO_GENERATOR @@ -583,7 +602,7 @@ while (noteOffs.begin() != noteOffs.end() && noteOffs.begin()->frame <= reqStart + m_processingBlockSize) { - int eventFrame = noteOffs.begin()->frame; + sv_frame_t eventFrame = noteOffs.begin()->frame; if (eventFrame < reqStart) eventFrame = reqStart; off.frameOffset = eventFrame - reqStart; @@ -609,10 +628,10 @@ return got; } -int +sv_frame_t AudioGenerator::mixContinuousSynthModel(Model *model, - int startFrame, - int frames, + sv_frame_t startFrame, + sv_frame_t frames, float **buffer, float gain, float pan) @@ -624,11 +643,11 @@ SparseTimeValueModel *stvm = qobject_cast<SparseTimeValueModel *>(model); if (stvm->getScaleUnits() != "Hz") return 0; - int blocks = frames / m_processingBlockSize; + int blocks = int(frames / m_processingBlockSize); //!!! todo: see comment in mixClipModel - int got = blocks * m_processingBlockSize; + sv_frame_t got = blocks * m_processingBlockSize; #ifdef DEBUG_AUDIO_GENERATOR cout << "mixModel [synth]: frames " << frames @@ -639,7 +658,7 @@ for (int i = 0; i < blocks; ++i) { - int reqStart = startFrame + i * m_processingBlockSize; + sv_frame_t reqStart = startFrame + i * m_processingBlockSize; for (int c = 0; c < m_targetChannelCount; ++c) { bufferIndexes[c] = buffer[c] + i * m_processingBlockSize;