-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.pas
163 lines (122 loc) · 2.89 KB
/
audio.pas
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
unit audio;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, SDL2, SDL2_Mixer, BaseTypes, Utility;
type
{ tAudioEngine }
rNote = record
Pitch, Velocity: word;
Duration, Position: single;
end;
rPattern = array of rNote;
{tPattern = class
A: array of ; default;
end;}
eEffect = (eNone, eUnderwater);
rTone = record
FS: tMemoryStream; //has memory pointer and loadfromfile, but sdl mixer also has load from file
end;
rTrack = record
Effect: eEffect;
Volume: single;
Patterns: array of rPattern;
Tones: array of rTone;
Sequence: array of integer;
end;
eToneKind = (tPercussion, tNormal);
{ tComposition }
tComposition = class
Seed: tSeed;
PercussionTracks: integer;
Tracks: array of rTrack;
procedure SynthesizeTones(TrackNr: integer; TK: eToneKind); //percussion in 0..n?
procedure ComposePatterns(TrackNr: integer; TK: eToneKind);
constructor Create(aSeed: tSeed);
destructor Destroy; override;
end;
{ tComposer }
tComposer = class
CurrentComp, NextComp: tComposition;
{function CompileWAV: pointer; //compiles next }
public
function GetNext: pointer; //returns pointer to wav, switches next to cur
constructor Create;
destructor Destroy; override;
end;
tAudioEngine = class //needs to be able to mix several simult as well as play in background
{queue
Files: array
function LoadFile(Filename: string): integer;
procedure PlayFile(Index: integer);
procedure StopPlayback;
procedure AddToQueue(index: integer); }
Composer: tComposer;
constructor Create;
destructor Destroy; override;
end;
var
AudioEngine: tAudioEngine;
implementation
{ tComposer }
function tComposer.GetNext: pointer;
begin
CurrentComp.Free;
CurrentComp:= NextComp;
NextComp:= tComposition.Create(random(high(tSeed)));
end;
constructor tComposer.Create;
begin
GetNext;
end;
destructor tComposer.Destroy;
begin
inherited Destroy;
CurrentComp.Free;
NextComp.Free;
end;
{ tComposition }
procedure tComposition.SynthesizeTones(TrackNr: integer; TK: eToneKind);
begin
with Tracks[TrackNr] do
begin
end;
end;
procedure tComposition.ComposePatterns(TrackNr: integer; TK: eToneKind);
begin
with Tracks[TrackNr] do
begin
end;
end;
constructor tComposition.Create(aSeed: tSeed);
var
i: integer;
TK: eToneKind;
begin
Seed:= aSeed;
setlength(Tracks, 2 + srand(4, Seed));
PercussionTracks:= length(Tracks) div 3;
TK:= tPercussion;
for i:= 0 to high(Tracks) do
begin
if i >= PercussionTracks then
TK:= tNormal;
SynthesizeTones(i, TK);
ComposePatterns(i, TK);
end;
end;
destructor tComposition.Destroy;
begin
inherited Destroy;
setlength(Tracks, 0);
end;
{ tAudioEngine }
constructor tAudioEngine.Create;
begin
Composer:= tComposer.Create;
end;
destructor tAudioEngine.Destroy;
begin
inherited Destroy;
end;
end.