Repository navigation
Expand file tree
/
Copy pathaudio.cpp
More file actions
83 lines (69 loc) · 2.69 KB
/
Copy pathaudio.cpp
File metadata and controls
83 lines (69 loc) · 2.69 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <circle/timer.h>
#include <circle/synchronize.h>
#include <circle/memory.h>
#include <circle/logger.h>
#include <assert.h>
#include <circle/sound/pwmsoundbasedevice.h>
#include <circle/logger.h>
#include "audio.h"
#include "dsp.h"
#include "test-tone.h"
static const char FromPDDevice[] = "pd_device";
mydsp *dsp;
void extract(const char *name, float *p, float init, float min, float max, float step){};
void declare(struct UIGlue *uiInterface, float *p, const char* key, const char* val){};
void openVerticalBox(struct UIGlue *uiInterface, char* key){};
void openHorizontalBox(struct UIGlue *uiInterface, char* key){};
void closeBox(struct UIGlue *uiInterface){};
void addVerticalBargraph(struct UIGlue *uiInterface, const char *name, float *p, float f1, float f2){};
void addButton(struct UIGlue *uiInterface, const char *name, float *p){extract(name, p, 0, 0, 0, 0);};
void addVerticalSlider(struct UIGlue *uiInterface, const char *name, float *p, float init, float min, float max, float step){extract(name, p, init, min, max, step);};
void addHorizontalSlider(struct UIGlue *uiInterface, const char *name, float *p, float init, float min, float max, float step){extract(name, p, init, min, max, step);};
void addNumEntry(struct UIGlue *uiInterface, const char *name, float *p, float init, float min, float max, float step){extract(name, p, init, min, max, step);};
UIGlue ui_glue = {
NULL,
openVerticalBox,
openHorizontalBox,
closeBox,
declare,
addVerticalSlider,
addHorizontalSlider,
addNumEntry,
addVerticalBargraph,
addButton
};
float **outBuffers = NULL;
CPDPWM::CPDPWM(CInterruptSystem *pInterrupt)
: CPWMSoundBaseDevice (pInterrupt)
{
dsp = newmydsp();
initmydsp(dsp, 44100);
buildUserInterfacemydsp(dsp, &ui_glue);
}
CPDPWM::~CPDPWM(void)
{
}
unsigned CPDPWM::GetChunk (u32 *pBuffer, unsigned nChunkSize)
{
int min = GetRangeMin();
int max = GetRangeMax();
int dc = max / 2;
float scale = 0.1;
int numFrames = nChunkSize / 2;
if(outBuffers == NULL){
outBuffers = (float **) malloc(2 * sizeof(float *));
for (int i = 0; i < 2; ++i) {
outBuffers[i] = (float *) malloc(numFrames * sizeof(float));
}
CLogger::Get ()->Write (FromPDDevice, LogDebug, "Allocated buffers");
}
computemydsp(dsp, numFrames, NULL, outBuffers);
for(int i=0; i<nChunkSize/2; i++){
s16 left = (outBuffers[0][i] * scale * dc) + dc;
s16 right = (outBuffers[1][i] * scale * dc) + dc;
pBuffer[i * 2] = left;
pBuffer[i * 2 + 1] = right;
}
// CLogger::Get ()->Write (FromPDDevice, LogDebug, "Wrote %d bytes, min %d, max %d", nChunkSize, min ,max);
return nChunkSize;
}