-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMixer.h
87 lines (77 loc) · 2.67 KB
/
Mixer.h
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
84
85
86
87
#include <stdio.h>
#include "Slice.h"
struct Mixer {
int voices;
float volume;
float * streamR;
float * streamL;
}Mixer1;
int MixerUpdate(struct Mixer *mixer, int nframes) {
//Clean mixer stream
//mixer = malloc(sizeof(struct Mixer));
mixer->voices =0;
mixer->volume = 1;
mixer->streamR = malloc(sizeof(float)*nframes);
mixer->streamL = malloc(sizeof(float)*nframes);
/*
for(int i =0; i<nframes; i++)
{
mixer->streamR[i] = mixer->streamL[i] = 0;
}
*/
//Find number of voices playing
struct Slice *currentS;
struct Playback * currentP;
currentS = &EmptySlice;
while(currentS->next != NULL)
{
currentP = ¤tS->next->playback;
int playbackleft=1;
while(playbackleft)
{
if(currentP->state == "playing")
{
mixer->voices++;
}
if(currentP->next ==NULL) playbackleft=0;
else currentP = currentP->next;
}
currentS = currentS->next;
}
currentS = &EmptySlice;
currentP = ¤tS->next->playback;
//copy all the playbacks with their coefficients
while(currentS->next != NULL)
{
currentP = ¤tS->next->playback;
int playbackleft=1;
while(playbackleft)
{
if(currentP->state == "playing")
{
if(currentP->pos < currentS->next->length + nframes)
{
for( int i =0; i < nframes; i++)
{
mixer->streamL[i] += (float) (SliceVolume(currentS->next, currentP->pos)/mixer->voices) * currentS->next->stream[currentP->pos];
mixer->streamR[i] += (float) (SliceVolume(currentS->next, currentP->pos)/mixer->voices) * currentS->next->stream[currentP->pos];
currentP->pos++;
}
}
}
else if(currentP->state == "paused")
{
//Do nothing;
}
else {
currentP->state = "done";
currentP->pos = 0;
}
if(currentP->next ==NULL) playbackleft=0;
else currentP = currentP->next;
}
currentS = currentS->next;
}
//return the Mixer
return 0;
}