main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <atomic>
  2. #include <memory>
  3. #include <string>
  4. #include <type_traits>
  5. #include "BellTask.h"
  6. #include "CentralAudioBuffer.h"
  7. #include "PortAudioSink.h"
  8. #include "StreamInfo.h"
  9. #define DEBUG_LEVEL 4
  10. #include <BellDSP.h>
  11. #include <BellLogger.h>
  12. std::shared_ptr<bell::CentralAudioBuffer> audioBuffer;
  13. std::atomic<bool> isPaused = false;
  14. class AudioPlayer : bell::Task {
  15. public:
  16. std::unique_ptr<PortAudioSink> audioSink;
  17. std::unique_ptr<bell::BellDSP> dsp;
  18. AudioPlayer() : bell::Task("player", 1024, 0, 0) {
  19. this->audioSink = std::make_unique<PortAudioSink>();
  20. this->audioSink->setParams(44100, 2, 16);
  21. this->dsp = std::make_unique<bell::BellDSP>(audioBuffer);
  22. startTask();
  23. }
  24. void runTask() override {
  25. while (true) {
  26. if (audioBuffer->hasAtLeast(64) || isPaused) {
  27. auto chunk = audioBuffer->readChunk();
  28. if (chunk != nullptr && chunk->pcmSize > 0) {
  29. this->dsp->process(chunk->pcmData, chunk->pcmSize, 2, 44100,
  30. bell::BitWidth::BW_16);
  31. this->audioSink->feedPCMFrames(chunk->pcmData, chunk->pcmSize);
  32. }
  33. }
  34. }
  35. }
  36. };
  37. int main() {
  38. bell::setDefaultLogger();
  39. BELL_LOG(info, "cock", "Published?");
  40. return 0;
  41. }