summaryrefslogtreecommitdiff
path: root/os2eindopdracht/SampleStream.cpp
blob: b9fd5421b0b21983be18e905b3a64bd8f7214067 (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
#include <algorithm>

#include "SampleStream.h"

using std::string;

SampleStream::SampleStream(string input_stream) {
  load(input_stream);

  // test direct sample editing:
  // std::transform(_stream.begin(), _stream.end(), _stream.begin(), [](int16_t s) { return s/2; });
}

void SampleStream::load(string input) {
  _stream.clear();
  for (unsigned long i = 0; i < input.size(); i += 2)
    _stream.push_back(((input[i] & 0xff) << 0) | ((input[i+1] & 0xff) << 8));
}

string SampleStream::save() {
  string out;
  for (int16_t sample : _stream) {
    out.push_back((sample >> 0) & 0xff);
    out.push_back((sample >> 8) & 0xff);
  }
  return out;
}