Mercurial > hg > sonic-visualiser
comparison audioio/AudioCallbackPlaySource.cpp @ 41:fbd7a497fd89
* Audition effects plugins during playback
author | Chris Cannam |
---|---|
date | Wed, 04 Oct 2006 11:01:39 +0000 |
parents | e3b32dc5180b |
children | c0ae41c72421 |
comparison
equal
deleted
inserted
replaced
40:75c5951cf9d7 | 41:fbd7a497fd89 |
---|---|
21 #include "view/ViewManager.h" | 21 #include "view/ViewManager.h" |
22 #include "base/PlayParameterRepository.h" | 22 #include "base/PlayParameterRepository.h" |
23 #include "base/Preferences.h" | 23 #include "base/Preferences.h" |
24 #include "data/model/DenseTimeValueModel.h" | 24 #include "data/model/DenseTimeValueModel.h" |
25 #include "data/model/SparseOneDimensionalModel.h" | 25 #include "data/model/SparseOneDimensionalModel.h" |
26 #include "plugin/RealTimePluginInstance.h" | |
26 #include "PhaseVocoderTimeStretcher.h" | 27 #include "PhaseVocoderTimeStretcher.h" |
27 | 28 |
28 #include <iostream> | 29 #include <iostream> |
29 #include <cassert> | 30 #include <cassert> |
30 | 31 |
50 m_playing(false), | 51 m_playing(false), |
51 m_exiting(false), | 52 m_exiting(false), |
52 m_lastModelEndFrame(0), | 53 m_lastModelEndFrame(0), |
53 m_outputLeft(0.0), | 54 m_outputLeft(0.0), |
54 m_outputRight(0.0), | 55 m_outputRight(0.0), |
56 m_auditioningPlugin(0), | |
55 m_timeStretcher(0), | 57 m_timeStretcher(0), |
56 m_fillThread(0), | 58 m_fillThread(0), |
57 m_converter(0), | 59 m_converter(0), |
58 m_crapConverter(0), | 60 m_crapConverter(0), |
59 m_resampleQuality(Preferences::getInstance()->getResampleQuality()) | 61 m_resampleQuality(Preferences::getInstance()->getResampleQuality()) |
95 delete m_writeBuffers; | 97 delete m_writeBuffers; |
96 | 98 |
97 delete m_audioGenerator; | 99 delete m_audioGenerator; |
98 | 100 |
99 m_bufferScavenger.scavenge(true); | 101 m_bufferScavenger.scavenge(true); |
102 m_pluginScavenger.scavenge(true); | |
103 m_timeStretcherScavenger.scavenge(true); | |
100 } | 104 } |
101 | 105 |
102 void | 106 void |
103 AudioCallbackPlaySource::addModel(Model *model) | 107 AudioCallbackPlaySource::addModel(Model *model) |
104 { | 108 { |
637 #endif | 641 #endif |
638 | 642 |
639 initialiseConverter(); | 643 initialiseConverter(); |
640 } | 644 } |
641 | 645 |
646 void | |
647 AudioCallbackPlaySource::setAuditioningPlugin(RealTimePluginInstance *plugin) | |
648 { | |
649 RealTimePluginInstance *formerPlugin = m_auditioningPlugin; | |
650 m_auditioningPlugin = plugin; | |
651 if (formerPlugin) m_pluginScavenger.claim(formerPlugin); | |
652 } | |
653 | |
642 size_t | 654 size_t |
643 AudioCallbackPlaySource::getTargetSampleRate() const | 655 AudioCallbackPlaySource::getTargetSampleRate() const |
644 { | 656 { |
645 if (m_targetSampleRate) return m_targetSampleRate; | 657 if (m_targetSampleRate) return m_targetSampleRate; |
646 else return getSourceSampleRate(); | 658 else return getSourceSampleRate(); |
750 for (size_t i = got; i < count; ++i) { | 762 for (size_t i = got; i < count; ++i) { |
751 buffer[ch][i] = 0.0; | 763 buffer[ch][i] = 0.0; |
752 } | 764 } |
753 } | 765 } |
754 } | 766 } |
767 | |
768 applyAuditioningEffect(count, buffer); | |
755 | 769 |
756 m_condition.wakeAll(); | 770 m_condition.wakeAll(); |
757 return got; | 771 return got; |
758 } | 772 } |
759 | 773 |
844 for (size_t i = 0; i < count; ++i) { | 858 for (size_t i = 0; i < count; ++i) { |
845 buffer[0][i] /= channels; | 859 buffer[0][i] /= channels; |
846 } | 860 } |
847 } | 861 } |
848 | 862 |
863 applyAuditioningEffect(count, buffer); | |
864 | |
849 m_condition.wakeAll(); | 865 m_condition.wakeAll(); |
850 | 866 |
851 return count; | 867 return count; |
852 } | 868 } |
869 | |
870 void | |
871 AudioCallbackPlaySource::applyAuditioningEffect(size_t count, float **buffers) | |
872 { | |
873 RealTimePluginInstance *plugin = m_auditioningPlugin; | |
874 if (!plugin) return; | |
875 | |
876 if (plugin->getAudioInputCount() != getTargetChannelCount()) { | |
877 std::cerr << "plugin input count " << plugin->getAudioInputCount() | |
878 << " != our channel count " << getTargetChannelCount() | |
879 << std::endl; | |
880 return; | |
881 } | |
882 if (plugin->getAudioOutputCount() != getTargetChannelCount()) { | |
883 std::cerr << "plugin output count " << plugin->getAudioOutputCount() | |
884 << " != our channel count " << getTargetChannelCount() | |
885 << std::endl; | |
886 return; | |
887 } | |
888 if (plugin->getBufferSize() != count) { | |
889 std::cerr << "plugin buffer size " << plugin->getBufferSize() | |
890 << " != our block size " << count | |
891 << std::endl; | |
892 return; | |
893 } | |
894 | |
895 float **ib = plugin->getAudioInputBuffers(); | |
896 float **ob = plugin->getAudioOutputBuffers(); | |
897 | |
898 for (size_t c = 0; c < getTargetChannelCount(); ++c) { | |
899 for (size_t i = 0; i < count; ++i) { | |
900 ib[c][i] = buffers[c][i]; | |
901 } | |
902 } | |
903 | |
904 plugin->run(Vamp::RealTime::zeroTime); | |
905 | |
906 for (size_t c = 0; c < getTargetChannelCount(); ++c) { | |
907 for (size_t i = 0; i < count; ++i) { | |
908 buffers[c][i] = ob[c][i]; | |
909 } | |
910 } | |
911 } | |
853 | 912 |
854 // Called from fill thread, m_playing true, mutex held | 913 // Called from fill thread, m_playing true, mutex held |
855 bool | 914 bool |
856 AudioCallbackPlaySource::fillBuffers() | 915 AudioCallbackPlaySource::fillBuffers() |
857 { | 916 { |
1284 | 1343 |
1285 while (!s.m_exiting) { | 1344 while (!s.m_exiting) { |
1286 | 1345 |
1287 s.unifyRingBuffers(); | 1346 s.unifyRingBuffers(); |
1288 s.m_bufferScavenger.scavenge(); | 1347 s.m_bufferScavenger.scavenge(); |
1348 s.m_pluginScavenger.scavenge(); | |
1289 s.m_timeStretcherScavenger.scavenge(); | 1349 s.m_timeStretcherScavenger.scavenge(); |
1290 | 1350 |
1291 if (work && s.m_playing && s.getSourceSampleRate()) { | 1351 if (work && s.m_playing && s.getSourceSampleRate()) { |
1292 | 1352 |
1293 #ifdef DEBUG_AUDIO_PLAY_SOURCE | 1353 #ifdef DEBUG_AUDIO_PLAY_SOURCE |