-
Notifications
You must be signed in to change notification settings - Fork 1
/
Buffer.cpp
164 lines (134 loc) · 4.76 KB
/
Buffer.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
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
163
164
#include "Common.h"
ALBuffer* Extension::BufferGetFromName(const char* Name)
{
map<string, ALBuffer>::iterator FoundBuffer = BufferMap.find(Name);
//A buffer with the name was found, return its handle.
if(FoundBuffer != BufferMap.end())
return &FoundBuffer->second;
//Nothing found, return zero.
return 0;
}
/* Actions */
void Extension::BufferCreateSampleForFile(const char* Name, const char* FilePath)
{
//Do not allow empty names.
if(*Name)
{
//Select the buffer for editing.
ALBuffer* Buffer = &BufferMap[Name];
DeleteBuffer(Buffer);
//Let Alure load the file and generate the buffer object.
Buffer->Handle = alureCreateBufferFromFile(FilePath);
Buffer->Type = BUFFER_TYPE_SAMPLE;
}
}
void Extension::BufferCreateStreamForFile(const char* Name, const char* FilePath)
{
//Do not allow empty names.
if(*Name)
{
//Select the buffer for editing.
ALBuffer* Buffer = &BufferMap[Name];
DeleteBuffer(Buffer);
//Let Alure load the file and generate the buffer object.
alureStreamSizeIsMicroSec(true);
Buffer->Stream = alureCreateStreamFromFile(FilePath, 250000, 0, 0);
Buffer->Type = BUFFER_TYPE_STREAM;
}
}
void Extension::BufferCreateSampleForMemory(const char* Name, const ALubyte* Address, unsigned int Size)
{
//Do not allow empty names.
if(*Name)
{
//Select the buffer for editing.
ALBuffer* Buffer = &BufferMap[Name];
DeleteBuffer(Buffer);
//Let Alure generate the buffer object.
Buffer->Handle = alureCreateBufferFromMemory(Address, Size);
Buffer->Type = BUFFER_TYPE_SAMPLE;
}
}
void Extension::BufferCreateSampleForMMF(const char* Name, const char* MMFName)
{
//Find the MMF sound with the given name.
unsigned int MMFID = FindSndFromName(rhPtr->rhIdAppli, SP_WAVE, MMFName);
//Do not allow empty names.
if(*Name && MMFID)
{
//Select the buffer for editing.
ALBuffer* Buffer = &BufferMap[Name];
DeleteBuffer(Buffer);
//Get MMF sound's data + size.
Sound MMFSound;
GetSoundInfo(rhPtr->rhIdAppli, MMFID, &MMFSound);
BYTE* Data = GetSoundDataPtr(rhPtr->rhIdAppli, MMFID);
//Let Alure generate the buffer object.
Buffer->Handle = alureCreateBufferFromMemory(Data, MMFSound.snSize-MMFSound.snNameSize);
Buffer->Type = BUFFER_TYPE_SAMPLE;
}
}
void Extension::BufferCreateStreamForCapture(const char* Name)
{
//Do not allow empty names.
if(*Name)
{
//Select the buffer for editing.
ALBuffer*Buffer = &BufferMap[Name];
DeleteBuffer(Buffer);
CaptureRecalculateSettings();
//Let Alure load the file and generate the buffer object.
alureStreamSizeIsMicroSec(false);
Buffer->Stream = alureCreateStreamFromCallback(StreamCaptureCallback, this, Input.Format, Input.Frequency, Input.BufferSamples, 0, 0);
Buffer->Type = BUFFER_TYPE_STREAM;
}
}
void Extension::BufferCreateStreamForSignal(const char* Name, ALuint SampleRate, ALuint Channels, ALuint Bits, const char* Type, ALfloat Frequency, ALfloat ModulatorAmplitude, ALfloat ModulatorFrequency)
{
if(!*Name || Channels < 1 || Channels > 2 || (Bits != 8 && Bits != 16) || SampleRate < 0)
return;
//Get the signal type enum based on the name.
ALuint IntType = SIGNAL_TYPE_WHITENOISE;
if(!_strnicmp("sine", Type, 4))
IntType = SIGNAL_TYPE_SINE;
else if(!_strnicmp("saw", Type, 3))
IntType = SIGNAL_TYPE_SAW;
else if(!_strnicmp("square", Type, 6))
IntType = SIGNAL_TYPE_SQUARE;
else if(!_strnicmp("triangle", Type, 8))
IntType = SIGNAL_TYPE_TRIANGLE;
//Select the buffer for editing.
ALBuffer* Buffer = &BufferMap[Name];
DeleteBuffer(Buffer);
//Store the parameters in the signal object.
Buffer->Signal = new ALSignal(SampleRate, Channels, Bits, IntType, Frequency, ModulatorAmplitude, ModulatorFrequency);
//Let Alure load the file and generate the buffer object.
alureStreamSizeIsMicroSec(false);
GetALError();
Buffer->Stream = alureCreateStreamFromCallback(StreamSignalCallback, Buffer->Signal, alureGetSampleFormat(Channels, Bits, 0), SampleRate, 1024*Channels*Bits/8, 0, 0);
Buffer->Type = BUFFER_TYPE_STREAM;
}
void Extension::BufferCreateStreamForCallback(const char* Name, ALuint SampleRate, ALuint Channels, ALuint Bits, ALuint BufferSize)
{
if(!*Name || Channels < 1 || Channels > 2 || (Bits != 8 && Bits != 16) || SampleRate < 0 || BufferSize <= 0)
return;
//Select the buffer for editing.
ALBuffer* Buffer = &BufferMap[Name];
DeleteBuffer(Buffer);
//Let Alure load the file and generate the buffer object.
Buffer->Stream = alureCreateStreamFromCallback(StreamCustomCallback, this, alureGetSampleFormat(Channels, Bits, 0), SampleRate, BufferSize, 0, 0);
Buffer->Type = BUFFER_TYPE_STREAM;
}
void Extension::BufferCallbackWriteBytes(int Bytes)
{
CallbackWrittenBytes = max(0, Bytes);
}
/* Expressions */
int Extension::BufferCallbackGetAddress()
{
return (int)CallbackBuffer;
}
int Extension::BufferCallbackGetBytes()
{
return CallbackAvailableBytes;
}