qb / main audionode.hpp

Tree @main (Download .tar.gz)

audionode.hpp @main

#ifndef audionode_hpp
#define audionode_hpp

#include <vector>

#include "qb.hpp"

#include "AudioFile/AudioFile.h"

namespace qb {
  using audio_file = AudioFile<float>;
  using audio_file_ptr = std::shared_ptr<audio_file>;
  using audio_file_cptr = std::shared_ptr<const audio_file>;

  struct audio_node : public node {
    audio_node(const context *c, const std::string &path);
    ~audio_node() override;

    const std::string &path() const { return _path; }
    load_state loadstate() const { return _loadstate; }
    const audio_file_cptr data() const { return _data; }

    const std::vector<float>& rendered() const;
    // number of render samples per frame
    double rsamplerate() const;

    // samples packed the way saudio likes them
    const std::vector<float>& packed() const;

    int minframe() const override;
    int maxframe() const override;

    void load_async();
    std::vector<float> render_samples(double rsamplerate);

    const std::string _path;
    audio_file_ptr _data;
    std::vector<float> _rhi;
    std::vector<float> _rlo;
    std::vector<float> _packed;
    load_state _loadstate;