sampleDelay.hpp 974 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm

#pragma once

#include "libvideostitch/audioObject.hpp"
#include "libvideostitch/audioBlock.hpp"

#include <queue>
#include <mutex>

namespace VideoStitch {
namespace Audio {

static const double kMaxDelayTime = 20.0;  // Seconds

class SampleDelay : public AudioObject {
 public:
  static double getMaxDelaySeconds() { return kMaxDelayTime; }
  static size_t getMaxDelaySamples() { return (size_t)(kMaxDelayTime * getDefaultSamplingRate()); }

  SampleDelay();
  ~SampleDelay() {}

  Status setDelaySeconds(double delayInSeconds);
  double getDelaySeconds();
  void setDelaySamples(size_t delayInSamples);
  size_t getDelaySamples();

  void step(AudioBlock& out, const AudioBlock& in);
  void step(AudioBlock& buf);

 private:
  std::mutex delayMutex_;
  size_t curDelayTime_;

  std::map<ChannelMap, std::deque<audioSample_t>> delayBuffers_;
};

}  // namespace Audio
}  // namespace VideoStitch