summaryrefslogtreecommitdiffhomepage
path: root/ClickStream.h
blob: c94f8de27db522eb7ef0534d86c4c3f8f756a4dc (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
52
53
54
55
56
57
#pragma once

#include "config.h"

#include <libreichwein/file.h>

#include <cstring>
#include <string>
#include <vector>

class ClickStream
{
public:
  ClickStream(): m_phase(1000000)
  {
    std::string data_s = Reichwein::File::getFile("media/click.s16le");
    m_data.resize(data_s.size() / 2); // src is in bytes
    memcpy(m_data.data(), data_s.data(), data_s.size());
  }

  // generate 1 buffer size
  void generate()
  {
    int i;
    size_t j = m_phase;

    for (i = 0; i < nframes; i++) {
        if (j >= m_data.size())
        {
          buffer[i] = 0;
        }
        else
        {
          buffer[i] = m_data[j];
        }
        j++;
    }

    m_phase = j;
  }

  void click()
  {
    m_phase = 0;
  }

  int16_t* get_buffer()
  {
    return buffer;
  }

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