summaryrefslogtreecommitdiffhomepage
path: root/PCM.h
blob: e7c7a5e52640955eddf770a2a3f58a952853cb41 (plain)
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
42
43
44
45
46
47
48
49
50
51
#pragma once

#include "config.h"
#include "debug.h"
#include "log.h"

#include <libreichwein/file.h>

#include <chrono>

#include <alsa/asoundlib.h>
#include <fmt/format.h>

#include <iostream>
#include <string>
#include <vector>

using namespace std::string_literals;

class PCM
{
public:
  PCM();
  ~PCM();

  void click(std::chrono::duration<double> offset);

  // generate 1 buffer size
  void generate();

  int fd();

  // write from buffer to ALSA PCM
  void write();

  bool wait_for_event();

  bool write_available();

private:
  int err;
  snd_pcm_t *handle;

  int npfd;
  struct pollfd* pfd;

  std::vector<uint16_t> m_data;
  int32_t m_phase;
  int16_t buffer[nframes];
};