Beispiel #1
0
void WebController::listener()
{
	Poco::SharedPtr<MultiView> multiView = new MultiView("base.tpl");
	multiView->add("head", new TemplateView("listener/head.tpl"));
	multiView->add("main", new TemplateView("listener/index.tpl"));
	setView(multiView);
}
Beispiel #2
0
void WebController::message()
{
	std::vector<std::string> parameters = getParameters();
	if ( parameters.size() < 2 )
	{
		setResponseStatus(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST, "Missing URI parameters");
		return;
	}

	mqwebData().set("queue", parameters[1]);
	std::string messageId;
	if ( parameters.size() > 2 )
	{
		messageId = parameters[2];
		mqwebData().set("messageId", messageId);
	}

	Poco::SharedPtr<MultiView> multiView = new MultiView("base.tpl");
	multiView->add("head", new TemplateView("message/head.tpl"));
	multiView->add("main", new TemplateView("message/index.tpl"));
	setView(multiView);
}
void SeparationTask::exportComponents() const
{
    debug_assert(&phaseMatrix() &&
                 &magnitudeSpectraMatrix(0) &&
                 &gainsMatrix());

    logger().debug(nameAndTaskID() + " exporting the components.");

    Poco::Util::LayeredConfiguration& cfg =
        BasicApplication::instance().config();

    // Determine whether to export components as WAV and/or as matrix files.
    bool exportAsMatrix = cfg.getBool("blissart.separation.export.matrix",
                                      false);
    if (exportAsMatrix)
        logger().debug("Exporting components as matrix file(s).");
    bool exportAsWave = cfg.getBool("blissart.separation.export.wave",
                                      true);
    if (exportAsWave)
        logger().debug("Exporting components as waveform file(s).");

    // Determine whether to use wiener reconstruction.
    bool wienerRec = cfg.getBool("blissart.separation.export.wienerrec", 
                                    true);

    // Compute the reconstructed matrix (WH) in case of wiener reconstruction.
    Poco::SharedPtr<Matrix> reconst;
    if (wienerRec) {
        //reconst = new Matrix(phaseMatrix().rows(), phaseMatrix().cols());
        reconst = new Matrix(magnitudeSpectraMatrix(0).rows(),
            gainsMatrix().cols());
        if (_nrOfSpectra > 1) {
            reconst->zero();
            Matrix hShifted = gainsMatrix();
            for (unsigned int t = 0; t < _nrOfSpectra; ++t) {
                reconst->add(magnitudeSpectraMatrix(t) * hShifted);
                hShifted.shiftColumnsRight();
            }
        }
        else {
            magnitudeSpectraMatrix(0).multWithMatrix(gainsMatrix(), reconst);
        }
        // revert transform to reconst
        reconst = revertTransforms(reconst);
    }

    // Retrieve desired component indices.
    vector<vector<int> > compIndices = _exportComponentIndices;
    if (compIndices.empty()) {
        vector<int> compIndicesSource;
        for (int i = 1; i <= _nrOfComponents; i++) {
            compIndicesSource.push_back(i);
        }
        compIndices.push_back(compIndicesSource);
    }

    // Reconstruct components and mix, if desired.
    int sourceIndex = 1;
    for (vector<vector<int> >::const_iterator sourceIt = compIndices.begin();
         sourceIt != compIndices.end(); ++sourceIt, ++sourceIndex)
    {
        // Holds the mixed spectrogram if mixing is desired.
        Poco::SharedPtr<Matrix> mixedSpectrogram;

        logger().debug("Exporting components for source #" +
            Poco::NumberFormatter::format(sourceIndex));
        for (vector<int>::const_iterator it = sourceIt->begin();
            it != sourceIt->end(); ++it)
        {
            if (*it < 1 || *it > _nrOfComponents) {
                logger().error(nameAndTaskID() + ": invalid component index: " +
                    Poco::NumberFormatter::format(*it));
                continue;
            }
            int i = *it - 1;
            logger().debug(nameAndTaskID() + " exporting component #" +
                Poco::NumberFormatter::format(i));
            // Compute the component's magnitude spectrum.
            Poco::SharedPtr<Matrix> magnitudeSpectrum = new Matrix(
                magnitudeSpectraMatrix(0).rows(),
                gainsMatrix().cols());
            // NMD case
            if (_nrOfSpectra > 1) {
                magnitudeSpectrum->zero();
                RowVector componentGains = gainsMatrix().nthRow(i);
                for (unsigned int t = 0; t < _nrOfSpectra; t++) {
                    ColVector componentSpectrum = magnitudeSpectraMatrix(t).nthColumn(i);
                    magnitudeSpectrum->add(componentSpectrum * componentGains);
                    componentGains.shiftRight();
                }
            }
            // "NMF" case (separated for efficiency)
            else {
                ColVector componentSpectrum = magnitudeSpectraMatrix(0).nthColumn(i);
                RowVector componentGains = gainsMatrix().nthRow(i);
                *magnitudeSpectrum = componentSpectrum * componentGains;
            }

            // revert transformation to component spectrogram
            magnitudeSpectrum = revertTransforms(magnitudeSpectrum);

            if (wienerRec) {
                // (Component/Whole) reconstruction
                reconst->floor(1e-6);
                magnitudeSpectrum->elementWiseDivision(*reconst, magnitudeSpectrum);
                // Use as filter for original spectrogram
                magnitudeSpectrum->elementWiseMultiplication(ftMagMatrix(),
                                                       magnitudeSpectrum);
            }

            // Mix the components to a single spectrogram that is exported after
            // the loop.
            if (_mixExportedComponents) {
                if (mixedSpectrogram.isNull()) {
                    mixedSpectrogram = new Matrix(magnitudeSpectrum->rows(), 
                        magnitudeSpectrum->cols());
                    mixedSpectrogram->zero();
                }
                mixedSpectrogram->add(*magnitudeSpectrum);
            }
            // Export components individually.
            else {
                // Construct the filename.
                string prefix = getExportPrefix();
                const int numDigits = (int)(1 + log10f((float)_nrOfComponents));
                stringstream ss;
                ss << prefix;
                if (compIndices.size() > 1) {
                    const int numDigitsS = (int)(1 + log10f((float)compIndices.size()));
                    ss << '_' << setfill('0') << setw(numDigitsS) << sourceIndex;
                }
                ss << '_' << setfill('0') << setw(numDigits) << *it;

                if (exportAsMatrix) {
                    magnitudeSpectrum->dump(ss.str() + ".dat");
                }
                if (exportAsWave) {
                    // Convert component spectrogram to time signal and save it as WAV.
                    spectrogramToAudioFile(magnitudeSpectrum, ss.str() + ".wav");
                }
            }
        }
        // Export the mixed source spectrogram to a single audio file.
        if (_mixExportedComponents) {
            // Construct the filename.
            stringstream ss;
            ss << getExportPrefix();
            const int numDigitsS = (int)(1 + log10f((float)compIndices.size()));
            ss << "_source" << setfill('0') << setw(numDigitsS) << sourceIndex;
            // Convert component spectrogram to time signal and save it as WAV.
            string filename = ss.str();
            logger().debug(nameAndTaskID() + ": creating mixed audio file " +
                filename);
            if (exportAsMatrix) {
                mixedSpectrogram->dump(filename + ".dat");
            }
            if (exportAsWave) {
                spectrogramToAudioFile(mixedSpectrogram, filename + ".wav");
            }
        }
    }

}