| 978 | } |
| 979 | |
| 980 | shared_ptr<Processor> Processor::createWithAutoInput( |
| 981 | shared_ptr<IInput> input) { |
| 982 | auto processor = make_shared<Processor>(); |
| 983 | processor->mAudioInput = input; |
| 984 | // weak_ptr so the lambda doesn't prevent Processor destruction |
| 985 | weak_ptr<Processor> weak = processor; |
| 986 | weak_ptr<IInput> weakInput = input; |
| 987 | processor->mAutoTask = fl::task::every_ms(1).then([weak, weakInput]() { |
| 988 | auto proc = weak.lock(); |
| 989 | auto inp = weakInput.lock(); |
| 990 | if (!proc || !inp) { |
| 991 | return; |
| 992 | } |
| 993 | vector_inlined<Sample, 16> samples; |
| 994 | inp->readAll(&samples); |
| 995 | for (const auto& sample : samples) { |
| 996 | proc->update(sample); |
| 997 | } |
| 998 | }); |
| 999 | return processor; |
| 1000 | } |
| 1001 | |
| 1002 | } // namespace audio |
| 1003 | } // namespace fl |