spek

Acoustic spectrum analyser https://github.com/alexkay/spek spek.cc
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

spek-audio.h (1339B)


      1 #pragma once
      2 
      3 #include <memory>
      4 #include <ostream>
      5 #include <string>
      6 
      7 class AudioFile;
      8 enum class AudioError;
      9 
     10 class Audio
     11 {
     12 public:
     13     Audio();
     14     ~Audio();
     15 
     16     std::unique_ptr<AudioFile> open(const std::string& file_name, int stream);
     17 };
     18 
     19 class AudioFile
     20 {
     21 public:
     22     virtual ~AudioFile() {}
     23 
     24     virtual void start(int channel, int samples) = 0;
     25     virtual int read() = 0;
     26 
     27     virtual AudioError get_error() const = 0;
     28     virtual std::string get_codec_name() const = 0;
     29     virtual int get_bit_rate() const = 0;
     30     virtual int get_sample_rate() const = 0;
     31     virtual int get_bits_per_sample() const = 0;
     32     virtual int get_streams() const = 0;
     33     virtual int get_channels() const = 0;
     34     virtual double get_duration() const = 0;
     35     virtual const float *get_buffer() const = 0;
     36     virtual int64_t get_frames_per_interval() const = 0;
     37     virtual int64_t get_error_per_interval() const = 0;
     38     virtual int64_t get_error_base() const = 0;
     39 };
     40 
     41 enum class AudioError
     42 {
     43     OK,
     44     CANNOT_OPEN_FILE,
     45     NO_STREAMS,
     46     NO_AUDIO,
     47     NO_DECODER,
     48     NO_DURATION,
     49     NO_CHANNELS,
     50     CANNOT_OPEN_DECODER,
     51     BAD_SAMPLE_FORMAT,
     52 };
     53 
     54 inline bool operator!(AudioError error) {
     55     return error == AudioError::OK;
     56 }
     57 
     58 inline std::ostream& operator<<(std::ostream& os, AudioError error) {
     59     return os << static_cast<int>(error);
     60 }