-
Notifications
You must be signed in to change notification settings - Fork 2
/
Recorder.cpp
58 lines (50 loc) · 1.03 KB
/
Recorder.cpp
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
58
//
// Recorder.cpp
// DSPLibrary
//
// Created by Mayank on 11/4/12.
// Copyright (c) 2012 Mayank Sanganeria. All rights reserved.
//
#include "Recorder.h"
void Recorder::setLength(const float withLength, float withFs)
{
length = withLength * withFs;
buffer = new float[length];
clearBuffer(); // clear the buffer before we start writing into it
readHead = 0;
writeHead = 0;
}
void Recorder::clearBuffer()
{
for (int i = 0; i < length; i++) { // clear buffer
buffer[i] = 0;
}
}
void Recorder::advanceWriteHead()
{
writeHead = writeHead++;
if (writeHead==length)
{
float *oldBuffer = buffer;
length*=2;
buffer = new float[length];
clearBuffer();
for (int i=0;i<length/2;i++)
{
buffer[i]=oldBuffer[i];
}
delete oldBuffer;
}
}
void Recorder::advanceReadHead()
{
readHead++;
}
void Recorder::write(float withSample)
{
buffer[writeHead] = withSample;
}
float Recorder::read()
{
return buffer[readHead];
}