SyncUnmountableManager::SyncUnmountableManager (QObject *parent) : SyncManagerBase (parent) , CopyMgr_ (new CopyManager<CopyJob> (this)) { connect (CopyMgr_, SIGNAL (startedCopying (QString)), this, SLOT (handleStartedCopying (QString))); connect (CopyMgr_, SIGNAL (finishedCopying ()), this, SLOT (handleFinishedCopying ())); connect (CopyMgr_, SIGNAL (copyProgress (qint64, qint64)), this, SLOT (handleCopyProgress (qint64, qint64))); connect (CopyMgr_, SIGNAL (errorCopying (QString, QString)), this, SLOT (handleErrorCopying (QString, QString))); }
void Effect::process(const synthclone::Zone &/*zone*/, synthclone::SampleInputStream &inputStream, synthclone::SampleOutputStream &outputStream) { synthclone::SampleFrameCount frames = inputStream.getFrames(); float sampleRate = static_cast<float>(inputStream.getSampleRate()); synthclone::SampleFrameCount fadeInFrames = fadeInEnabled ? static_cast<synthclone::SampleFrameCount>(fadeInTime * sampleRate) : 0; synthclone::SampleFrameCount fadeOutFrames = fadeOutEnabled ? static_cast<synthclone::SampleFrameCount>(fadeOutTime * sampleRate) : 0; synthclone::SampleFrameCount totalFadeFrames = fadeInFrames + fadeOutFrames; qDebug() << "\tfade in frames:" << fadeInFrames; qDebug() << "\t fade out frames:" << fadeOutFrames; // If the amount of frames spent fading is greater than the number of total // frames, then shorten the fades proportionally. If anyone has a better // suggestion, I'm all ears. if (totalFadeFrames > frames) { qDebug() << "adjusting fade frames"; fadeInFrames = static_cast<synthclone::SampleFrameCount> (static_cast<float>(fadeInFrames) * (static_cast<float>(frames) / static_cast<float>(totalFadeFrames))); fadeOutFrames = frames - fadeInFrames; qDebug() << "\tfade in frames:" << fadeInFrames; qDebug() << "\t fade out frames:" << fadeOutFrames; } synthclone::SampleChannelCount channels = inputStream.getChannels(); QScopedArrayPointer<float> audioDataPtr(new float[channels]); float *audioData = audioDataPtr.data(); synthclone::SampleFrameCount currentFrame = 0; synthclone::SampleFrameCount framesRead; float volume; if (fadeInFrames) { qDebug() << "\tapplying fade in ..."; emit statusChanged(tr("Creating fade-in of sample ...")); for (; currentFrame < fadeInFrames; currentFrame++) { framesRead = inputStream.read(audioData, 1); assert(framesRead == 1); volume = getAmplitude(fadeInStartVolume * (1.0 - (static_cast<float>(currentFrame + 1) / static_cast<float>(fadeInFrames)))); for (int i = 0; i < channels; i++) { audioData[i] *= volume; } outputStream.write(audioData, 1); emit progressChanged(static_cast<float>(currentFrame + 1) / static_cast<float>(frames)); } } synthclone::SampleFrameCount fadeOutStartFrame = frames - fadeOutFrames; synthclone::SampleFrameCount copyFrames = fadeOutStartFrame - currentFrame; qDebug() << "\tcopy frames:" << copyFrames; qDebug() << "\tfade out start frame:" << fadeOutStartFrame; if (copyFrames) { qDebug() << "copying frames ..."; emit statusChanged(tr("Writing sample ...")); copyStartFrame = currentFrame; copyTotalFrames = frames; synthclone::SampleCopier copier; connect(&copier, SIGNAL(copyProgress(synthclone::SampleFrameCount, synthclone::SampleFrameCount)), SLOT(handleCopyProgress(synthclone::SampleFrameCount, synthclone::SampleFrameCount)), Qt::DirectConnection); copier.copy(inputStream, outputStream, copyFrames); } currentFrame += copyFrames; if (fadeOutFrames) { qDebug() << "\tapplying fade out ..."; emit statusChanged(tr("Creating fade-out of sample ...")); for (; currentFrame < frames; currentFrame++) { framesRead = inputStream.read(audioData, 1); assert(framesRead == 1); volume = getAmplitude(fadeOutEndVolume * (static_cast<float>(currentFrame + 1 - fadeOutStartFrame) / static_cast<float>(fadeOutFrames))); for (int i = 0; i < channels; i++) { audioData[i] *= volume; } outputStream.write(audioData, 1); emit progressChanged(static_cast<float>(currentFrame + 1) / static_cast<float>(frames)); } } emit progressChanged(0.0); emit statusChanged(""); qDebug() << "/Effect::process"; }