Mercurial > hg > sonic-annotator
comparison runner/FeatureExtractionManager.cpp @ 331:e39307a8d22d
Use sv samplerate/frame types, fixing compiler warnings
author | Chris Cannam |
---|---|
date | Tue, 12 Jun 2018 10:14:22 +0100 |
parents | 0e866ef12d87 |
children | 9f7297c47850 |
comparison
equal
deleted
inserted
replaced
330:4819abbd24bb | 331:e39307a8d22d |
---|---|
92 void FeatureExtractionManager::setChannels(int channels) | 92 void FeatureExtractionManager::setChannels(int channels) |
93 { | 93 { |
94 m_channels = channels; | 94 m_channels = channels; |
95 } | 95 } |
96 | 96 |
97 void FeatureExtractionManager::setDefaultSampleRate(int sampleRate) | 97 void FeatureExtractionManager::setDefaultSampleRate(sv_samplerate_t sampleRate) |
98 { | 98 { |
99 m_defaultSampleRate = sampleRate; | 99 m_defaultSampleRate = sampleRate; |
100 } | 100 } |
101 | 101 |
102 void FeatureExtractionManager::setNormalise(bool normalise) | 102 void FeatureExtractionManager::setNormalise(bool normalise) |
279 plugin = pba; | 279 plugin = pba; |
280 | 280 |
281 if (transform.getStepSize() != 0) { | 281 if (transform.getStepSize() != 0) { |
282 pba->setPluginStepSize(transform.getStepSize()); | 282 pba->setPluginStepSize(transform.getStepSize()); |
283 } else { | 283 } else { |
284 transform.setStepSize(pluginStepSize); | 284 transform.setStepSize(int(pluginStepSize)); |
285 } | 285 } |
286 | 286 |
287 if (transform.getBlockSize() != 0) { | 287 if (transform.getBlockSize() != 0) { |
288 pba->setPluginBlockSize(transform.getBlockSize()); | 288 pba->setPluginBlockSize(transform.getBlockSize()); |
289 } else { | 289 } else { |
290 transform.setBlockSize(pluginBlockSize); | 290 transform.setBlockSize(int(pluginBlockSize)); |
291 } | 291 } |
292 | 292 |
293 plugin = new PluginChannelAdapter(plugin); | 293 plugin = new PluginChannelAdapter(plugin); |
294 | 294 |
295 if (!m_summaries.empty() || | 295 if (!m_summaries.empty() || |
309 SVDEBUG << "Initialised plugin" << endl; | 309 SVDEBUG << "Initialised plugin" << endl; |
310 | 310 |
311 size_t actualStepSize = 0; | 311 size_t actualStepSize = 0; |
312 size_t actualBlockSize = 0; | 312 size_t actualBlockSize = 0; |
313 pba->getActualStepAndBlockSizes(actualStepSize, actualBlockSize); | 313 pba->getActualStepAndBlockSizes(actualStepSize, actualBlockSize); |
314 transform.setStepSize(actualStepSize); | 314 transform.setStepSize(int(actualStepSize)); |
315 transform.setBlockSize(actualBlockSize); | 315 transform.setBlockSize(int(actualBlockSize)); |
316 | 316 |
317 Plugin::OutputList outputs = plugin->getOutputDescriptors(); | 317 Plugin::OutputList outputs = plugin->getOutputDescriptors(); |
318 for (int i = 0; i < (int)outputs.size(); ++i) { | 318 for (int i = 0; i < (int)outputs.size(); ++i) { |
319 | 319 |
320 SVDEBUG << "Newly initialised plugin output " << i << " has bin count " << outputs[i].binCount << endl; | 320 SVDEBUG << "Newly initialised plugin output " << i << " has bin count " << outputs[i].binCount << endl; |
349 size_t actualStepSize = 0; | 349 size_t actualStepSize = 0; |
350 size_t actualBlockSize = 0; | 350 size_t actualBlockSize = 0; |
351 pba->getActualStepAndBlockSizes(actualStepSize, | 351 pba->getActualStepAndBlockSizes(actualStepSize, |
352 actualBlockSize); | 352 actualBlockSize); |
353 if (transform.getStepSize() == 0) { | 353 if (transform.getStepSize() == 0) { |
354 transform.setStepSize(actualStepSize); | 354 transform.setStepSize(int(actualStepSize)); |
355 } | 355 } |
356 if (transform.getBlockSize() == 0) { | 356 if (transform.getBlockSize() == 0) { |
357 transform.setBlockSize(actualBlockSize); | 357 transform.setBlockSize(int(actualBlockSize)); |
358 } | 358 } |
359 } | 359 } |
360 } | 360 } |
361 } | 361 } |
362 } | 362 } |
752 m_r = 0; | 752 m_r = 0; |
753 } | 753 } |
754 }; | 754 }; |
755 LifespanMgr lifemgr(reader, m_channels, data); | 755 LifespanMgr lifemgr(reader, m_channels, data); |
756 | 756 |
757 size_t frameCount = reader->getFrameCount(); | 757 sv_frame_t frameCount = reader->getFrameCount(); |
758 | 758 |
759 SVDEBUG << "FeatureExtractionManager: file has " << frameCount << " frames" << endl; | 759 SVDEBUG << "FeatureExtractionManager: file has " << frameCount << " frames" << endl; |
760 | 760 |
761 int earliestStartFrame = 0; | 761 sv_frame_t earliestStartFrame = 0; |
762 int latestEndFrame = frameCount; | 762 sv_frame_t latestEndFrame = frameCount; |
763 bool haveExtents = false; | 763 bool haveExtents = false; |
764 | 764 |
765 foreach (Plugin *plugin, m_orderedPlugins) { | 765 foreach (Plugin *plugin, m_orderedPlugins) { |
766 | 766 |
767 PluginMap::iterator pi = m_plugins.find(plugin); | 767 PluginMap::iterator pi = m_plugins.find(plugin); |
772 for (TransformWriterMap::iterator ti = pi->second.begin(); | 772 for (TransformWriterMap::iterator ti = pi->second.begin(); |
773 ti != pi->second.end(); ++ti) { | 773 ti != pi->second.end(); ++ti) { |
774 | 774 |
775 const Transform &transform = ti->first; | 775 const Transform &transform = ti->first; |
776 | 776 |
777 int startFrame = RealTime::realTime2Frame | 777 sv_frame_t startFrame = RealTime::realTime2Frame |
778 (transform.getStartTime(), m_sampleRate); | 778 (transform.getStartTime(), m_sampleRate); |
779 int duration = RealTime::realTime2Frame | 779 sv_frame_t duration = RealTime::realTime2Frame |
780 (transform.getDuration(), m_sampleRate); | 780 (transform.getDuration(), m_sampleRate); |
781 if (duration == 0) { | 781 if (duration == 0) { |
782 duration = frameCount - startFrame; | 782 duration = frameCount - startFrame; |
783 } | 783 } |
784 | 784 |
821 } | 821 } |
822 } | 822 } |
823 } | 823 } |
824 } | 824 } |
825 | 825 |
826 int startFrame = earliestStartFrame; | 826 sv_frame_t startFrame = earliestStartFrame; |
827 int endFrame = latestEndFrame; | 827 sv_frame_t endFrame = latestEndFrame; |
828 | 828 |
829 foreach (Plugin *plugin, m_orderedPlugins) { | 829 foreach (Plugin *plugin, m_orderedPlugins) { |
830 | 830 |
831 PluginMap::iterator pi = m_plugins.find(plugin); | 831 PluginMap::iterator pi = m_plugins.find(plugin); |
832 | 832 |
847 } | 847 } |
848 | 848 |
849 ProgressPrinter extractionProgress("Extracting and writing features..."); | 849 ProgressPrinter extractionProgress("Extracting and writing features..."); |
850 int progress = 0; | 850 int progress = 0; |
851 | 851 |
852 for (int i = startFrame; i < endFrame; i += m_blockSize) { | 852 for (sv_frame_t i = startFrame; i < endFrame; i += m_blockSize) { |
853 | 853 |
854 //!!! inefficient, although much of the inefficiency may be | 854 //!!! inefficient, although much of the inefficiency may be |
855 // susceptible to compiler optimisation | 855 // susceptible to compiler optimisation |
856 | 856 |
857 auto frames = reader->getInterleavedFrames(i, m_blockSize); | 857 auto frames = reader->getInterleavedFrames(i, m_blockSize); |
878 index = j * rc + c; | 878 index = j * rc + c; |
879 if (index < fc) data[0][j] += frames[index]; | 879 if (index < fc) data[0][j] += frames[index]; |
880 } | 880 } |
881 } | 881 } |
882 for (int j = 0; j < m_blockSize; ++j) { | 882 for (int j = 0; j < m_blockSize; ++j) { |
883 data[0][j] /= rc; | 883 data[0][j] /= float(rc); |
884 } | 884 } |
885 } else { | 885 } else { |
886 for (int c = 0; c < m_channels; ++c) { | 886 for (int c = 0; c < m_channels; ++c) { |
887 for (int j = 0; j < m_blockSize; ++j) { | 887 for (int j = 0; j < m_blockSize; ++j) { |
888 data[c][j] = 0.f; | 888 data[c][j] = 0.f; |
894 } | 894 } |
895 } | 895 } |
896 } | 896 } |
897 } | 897 } |
898 | 898 |
899 Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime | 899 RealTime timestamp = RealTime::frame2RealTime(i, m_sampleRate); |
900 (i, m_sampleRate); | |
901 | 900 |
902 foreach (Plugin *plugin, m_orderedPlugins) { | 901 foreach (Plugin *plugin, m_orderedPlugins) { |
903 | 902 |
904 PluginMap::iterator pi = m_plugins.find(plugin); | 903 PluginMap::iterator pi = m_plugins.find(plugin); |
905 | 904 |
908 // given plugin must have the same start time -- they can | 907 // given plugin must have the same start time -- they can |
909 // only differ in output and summary type.) | 908 // only differ in output and summary type.) |
910 bool inRange = false; | 909 bool inRange = false; |
911 for (TransformWriterMap::const_iterator ti = pi->second.begin(); | 910 for (TransformWriterMap::const_iterator ti = pi->second.begin(); |
912 ti != pi->second.end(); ++ti) { | 911 ti != pi->second.end(); ++ti) { |
913 int startFrame = RealTime::realTime2Frame | 912 sv_frame_t startFrame = RealTime::realTime2Frame |
914 (ti->first.getStartTime(), m_sampleRate); | 913 (ti->first.getStartTime(), m_sampleRate); |
915 if (i >= startFrame || i + m_blockSize > startFrame) { | 914 if (i >= startFrame || i + m_blockSize > startFrame) { |
916 inRange = true; | 915 inRange = true; |
917 break; | 916 break; |
918 } | 917 } |
919 } | 918 } |
920 if (!inRange) { | 919 if (!inRange) { |
921 continue; | 920 continue; |
922 } | 921 } |
923 | 922 |
924 Plugin::FeatureSet featureSet = plugin->process(data, timestamp); | 923 Plugin::FeatureSet featureSet = |
924 plugin->process(data, timestamp.toVampRealTime()); | |
925 | 925 |
926 if (!m_summariesOnly) { | 926 if (!m_summariesOnly) { |
927 writeFeatures(audioSource, plugin, featureSet); | 927 writeFeatures(audioSource, plugin, featureSet); |
928 } | 928 } |
929 } | 929 } |
930 | 930 |
931 int pp = progress; | 931 int pp = progress; |
932 progress = int(((i - startFrame) * 100.0) / (endFrame - startFrame) + 0.1); | 932 progress = int((double(i - startFrame) * 100.0) / |
933 double(endFrame - startFrame) + 0.1); | |
933 if (progress > pp && m_verbose) extractionProgress.setProgress(progress); | 934 if (progress > pp && m_verbose) extractionProgress.setProgress(progress); |
934 } | 935 } |
935 | 936 |
936 SVDEBUG << "FeatureExtractionManager: deleting audio file reader" << endl; | 937 SVDEBUG << "FeatureExtractionManager: deleting audio file reader" << endl; |
937 | 938 |
938 lifemgr.destroy(); // deletes reader, data | 939 lifemgr.destroy(); // deletes reader, data |
939 | 940 |
940 foreach (Plugin *plugin, m_orderedPlugins) { | 941 foreach (Plugin *plugin, m_orderedPlugins) { |
941 | 942 |
942 PluginMap::iterator pi = m_plugins.find(plugin); | |
943 Plugin::FeatureSet featureSet = plugin->getRemainingFeatures(); | 943 Plugin::FeatureSet featureSet = plugin->getRemainingFeatures(); |
944 | 944 |
945 if (!m_summariesOnly) { | 945 if (!m_summariesOnly) { |
946 writeFeatures(audioSource, plugin, featureSet); | 946 writeFeatures(audioSource, plugin, featureSet); |
947 } | 947 } |