Mercurial > hg > segmenter-vamp-plugin
comparison segmentino/Segmentino.cpp @ 59:6be9479ad11f
removed all but one output
author | matthiasm |
---|---|
date | Thu, 13 Jun 2013 16:30:31 +0100 |
parents | e2e09a2196a9 |
children | b536a23b8523 |
comparison
equal
deleted
inserted
replaced
56:e2e09a2196a9 | 59:6be9479ad11f |
---|---|
534 | 534 |
535 // Initialise Chroma Extractor | 535 // Initialise Chroma Extractor |
536 m_chromadata = new ChromaData(m_inputSampleRate, blockSize); | 536 m_chromadata = new ChromaData(m_inputSampleRate, blockSize); |
537 m_chromadata->initialise(); | 537 m_chromadata->initialise(); |
538 | 538 |
539 // definition of outputs numbers used internally | |
540 int outputCounter = 1; | |
541 m_beatOutputNumber = outputCounter++; | |
542 m_barsOutputNumber = outputCounter++; | |
543 m_beatcountsOutputNumber = outputCounter++; | |
544 m_beatsdOutputNumber = outputCounter++; | |
545 m_logscalespecOutputNumber = outputCounter++; | |
546 m_bothchromaOutputNumber = outputCounter++; | |
547 m_qchromafwOutputNumber = outputCounter++; | |
548 m_qchromaOutputNumber = outputCounter++; | |
549 | |
539 return true; | 550 return true; |
540 } | 551 } |
541 | 552 |
542 void Segmentino::reset() | 553 void Segmentino::reset() |
543 { | 554 { |
546 m_pluginFrameCount = 0; | 557 m_pluginFrameCount = 0; |
547 } | 558 } |
548 | 559 |
549 Segmentino::OutputList Segmentino::getOutputDescriptors() const | 560 Segmentino::OutputList Segmentino::getOutputDescriptors() const |
550 { | 561 { |
562 | |
551 OutputList list; | 563 OutputList list; |
552 int outputCounter = 0; | |
553 | |
554 OutputDescriptor beat; | |
555 beat.identifier = "beats"; | |
556 beat.name = "Beats"; | |
557 beat.description = "Beat locations labelled with metrical position"; | |
558 beat.unit = ""; | |
559 beat.hasFixedBinCount = true; | |
560 beat.binCount = 0; | |
561 beat.sampleType = OutputDescriptor::VariableSampleRate; | |
562 beat.sampleRate = 1.0 / m_stepSecs; | |
563 m_beatOutputNumber = outputCounter++; | |
564 | |
565 OutputDescriptor bars; | |
566 bars.identifier = "bars"; | |
567 bars.name = "Bars"; | |
568 bars.description = "Bar locations"; | |
569 bars.unit = ""; | |
570 bars.hasFixedBinCount = true; | |
571 bars.binCount = 0; | |
572 bars.sampleType = OutputDescriptor::VariableSampleRate; | |
573 bars.sampleRate = 1.0 / m_stepSecs; | |
574 m_barsOutputNumber = outputCounter++; | |
575 | |
576 OutputDescriptor beatcounts; | |
577 beatcounts.identifier = "beatcounts"; | |
578 beatcounts.name = "Beat Count"; | |
579 beatcounts.description = "Beat counter function"; | |
580 beatcounts.unit = ""; | |
581 beatcounts.hasFixedBinCount = true; | |
582 beatcounts.binCount = 1; | |
583 beatcounts.sampleType = OutputDescriptor::VariableSampleRate; | |
584 beatcounts.sampleRate = 1.0 / m_stepSecs; | |
585 m_beatcountsOutputNumber = outputCounter++; | |
586 | |
587 OutputDescriptor beatsd; | |
588 beatsd.identifier = "beatsd"; | |
589 beatsd.name = "Beat Spectral Difference"; | |
590 beatsd.description = "Beat spectral difference function used for bar-line detection"; | |
591 beatsd.unit = ""; | |
592 beatsd.hasFixedBinCount = true; | |
593 beatsd.binCount = 1; | |
594 beatsd.sampleType = OutputDescriptor::VariableSampleRate; | |
595 beatsd.sampleRate = 1.0 / m_stepSecs; | |
596 m_beatsdOutputNumber = outputCounter++; | |
597 | |
598 OutputDescriptor logscalespec; | |
599 logscalespec.identifier = "logscalespec"; | |
600 logscalespec.name = "Log-Frequency Spectrum"; | |
601 logscalespec.description = "Spectrum with linear frequency on a log scale."; | |
602 logscalespec.unit = ""; | |
603 logscalespec.hasFixedBinCount = true; | |
604 logscalespec.binCount = nNote; | |
605 logscalespec.hasKnownExtents = false; | |
606 logscalespec.isQuantized = false; | |
607 logscalespec.sampleType = OutputDescriptor::FixedSampleRate; | |
608 logscalespec.hasDuration = false; | |
609 logscalespec.sampleRate = m_inputSampleRate/2048; | |
610 m_logscalespecOutputNumber = outputCounter++; | |
611 | |
612 OutputDescriptor bothchroma; | |
613 bothchroma.identifier = "bothchroma"; | |
614 bothchroma.name = "Chromagram and Bass Chromagram"; | |
615 bothchroma.description = "Tuning-adjusted chromagram and bass chromagram (stacked on top of each other) from NNLS approximate transcription."; | |
616 bothchroma.unit = ""; | |
617 bothchroma.hasFixedBinCount = true; | |
618 bothchroma.binCount = 24; | |
619 bothchroma.hasKnownExtents = false; | |
620 bothchroma.isQuantized = false; | |
621 bothchroma.sampleType = OutputDescriptor::FixedSampleRate; | |
622 bothchroma.hasDuration = false; | |
623 bothchroma.sampleRate = m_inputSampleRate/2048; | |
624 m_bothchromaOutputNumber = outputCounter++; | |
625 | |
626 OutputDescriptor qchromafw; | |
627 qchromafw.identifier = "qchromafw"; | |
628 qchromafw.name = "Pseudo-Quantised Chromagram and Bass Chromagram"; | |
629 qchromafw.description = "Pseudo-Quantised Chromagram and Bass Chromagram (frames between two beats are identical)."; | |
630 qchromafw.unit = ""; | |
631 qchromafw.hasFixedBinCount = true; | |
632 qchromafw.binCount = 24; | |
633 qchromafw.hasKnownExtents = false; | |
634 qchromafw.isQuantized = false; | |
635 qchromafw.sampleType = OutputDescriptor::FixedSampleRate; | |
636 qchromafw.hasDuration = false; | |
637 qchromafw.sampleRate = m_inputSampleRate/2048; | |
638 m_qchromafwOutputNumber = outputCounter++; | |
639 | |
640 OutputDescriptor qchroma; | |
641 qchroma.identifier = "qchroma"; | |
642 qchroma.name = "Quantised Chromagram and Bass Chromagram"; | |
643 qchroma.description = "Quantised Chromagram and Bass Chromagram."; | |
644 qchroma.unit = ""; | |
645 qchroma.hasFixedBinCount = true; | |
646 qchroma.binCount = 24; | |
647 qchroma.hasKnownExtents = false; | |
648 qchroma.isQuantized = false; | |
649 qchroma.sampleType = OutputDescriptor::FixedSampleRate; | |
650 qchroma.hasDuration = true; | |
651 qchroma.sampleRate = m_inputSampleRate/2048; | |
652 m_qchromaOutputNumber = outputCounter++; | |
653 | 564 |
654 OutputDescriptor segm; | 565 OutputDescriptor segm; |
655 segm.identifier = "segmentation"; | 566 segm.identifier = "segmentation"; |
656 segm.name = "Segmentation"; | 567 segm.name = "Segmentation"; |
657 segm.description = "Segmentation"; | 568 segm.description = "Segmentation"; |
665 segm.isQuantized = true; | 576 segm.isQuantized = true; |
666 segm.quantizeStep = 1; | 577 segm.quantizeStep = 1; |
667 segm.sampleType = OutputDescriptor::VariableSampleRate; | 578 segm.sampleType = OutputDescriptor::VariableSampleRate; |
668 segm.sampleRate = 1.0 / m_stepSecs; | 579 segm.sampleRate = 1.0 / m_stepSecs; |
669 segm.hasDuration = true; | 580 segm.hasDuration = true; |
670 m_segmOutputNumber = outputCounter++; | 581 m_segmOutputNumber = 0; |
671 | 582 |
672 | |
673 /* | |
674 OutputList list; | |
675 OutputDescriptor segmentation; | |
676 segmentation.identifier = "segmentation"; | |
677 segmentation.name = "Segmentation"; | |
678 segmentation.description = "Segmentation"; | |
679 segmentation.unit = "segment-type"; | |
680 segmentation.hasFixedBinCount = true; | |
681 segmentation.binCount = 1; | |
682 segmentation.hasKnownExtents = true; | |
683 segmentation.minValue = 1; | |
684 segmentation.maxValue = nSegmentTypes; | |
685 segmentation.isQuantized = true; | |
686 segmentation.quantizeStep = 1; | |
687 segmentation.sampleType = OutputDescriptor::VariableSampleRate; | |
688 segmentation.sampleRate = m_inputSampleRate / getPreferredStepSize(); | |
689 list.push_back(segmentation); | |
690 return list; | |
691 */ | |
692 | |
693 | |
694 list.push_back(beat); | |
695 list.push_back(bars); | |
696 list.push_back(beatcounts); | |
697 list.push_back(beatsd); | |
698 list.push_back(logscalespec); | |
699 list.push_back(bothchroma); | |
700 list.push_back(qchromafw); | |
701 list.push_back(qchroma); | |
702 list.push_back(segm); | 583 list.push_back(segm); |
703 | 584 |
704 return list; | 585 return list; |
705 } | 586 } |
706 | 587 |
784 << "Segmentino has not been initialised" | 665 << "Segmentino has not been initialised" |
785 << endl; | 666 << endl; |
786 return FeatureSet(); | 667 return FeatureSet(); |
787 } | 668 } |
788 | 669 |
789 FeatureSet masterFeatureset = beatTrack(); | 670 FeatureSet masterFeatureset; |
790 int beatcount = masterFeatureset[m_beatOutputNumber].size(); | 671 FeatureSet internalFeatureset = beatTrack(); |
672 | |
673 int beatcount = internalFeatureset[m_beatOutputNumber].size(); | |
791 if (beatcount == 0) return Segmentino::FeatureSet(); | 674 if (beatcount == 0) return Segmentino::FeatureSet(); |
792 Vamp::RealTime last_beattime = masterFeatureset[m_beatOutputNumber][beatcount-1].timestamp; | 675 Vamp::RealTime last_beattime = internalFeatureset[m_beatOutputNumber][beatcount-1].timestamp; |
793 masterFeatureset[m_beatOutputNumber].clear(); | 676 |
794 Vamp::RealTime beattime = Vamp::RealTime::fromSeconds(1.0); | 677 // internalFeatureset[m_beatOutputNumber].clear(); |
795 while (beattime < last_beattime) | 678 // Vamp::RealTime beattime = Vamp::RealTime::fromSeconds(1.0); |
796 { | 679 // while (beattime < last_beattime) |
797 Feature beatfeature; | 680 // { |
798 beatfeature.hasTimestamp = true; | 681 // Feature beatfeature; |
799 beatfeature.timestamp = beattime; | 682 // beatfeature.hasTimestamp = true; |
800 masterFeatureset[m_beatOutputNumber].push_back(beatfeature); | 683 // beatfeature.timestamp = beattime; |
801 beattime = beattime + Vamp::RealTime::fromSeconds(0.5); | 684 // masterFeatureset[m_beatOutputNumber].push_back(beatfeature); |
802 } | 685 // beattime = beattime + Vamp::RealTime::fromSeconds(0.5); |
803 | 686 // } |
804 | 687 |
805 FeatureList chromaList = chromaFeatures(); | 688 FeatureList chromaList = chromaFeatures(); |
806 | 689 |
807 for (int i = 0; i < (int)chromaList.size(); ++i) | 690 for (int i = 0; i < (int)chromaList.size(); ++i) |
808 { | 691 { |
809 masterFeatureset[m_bothchromaOutputNumber].push_back(chromaList[i]); | 692 internalFeatureset[m_bothchromaOutputNumber].push_back(chromaList[i]); |
810 } | 693 } |
811 | 694 |
812 // quantised and pseudo-quantised (beat-wise) chroma | 695 // quantised and pseudo-quantised (beat-wise) chroma |
813 std::vector<FeatureList> quantisedChroma = beatQuantiser(chromaList, masterFeatureset[m_beatOutputNumber]); | 696 std::vector<FeatureList> quantisedChroma = beatQuantiser(chromaList, internalFeatureset[m_beatOutputNumber]); |
814 | 697 |
815 if (quantisedChroma.empty()) return masterFeatureset; | 698 if (quantisedChroma.empty()) return masterFeatureset; |
816 | 699 |
817 masterFeatureset[m_qchromafwOutputNumber] = quantisedChroma[0]; | 700 internalFeatureset[m_qchromafwOutputNumber] = quantisedChroma[0]; |
818 masterFeatureset[m_qchromaOutputNumber] = quantisedChroma[1]; | 701 internalFeatureset[m_qchromaOutputNumber] = quantisedChroma[1]; |
819 | 702 |
820 // Segmentation | 703 // Segmentation |
821 try { | 704 try { |
822 masterFeatureset[m_segmOutputNumber] = runSegmenter(quantisedChroma[1]); | 705 masterFeatureset[m_segmOutputNumber] = runSegmenter(quantisedChroma[1]); |
823 } catch (std::bad_alloc &a) { | 706 } catch (std::bad_alloc &a) { |