Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/faudio/src/FACT_internal.h
4389 views
1
/* FAudio - XAudio Reimplementation for FNA
2
*
3
* Copyright (c) 2011-2024 Ethan Lee, Luigi Auriemma, and the MonoGame Team
4
*
5
* This software is provided 'as-is', without any express or implied warranty.
6
* In no event will the authors be held liable for any damages arising from
7
* the use of this software.
8
*
9
* Permission is granted to anyone to use this software for any purpose,
10
* including commercial applications, and to alter it and redistribute it
11
* freely, subject to the following restrictions:
12
*
13
* 1. The origin of this software must not be misrepresented; you must not
14
* claim that you wrote the original software. If you use this software in a
15
* product, an acknowledgment in the product documentation would be
16
* appreciated but is not required.
17
*
18
* 2. Altered source versions must be plainly marked as such, and must not be
19
* misrepresented as being the original software.
20
*
21
* 3. This notice may not be removed or altered from any source distribution.
22
*
23
* Ethan "flibitijibibo" Lee <[email protected]>
24
*
25
*/
26
27
#include "FACT.h"
28
#include "FACT3D.h"
29
#include "FAudio_internal.h"
30
31
/* Internal AudioEngine Types */
32
33
typedef struct FACTAudioCategory
34
{
35
uint8_t instanceLimit;
36
uint16_t fadeInMS;
37
uint16_t fadeOutMS;
38
uint8_t maxInstanceBehavior;
39
int16_t parentCategory;
40
float volume;
41
uint8_t visibility;
42
43
uint8_t instanceCount;
44
float currentVolume;
45
} FACTAudioCategory;
46
47
typedef struct FACTVariable
48
{
49
uint8_t accessibility;
50
float initialValue;
51
float minValue;
52
float maxValue;
53
} FACTVariable;
54
55
typedef struct FACTRPCPoint
56
{
57
float x;
58
float y;
59
uint8_t type;
60
} FACTRPCPoint;
61
62
typedef enum FACTRPCParameter
63
{
64
RPC_PARAMETER_VOLUME,
65
RPC_PARAMETER_PITCH,
66
RPC_PARAMETER_REVERBSEND,
67
RPC_PARAMETER_FILTERFREQUENCY,
68
RPC_PARAMETER_FILTERQFACTOR,
69
RPC_PARAMETER_COUNT /* If >=, DSP Parameter! */
70
} FACTRPCParameter;
71
72
typedef struct FACTRPC
73
{
74
uint16_t variable;
75
uint8_t pointCount;
76
uint16_t parameter;
77
FACTRPCPoint *points;
78
} FACTRPC;
79
80
typedef struct FACTDSPParameter
81
{
82
uint8_t type;
83
float value;
84
float minVal;
85
float maxVal;
86
uint16_t unknown;
87
} FACTDSPParameter;
88
89
typedef struct FACTDSPPreset
90
{
91
uint8_t accessibility;
92
uint16_t parameterCount;
93
FACTDSPParameter *parameters;
94
} FACTDSPPreset;
95
96
typedef enum FACTNoticationsFlags
97
{
98
NOTIFY_CUEPREPARED = 0x00000001,
99
NOTIFY_CUEPLAY = 0x00000002,
100
NOTIFY_CUESTOP = 0x00000004,
101
NOTIFY_CUEDESTROY = 0x00000008,
102
NOTIFY_MARKER = 0x00000010,
103
NOTIFY_SOUNDBANKDESTROY = 0x00000020,
104
NOTIFY_WAVEBANKDESTROY = 0x00000040,
105
NOTIFY_LOCALVARIABLECHANGED = 0x00000080,
106
NOTIFY_GLOBALVARIABLECHANGED = 0x00000100,
107
NOTIFY_GUICONNECTED = 0x00000200,
108
NOTIFY_GUIDISCONNECTED = 0x00000400,
109
NOTIFY_WAVEPREPARED = 0x00000800,
110
NOTIFY_WAVEPLAY = 0x00001000,
111
NOTIFY_WAVESTOP = 0x00002000,
112
NOTIFY_WAVELOOPED = 0x00004000,
113
NOTIFY_WAVEDESTROY = 0x00008000,
114
NOTIFY_WAVEBANKPREPARED = 0x00010000,
115
NOTIFY_WAVEBANKSTREAMING_INVALIDCONTENT = 0x00020000
116
} FACTNoticationsFlags;
117
118
/* Internal SoundBank Types */
119
120
typedef enum
121
{
122
FACTEVENT_STOP = 0,
123
FACTEVENT_PLAYWAVE = 1,
124
FACTEVENT_PLAYWAVETRACKVARIATION = 3,
125
FACTEVENT_PLAYWAVEEFFECTVARIATION = 4,
126
FACTEVENT_PLAYWAVETRACKEFFECTVARIATION = 6,
127
FACTEVENT_PITCH = 7,
128
FACTEVENT_VOLUME = 8,
129
FACTEVENT_MARKER = 9,
130
FACTEVENT_PITCHREPEATING = 16,
131
FACTEVENT_VOLUMEREPEATING = 17,
132
FACTEVENT_MARKERREPEATING = 18
133
} FACTEventType;
134
135
typedef struct FACTEvent
136
{
137
uint16_t type;
138
uint16_t timestamp;
139
uint16_t randomOffset;
140
FAUDIONAMELESS union
141
{
142
/* Play Wave Event */
143
struct
144
{
145
uint8_t flags;
146
uint8_t loopCount;
147
uint16_t position;
148
uint16_t angle;
149
150
/* Track Variation */
151
uint8_t isComplex;
152
FAUDIONAMELESS union
153
{
154
struct
155
{
156
uint16_t track;
157
uint8_t wavebank;
158
} simple;
159
struct
160
{
161
uint16_t variation;
162
uint16_t trackCount;
163
uint16_t *tracks;
164
uint8_t *wavebanks;
165
uint8_t *weights;
166
} complex;
167
};
168
169
/* Effect Variation */
170
int16_t minPitch;
171
int16_t maxPitch;
172
float minVolume;
173
float maxVolume;
174
float minFrequency;
175
float maxFrequency;
176
float minQFactor;
177
float maxQFactor;
178
uint16_t variationFlags;
179
} wave;
180
/* Set Pitch/Volume Event */
181
struct
182
{
183
uint8_t settings;
184
uint16_t repeats;
185
uint16_t frequency;
186
FAUDIONAMELESS union
187
{
188
struct
189
{
190
float initialValue;
191
float initialSlope;
192
float slopeDelta;
193
uint16_t duration;
194
} ramp;
195
struct
196
{
197
uint8_t flags;
198
float value1;
199
float value2;
200
} equation;
201
};
202
} value;
203
/* Stop Event */
204
struct
205
{
206
uint8_t flags;
207
} stop;
208
/* Marker Event */
209
struct
210
{
211
uint32_t marker;
212
uint16_t repeats;
213
uint16_t frequency;
214
} marker;
215
};
216
} FACTEvent;
217
218
typedef struct FACTTrack
219
{
220
uint32_t code;
221
222
float volume;
223
uint8_t filter;
224
uint8_t qfactor;
225
uint16_t frequency;
226
227
uint8_t rpcCodeCount;
228
uint32_t *rpcCodes;
229
230
uint8_t eventCount;
231
FACTEvent *events;
232
} FACTTrack;
233
234
typedef struct FACTSound
235
{
236
uint8_t flags;
237
uint16_t category;
238
float volume;
239
int16_t pitch;
240
uint8_t priority;
241
242
uint8_t trackCount;
243
uint8_t rpcCodeCount;
244
uint8_t dspCodeCount;
245
246
FACTTrack *tracks;
247
uint32_t *rpcCodes;
248
uint32_t *dspCodes;
249
} FACTSound;
250
251
typedef struct FACTCueData
252
{
253
uint8_t flags;
254
uint32_t sbCode;
255
uint32_t transitionOffset;
256
uint8_t instanceLimit;
257
uint16_t fadeInMS;
258
uint16_t fadeOutMS;
259
uint8_t maxInstanceBehavior;
260
uint8_t instanceCount;
261
} FACTCueData;
262
263
typedef struct FACTVariation
264
{
265
FAUDIONAMELESS union
266
{
267
struct
268
{
269
uint16_t track;
270
uint8_t wavebank;
271
} simple;
272
uint32_t soundCode;
273
};
274
float minWeight;
275
float maxWeight;
276
uint32_t linger;
277
} FACTVariation;
278
279
typedef struct FACTVariationTable
280
{
281
uint8_t flags;
282
int16_t variable;
283
uint8_t isComplex;
284
285
uint16_t entryCount;
286
FACTVariation *entries;
287
} FACTVariationTable;
288
289
typedef struct FACTTransition
290
{
291
int32_t soundCode;
292
uint32_t srcMarkerMin;
293
uint32_t srcMarkerMax;
294
uint32_t dstMarkerMin;
295
uint32_t dstMarkerMax;
296
uint16_t fadeIn;
297
uint16_t fadeOut;
298
uint16_t flags;
299
} FACTTransition;
300
301
typedef struct FACTTransitionTable
302
{
303
uint32_t entryCount;
304
FACTTransition *entries;
305
} FACTTransitionTable;
306
307
/* Internal WaveBank Types */
308
309
typedef struct FACTSeekTable
310
{
311
uint32_t entryCount;
312
uint32_t *entries;
313
} FACTSeekTable;
314
315
/* Internal Cue Types */
316
317
typedef struct FACTInstanceRPCData
318
{
319
float rpcVolume;
320
float rpcPitch;
321
float rpcReverbSend;
322
float rpcFilterFreq;
323
float rpcFilterQFactor;
324
} FACTInstanceRPCData;
325
326
typedef struct FACTEventInstance
327
{
328
uint32_t timestamp;
329
uint16_t loopCount;
330
uint8_t finished;
331
FAUDIONAMELESS union
332
{
333
float value;
334
uint32_t valuei;
335
};
336
} FACTEventInstance;
337
338
typedef struct FACTTrackInstance
339
{
340
/* Tracks which events have fired */
341
FACTEventInstance *events;
342
343
/* RPC instance data */
344
FACTInstanceRPCData rpcData;
345
346
/* SetPitch/SetVolume data */
347
float evtPitch;
348
float evtVolume;
349
350
/* Wave playback */
351
struct
352
{
353
FACTWave *wave;
354
float baseVolume;
355
int16_t basePitch;
356
float baseQFactor;
357
float baseFrequency;
358
} activeWave, upcomingWave;
359
FACTEvent *waveEvt;
360
FACTEventInstance *waveEvtInst;
361
} FACTTrackInstance;
362
363
typedef struct FACTSoundInstance
364
{
365
/* Base Sound reference */
366
FACTSound *sound;
367
368
/* Per-instance track information */
369
FACTTrackInstance *tracks;
370
371
/* RPC instance data */
372
FACTInstanceRPCData rpcData;
373
374
/* Fade data */
375
uint32_t fadeStart;
376
uint16_t fadeTarget;
377
uint8_t fadeType; /* In (1), Out (2), Release RPC (3) */
378
379
/* Engine references */
380
FACTCue *parentCue;
381
} FACTSoundInstance;
382
383
/* Internal Wave Types */
384
385
typedef struct FACTWaveCallback
386
{
387
FAudioVoiceCallback callback;
388
FACTWave *wave;
389
} FACTWaveCallback;
390
391
/* Public XACT Types */
392
393
struct FACTAudioEngine
394
{
395
uint32_t refcount;
396
FACTNotificationCallback notificationCallback;
397
FACTReadFileCallback pReadFile;
398
FACTGetOverlappedResultCallback pGetOverlappedResult;
399
400
uint16_t categoryCount;
401
uint16_t variableCount;
402
uint16_t rpcCount;
403
uint16_t dspPresetCount;
404
uint16_t dspParameterCount;
405
406
char **categoryNames;
407
char **variableNames;
408
uint32_t *rpcCodes;
409
uint32_t *dspPresetCodes;
410
411
FACTAudioCategory *categories;
412
FACTVariable *variables;
413
FACTRPC *rpcs;
414
FACTDSPPreset *dspPresets;
415
416
/* Engine references */
417
LinkedList *sbList;
418
LinkedList *wbList;
419
FAudioMutex sbLock;
420
FAudioMutex wbLock;
421
float *globalVariableValues;
422
423
/* FAudio references */
424
FAudio *audio;
425
FAudioMasteringVoice *master;
426
FAudioSubmixVoice *reverbVoice;
427
428
/* Engine thread */
429
FAudioThread apiThread;
430
FAudioMutex apiLock;
431
uint8_t initialized;
432
433
/* Allocator callbacks */
434
FAudioMallocFunc pMalloc;
435
FAudioFreeFunc pFree;
436
FAudioReallocFunc pRealloc;
437
438
/* Peristent Notifications */
439
FACTNoticationsFlags notifications;
440
void *cue_context;
441
void *sb_context;
442
void *wb_context;
443
void *wave_context;
444
LinkedList *wb_notifications_list;
445
446
/* Settings handle */
447
void *settings;
448
};
449
450
struct FACTSoundBank
451
{
452
/* Engine references */
453
FACTAudioEngine *parentEngine;
454
FACTCue *cueList;
455
uint8_t notifyOnDestroy;
456
void *usercontext;
457
458
/* Array sizes */
459
uint16_t cueCount;
460
uint8_t wavebankCount;
461
uint16_t soundCount;
462
uint16_t variationCount;
463
uint16_t transitionCount;
464
465
/* Strings, strings everywhere! */
466
char **wavebankNames;
467
char **cueNames;
468
469
/* Actual SoundBank information */
470
char *name;
471
FACTCueData *cues;
472
FACTSound *sounds;
473
uint32_t *soundCodes;
474
FACTVariationTable *variations;
475
uint32_t *variationCodes;
476
FACTTransitionTable *transitions;
477
uint32_t *transitionCodes;
478
};
479
480
struct FACTWaveBank
481
{
482
/* Engine references */
483
FACTAudioEngine *parentEngine;
484
LinkedList *waveList;
485
FAudioMutex waveLock;
486
uint8_t notifyOnDestroy;
487
void *usercontext;
488
489
/* Actual WaveBank information */
490
char *name;
491
uint32_t entryCount;
492
FACTWaveBankEntry *entries;
493
uint32_t *entryRefs;
494
FACTSeekTable *seekTables;
495
char *waveBankNames;
496
497
/* I/O information */
498
uint32_t packetSize;
499
uint16_t streaming;
500
uint8_t *packetBuffer;
501
uint32_t packetBufferLen;
502
void* io;
503
};
504
505
struct FACTWave
506
{
507
/* Engine references */
508
FACTWaveBank *parentBank;
509
FACTCue *parentCue;
510
uint16_t index;
511
uint8_t notifyOnDestroy;
512
void *usercontext;
513
514
/* Playback */
515
uint32_t state;
516
float volume;
517
int16_t pitch;
518
uint8_t loopCount;
519
520
/* Stream data */
521
uint32_t streamSize;
522
uint32_t streamOffset;
523
uint8_t *streamCache;
524
525
/* FAudio references */
526
uint16_t srcChannels;
527
FAudioSourceVoice *voice;
528
FACTWaveCallback callback;
529
};
530
531
struct FACTCue
532
{
533
/* Engine references */
534
FACTSoundBank *parentBank;
535
FACTCue *next;
536
uint8_t managed;
537
uint16_t index;
538
uint8_t notifyOnDestroy;
539
void *usercontext;
540
541
/* Sound data */
542
FACTCueData *data;
543
FAUDIONAMELESS union
544
{
545
FACTVariationTable *variation;
546
547
/* This is only used in scenarios where there is only one
548
* Sound; XACT does not generate variation tables for
549
* Cues with only one Sound.
550
*/
551
FACTSound *sound;
552
};
553
554
/* Instance data */
555
float *variableValues;
556
float interactive;
557
558
/* Playback */
559
uint32_t state;
560
FACTWave *simpleWave;
561
FACTSoundInstance *playingSound;
562
FACTVariation *playingVariation;
563
uint32_t maxRpcReleaseTime;
564
565
/* 3D Data */
566
uint8_t active3D;
567
uint32_t srcChannels;
568
uint32_t dstChannels;
569
float matrixCoefficients[2 * 8]; /* Stereo input, 7.1 output */
570
571
/* Timer */
572
uint32_t start;
573
uint32_t elapsed;
574
};
575
576
/* Internal functions */
577
578
void FACT_INTERNAL_GetNextWave(
579
FACTCue *cue,
580
FACTSound *sound,
581
FACTTrack *track,
582
FACTTrackInstance *trackInst,
583
FACTEvent *evt,
584
FACTEventInstance *evtInst
585
);
586
uint8_t FACT_INTERNAL_CreateSound(FACTCue *cue, uint16_t fadeInMS);
587
void FACT_INTERNAL_DestroySound(FACTSoundInstance *sound);
588
void FACT_INTERNAL_BeginFadeOut(FACTSoundInstance *sound, uint16_t fadeOutMS);
589
void FACT_INTERNAL_BeginReleaseRPC(FACTSoundInstance *sound, uint16_t releaseMS);
590
591
void FACT_INTERNAL_SendCueNotification(FACTCue *cue, FACTNoticationsFlags flag, uint8_t type);
592
593
/* RPC Helper Functions */
594
595
FACTRPC* FACT_INTERNAL_GetRPC(FACTAudioEngine *engine, uint32_t code);
596
597
/* FACT Thread */
598
599
int32_t FAUDIOCALL FACT_INTERNAL_APIThread(void* enginePtr);
600
601
/* FAudio callbacks */
602
603
void FACT_INTERNAL_OnBufferEnd(FAudioVoiceCallback *callback, void* pContext);
604
void FACT_INTERNAL_OnStreamEnd(FAudioVoiceCallback *callback);
605
606
/* FAudioIOStream functions */
607
608
int32_t FACTCALL FACT_INTERNAL_DefaultReadFile(
609
void *hFile,
610
void *buffer,
611
uint32_t nNumberOfBytesToRead,
612
uint32_t *lpNumberOfBytesRead,
613
FACTOverlapped *lpOverlapped
614
);
615
616
int32_t FACTCALL FACT_INTERNAL_DefaultGetOverlappedResult(
617
void *hFile,
618
FACTOverlapped *lpOverlapped,
619
uint32_t *lpNumberOfBytesTransferred,
620
int32_t bWait
621
);
622
623
/* Parsing functions */
624
625
uint32_t FACT_INTERNAL_ParseAudioEngine(
626
FACTAudioEngine *pEngine,
627
const FACTRuntimeParameters *pParams
628
);
629
uint32_t FACT_INTERNAL_ParseSoundBank(
630
FACTAudioEngine *pEngine,
631
const void *pvBuffer,
632
uint32_t dwSize,
633
FACTSoundBank **ppSoundBank
634
);
635
uint32_t FACT_INTERNAL_ParseWaveBank(
636
FACTAudioEngine *pEngine,
637
void* io,
638
uint32_t offset,
639
uint32_t packetSize,
640
FACTReadFileCallback pRead,
641
FACTGetOverlappedResultCallback pOverlap,
642
uint16_t isStreaming,
643
FACTWaveBank **ppWaveBank
644
);
645
646
/* vim: set noexpandtab shiftwidth=8 tabstop=8: */
647
648