forked from kcat/dsoal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eax4.c
1522 lines (1330 loc) · 57.8 KB
/
eax4.c
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* DirectSound EAX interface
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define CONST_VTABLE
#include <stdarg.h>
#include <string.h>
#include "windows.h"
#include "dsound_wrap.h"
#include "dsound_private.h"
#include "eax-presets.h"
static const char *debug_fxslot(const GUID *guid)
{
#define HANDLE_ID(id) if(IsEqualGUID(guid, &(id))) return #id
HANDLE_ID(EAX_NULL_GUID);
HANDLE_ID(EAX_PrimaryFXSlotID);
HANDLE_ID(EAXPROPERTYID_EAX40_FXSlot0);
HANDLE_ID(EAXPROPERTYID_EAX40_FXSlot1);
HANDLE_ID(EAXPROPERTYID_EAX40_FXSlot2);
HANDLE_ID(EAXPROPERTYID_EAX40_FXSlot3);
#undef HANDLE_ID
return debugstr_guid(guid);
}
static const char *debug_fxguid(const GUID *guid)
{
#define HANDLE_ID(id) if(IsEqualGUID(guid, &(id))) return #id
HANDLE_ID(EAX_NULL_GUID);
HANDLE_ID(EAX_REVERB_EFFECT);
HANDLE_ID(EAX_AGCCOMPRESSOR_EFFECT);
HANDLE_ID(EAX_AUTOWAH_EFFECT);
HANDLE_ID(EAX_CHORUS_EFFECT);
HANDLE_ID(EAX_DISTORTION_EFFECT);
HANDLE_ID(EAX_ECHO_EFFECT);
HANDLE_ID(EAX_EQUALIZER_EFFECT);
HANDLE_ID(EAX_FLANGER_EFFECT);
HANDLE_ID(EAX_FREQUENCYSHIFTER_EFFECT);
HANDLE_ID(EAX_VOCALMORPHER_EFFECT);
HANDLE_ID(EAX_PITCHSHIFTER_EFFECT);
HANDLE_ID(EAX_RINGMODULATOR_EFFECT);
#undef HANDLE_ID
return debugstr_guid(guid);
}
HRESULT EAX4Context_Query(DSPrimary *prim, DWORD propid, ULONG *pTypeSupport)
{
if(!HAS_EXTENSION(prim->share, EXT_EFX))
return E_PROP_ID_UNSUPPORTED;
switch((propid&~EAXCONTEXT_PARAMETER_DEFERRED))
{
case EAXCONTEXT_NONE:
case EAXCONTEXT_ALLPARAMETERS:
case EAXCONTEXT_PRIMARYFXSLOTID:
case EAXCONTEXT_DISTANCEFACTOR:
case EAXCONTEXT_AIRABSORPTIONHF:
case EAXCONTEXT_HFREFERENCE:
case EAXCONTEXT_LASTERROR:
*pTypeSupport = KSPROPERTY_SUPPORT_GET | KSPROPERTY_SUPPORT_SET;
return DS_OK;
}
FIXME("Unhandled propid: 0x%08lx\n", propid);
return E_PROP_ID_UNSUPPORTED;
}
HRESULT EAX4Context_Set(DSPrimary *prim, DWORD propid, void *pPropData, ULONG cbPropData)
{
if(!HAS_EXTENSION(prim->share, EXT_EFX))
return E_PROP_ID_UNSUPPORTED;
switch(propid)
{
case EAXCONTEXT_NONE: /* not setting any property, just applying */
return DS_OK;
case EAXCONTEXT_ALLPARAMETERS:
if(cbPropData >= sizeof(EAXCONTEXTPROPERTIES))
{
union { void *v; const EAXCONTEXTPROPERTIES *props; } data = { pPropData };
ALint prim_idx;
TRACE("Parameters:\n\tPrimary FXSlot: %s\n\tDistance Factor: %f\n\t"
"Air Absorption: %f\n\tHF Reference: %f\n",
debug_fxslot(&data.props->guidPrimaryFXSlotID), data.props->flDistanceFactor,
data.props->flAirAbsorptionHF, data.props->flHFReference
);
prim_idx = -1;
if(IsEqualGUID(&data.props->guidPrimaryFXSlotID, &EAXPROPERTYID_EAX40_FXSlot0))
prim_idx = 0;
else if(IsEqualGUID(&data.props->guidPrimaryFXSlotID, &EAXPROPERTYID_EAX40_FXSlot1))
prim_idx = 1;
else if(IsEqualGUID(&data.props->guidPrimaryFXSlotID, &EAXPROPERTYID_EAX40_FXSlot2))
prim_idx = 2;
else if(IsEqualGUID(&data.props->guidPrimaryFXSlotID, &EAXPROPERTYID_EAX40_FXSlot3))
prim_idx = 3;
if(prim_idx == -1 && !IsEqualGUID(&data.props->guidPrimaryFXSlotID, &EAX_NULL_GUID))
{
ERR("Unexpected primary FXSlot: %s\n",
debug_fxslot(&data.props->guidPrimaryFXSlotID));
return DSERR_INVALIDPARAM;
}
if(!(data.props->flDistanceFactor >= DS3D_MINDISTANCEFACTOR &&
data.props->flDistanceFactor <= DS3D_MAXDISTANCEFACTOR))
{
ERR("Unexpected distance factor: %f\n", data.props->flDistanceFactor);
return DSERR_INVALIDPARAM;
}
if(!(data.props->flAirAbsorptionHF <= 0.0f && data.props->flAirAbsorptionHF >= -100.0f))
{
ERR("Unexpected air absorption: %f\n", data.props->flAirAbsorptionHF);
return DSERR_INVALIDPARAM;
}
if(!(data.props->flHFReference >= 1000.0f && data.props->flHFReference <= 20000.0f))
{
ERR("Unexpected HF reference: %f\n", data.props->flAirAbsorptionHF);
return DSERR_INVALIDPARAM;
}
prim->deferred.ctx = *data.props;
prim->primary_idx = prim_idx;
prim->dirty.bit.prim_slotid = 1;
prim->dirty.bit.distancefactor2 = 1;
prim->dirty.bit.air_absorbhf = 1;
prim->dirty.bit.hfreference = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXCONTEXT_PRIMARYFXSLOTID:
if(cbPropData >= sizeof(GUID))
{
union { void *v; const GUID *guid; } data = { pPropData };
ALint prim_idx;
TRACE("Primary FXSlot: %s\n", debug_fxslot(data.guid));
prim_idx = -1;
if(IsEqualGUID(data.guid, &EAXPROPERTYID_EAX40_FXSlot0))
prim_idx = 0;
else if(IsEqualGUID(data.guid, &EAXPROPERTYID_EAX40_FXSlot1))
prim_idx = 1;
else if(IsEqualGUID(data.guid, &EAXPROPERTYID_EAX40_FXSlot2))
prim_idx = 2;
else if(IsEqualGUID(data.guid, &EAXPROPERTYID_EAX40_FXSlot3))
prim_idx = 3;
if(prim_idx == -1 && !IsEqualGUID(data.guid, &EAX_NULL_GUID))
{
ERR("Unexpected primary FXSlot: %s\n", debug_fxslot(data.guid));
return DSERR_INVALIDPARAM;
}
prim->deferred.ctx.guidPrimaryFXSlotID = *data.guid;
prim->primary_idx = prim_idx;
prim->dirty.bit.prim_slotid = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXCONTEXT_DISTANCEFACTOR:
if(cbPropData >= sizeof(float))
{
union { void *v; const float *fl; } data = { pPropData };
TRACE("Distance Factor: %f\n", *data.fl);
if(!(*data.fl >= DS3D_MINDISTANCEFACTOR && *data.fl <= DS3D_MAXDISTANCEFACTOR))
{
ERR("Unexpected distance factor: %f\n", *data.fl);
return DSERR_INVALIDPARAM;
}
prim->deferred.ctx.flDistanceFactor = *data.fl;
prim->dirty.bit.distancefactor2 = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXCONTEXT_AIRABSORPTIONHF:
if(cbPropData >= sizeof(float))
{
union { void *v; const float *fl; } data = { pPropData };
TRACE("Air Absorption: %f\n", *data.fl);
if(!(*data.fl <= 0.0f && *data.fl >= -100.0f))
{
ERR("Unexpected air absorption: %f\n", *data.fl);
return DSERR_INVALIDPARAM;
}
prim->deferred.ctx.flAirAbsorptionHF = *data.fl;
prim->dirty.bit.air_absorbhf = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXCONTEXT_HFREFERENCE:
if(cbPropData >= sizeof(float))
{
union { void *v; const float *fl; } data = { pPropData };
TRACE("HF Reference: %f\n", *data.fl);
if(!(*data.fl >= 1000.0f && *data.fl <= 20000.0f))
{
ERR("Unexpected HF reference: %f\n", *data.fl);
return DSERR_INVALIDPARAM;
}
prim->deferred.ctx.flHFReference = *data.fl;
prim->dirty.bit.hfreference = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXCONTEXT_LASTERROR:
if(cbPropData >= sizeof(long))
{
union { void *v; const long *l; } data = { pPropData };
TRACE("Last Error: %ld\n", *data.l);
prim->eax_error = *data.l;
return DS_OK;
}
return DSERR_INVALIDPARAM;
}
FIXME("Unhandled propid: 0x%08lx\n", propid);
return E_PROP_ID_UNSUPPORTED;
}
#define GET_PROP(src, T) do { \
if(cbPropData >= sizeof(T)) \
{ \
union { void *v; T *props; } data = { pPropData }; \
*data.props = src; \
*pcbReturned = sizeof(T); \
return DS_OK; \
} \
return DSERR_INVALIDPARAM; \
} while(0)
HRESULT EAX4Context_Get(DSPrimary *prim, DWORD propid, void *pPropData, ULONG cbPropData, ULONG *pcbReturned)
{
if(!HAS_EXTENSION(prim->share, EXT_EFX))
return E_PROP_ID_UNSUPPORTED;
switch(propid)
{
case EAXCONTEXT_NONE:
*pcbReturned = 0;
return DS_OK;
case EAXCONTEXT_ALLPARAMETERS:
GET_PROP(prim->current.ctx, EAXCONTEXTPROPERTIES);
case EAXCONTEXT_PRIMARYFXSLOTID:
GET_PROP(prim->current.ctx.guidPrimaryFXSlotID, GUID);
case EAXCONTEXT_DISTANCEFACTOR:
GET_PROP(prim->current.ctx.flDistanceFactor, float);
case EAXCONTEXT_AIRABSORPTIONHF:
GET_PROP(prim->current.ctx.flAirAbsorptionHF, float);
case EAXCONTEXT_HFREFERENCE:
GET_PROP(prim->current.ctx.flHFReference, float);
case EAXCONTEXT_LASTERROR:
GET_PROP(InterlockedExchange(&prim->eax_error, EAX_OK), long);
}
FIXME("Unhandled propid: 0x%08lx\n", propid);
return E_PROP_ID_UNSUPPORTED;
}
HRESULT EAX4Slot_Query(DSPrimary *prim, LONG idx, DWORD propid, ULONG *pTypeSupport)
{
if(prim->auxslot[idx] == 0)
return E_PROP_ID_UNSUPPORTED;
if((propid&~EAXFXSLOT_PARAMETER_DEFERRED) < EAXFXSLOT_NONE)
{
if(prim->current.fxslot[idx].effect_type == FXSLOT_EFFECT_REVERB)
{
if((propid&~EAXFXSLOT_PARAMETER_DEFERRED) <= EAXREVERB_FLAGS)
{
*pTypeSupport = KSPROPERTY_SUPPORT_GET | KSPROPERTY_SUPPORT_SET;
return DS_OK;
}
FIXME("Unhandled reverb propid: 0x%08lx\n", propid);
}
else if(prim->current.fxslot[idx].effect_type == FXSLOT_EFFECT_CHORUS)
{
if((propid&~EAXFXSLOT_PARAMETER_DEFERRED) <= EAXCHORUS_DELAY)
{
*pTypeSupport = KSPROPERTY_SUPPORT_GET | KSPROPERTY_SUPPORT_SET;
return DS_OK;
}
FIXME("Unhandled chorus propid: 0x%08lx\n", propid);
}
else /*if(prim->current.fxslot[idx].effect_type == FXSLOT_EFFECT_NULL)*/
{
FIXME("Unhandled null effect propid: 0x%08lx\n", propid);
}
return DSERR_INVALIDPARAM;
}
switch((propid&~EAXFXSLOT_PARAMETER_DEFERRED))
{
case EAXFXSLOT_NONE:
case EAXFXSLOT_ALLPARAMETERS:
case EAXFXSLOT_LOADEFFECT:
case EAXFXSLOT_VOLUME:
case EAXFXSLOT_LOCK:
case EAXFXSLOT_FLAGS:
*pTypeSupport = KSPROPERTY_SUPPORT_GET | KSPROPERTY_SUPPORT_SET;
return DS_OK;
}
FIXME("Unhandled propid: 0x%08lx\n", propid);
return E_PROP_ID_UNSUPPORTED;
}
HRESULT EAX4Slot_Set(DSPrimary *prim, LONG idx, DWORD propid, void *pPropData, ULONG cbPropData)
{
if(prim->auxslot[idx] == 0)
return E_PROP_ID_UNSUPPORTED;
if(propid < EAXFXSLOT_NONE)
{
if(prim->deferred.fxslot[idx].effect_type == FXSLOT_EFFECT_REVERB)
return EAXReverb_Set(prim, idx, propid, pPropData, cbPropData);
if(prim->deferred.fxslot[idx].effect_type == FXSLOT_EFFECT_CHORUS)
return EAXChorus_Set(prim, idx, propid, pPropData, cbPropData);
ERR("Unexpected null effect propid 0x%08lx\n", propid);
return E_PROP_ID_UNSUPPORTED;
}
switch(propid)
{
case EAXFXSLOT_NONE: /* not setting any property, just applying */
return DS_OK;
case EAXFXSLOT_ALLPARAMETERS:
if(cbPropData >= sizeof(EAXFXSLOTPROPERTIES))
{
union { const void *v; const EAXFXSLOTPROPERTIES *props; } data = { pPropData };
DWORD effect_type;
TRACE("Parameters:\n\tLoad Effect: %s\n\tVolume: %ld\n\tLock: %ld\n\tFlags: 0x%lx\n",
debug_fxguid(&data.props->guidLoadEffect), data.props->lVolume, data.props->lLock,
data.props->dwFlags
);
effect_type = FXSLOT_EFFECT_NULL;
if(IsEqualGUID(&data.props->guidLoadEffect, &EAX_REVERB_EFFECT))
effect_type = FXSLOT_EFFECT_REVERB;
else if(IsEqualGUID(&data.props->guidLoadEffect, &EAX_CHORUS_EFFECT))
effect_type = FXSLOT_EFFECT_CHORUS;
else if(!IsEqualGUID(&data.props->guidLoadEffect, &EAX_NULL_GUID))
{
ERR("Unhandled effect: %s\n", debug_fxguid(&data.props->guidLoadEffect));
return DSERR_INVALIDPARAM;
}
if(data.props->lLock == EAXFXSLOT_LOCKED &&
prim->deferred.fxslot[idx].props.lLock == EAXFXSLOT_LOCKED &&
prim->deferred.fxslot[idx].effect_type != effect_type)
{
ERR("Attempting to change effect type for locked FXSlot\n");
return DSERR_INVALIDCALL;
}
if(prim->deferred.fxslot[idx].effect_type != effect_type)
{
alGetError();
alEffecti(prim->effect[idx], AL_EFFECT_TYPE,
(effect_type == FXSLOT_EFFECT_REVERB) ? AL_EFFECT_EAXREVERB :
(effect_type == FXSLOT_EFFECT_CHORUS) ? AL_EFFECT_CHORUS :
AL_EFFECT_NULL
);
if(alGetError() != AL_NO_ERROR)
{
ERR("Failed to set effect type %lu\n", effect_type);
return DSERR_INVALIDPARAM;
}
prim->deferred.fxslot[idx].effect_type = effect_type;
memset(&prim->deferred.fxslot[idx].fx, 0, sizeof(prim->deferred.fxslot[idx].fx));
if(effect_type == FXSLOT_EFFECT_REVERB)
prim->deferred.fxslot[idx].fx.reverb = EnvironmentDefaults[EAX_ENVIRONMENT_GENERIC];
else if(effect_type == FXSLOT_EFFECT_CHORUS)
{
const EAXCHORUSPROPERTIES chorus_def = CHORUS_PRESET_DEFAULT;
prim->deferred.fxslot[idx].fx.chorus = chorus_def;
}
FXSLOT_SET_DIRTY(prim->dirty.bit, idx, FXSLOT_EFFECT_BIT);
}
prim->deferred.fxslot[idx].props = *data.props;
FXSLOT_SET_DIRTY(prim->dirty.bit, idx, FXSLOT_VOL_BIT);
FXSLOT_SET_DIRTY(prim->dirty.bit, idx, FXSLOT_LOCK_BIT);
FXSLOT_SET_DIRTY(prim->dirty.bit, idx, FXSLOT_FLAGS_BIT);
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXFXSLOT_LOADEFFECT:
if(cbPropData >= sizeof(GUID))
{
union { const void *v; const GUID *guid; } data = { pPropData };
DWORD effect_type;
TRACE("Load Effect: %s\n", debug_fxguid(data.guid));
effect_type = FXSLOT_EFFECT_NULL;
if(IsEqualGUID(data.guid, &EAX_REVERB_EFFECT))
effect_type = FXSLOT_EFFECT_REVERB;
else if(IsEqualGUID(data.guid, &EAX_CHORUS_EFFECT))
effect_type = FXSLOT_EFFECT_CHORUS;
else if(!IsEqualGUID(data.guid, &EAX_NULL_GUID))
{
ERR("Unhandled effect: %s\n", debug_fxguid(data.guid));
return DSERR_INVALIDPARAM;
}
if(prim->deferred.fxslot[idx].props.lLock == EAXFXSLOT_LOCKED)
{
ERR("Attempting to change effect type for locked FXSlot\n");
return DSERR_INVALIDCALL;
}
alGetError();
alEffecti(prim->effect[idx], AL_EFFECT_TYPE,
(effect_type == FXSLOT_EFFECT_REVERB) ? AL_EFFECT_EAXREVERB :
(effect_type == FXSLOT_EFFECT_CHORUS) ? AL_EFFECT_CHORUS :
AL_EFFECT_NULL
);
if(alGetError() != AL_NO_ERROR)
{
ERR("Failed to set effect type %lu\n", effect_type);
return DSERR_INVALIDPARAM;
}
prim->deferred.fxslot[idx].effect_type = effect_type;
memset(&prim->deferred.fxslot[idx].fx, 0, sizeof(prim->deferred.fxslot[idx].fx));
if(effect_type == FXSLOT_EFFECT_REVERB)
prim->deferred.fxslot[idx].fx.reverb = EnvironmentDefaults[EAX_ENVIRONMENT_GENERIC];
else if(effect_type == FXSLOT_EFFECT_CHORUS)
{
const EAXCHORUSPROPERTIES chorus_def = CHORUS_PRESET_DEFAULT;
prim->deferred.fxslot[idx].fx.chorus = chorus_def;
}
prim->deferred.fxslot[idx].props.guidLoadEffect = *data.guid;
FXSLOT_SET_DIRTY(prim->dirty.bit, idx, FXSLOT_EFFECT_BIT);
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXFXSLOT_VOLUME:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Volume: %ld\n", *data.l);
prim->deferred.fxslot[idx].props.lVolume = *data.l;
FXSLOT_SET_DIRTY(prim->dirty.bit, idx, FXSLOT_VOL_BIT);
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXFXSLOT_LOCK:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Lock: %ld\n", *data.l);
prim->deferred.fxslot[idx].props.lLock = *data.l;
FXSLOT_SET_DIRTY(prim->dirty.bit, idx, FXSLOT_LOCK_BIT);
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXFXSLOT_FLAGS:
if(cbPropData >= sizeof(DWORD))
{
union { const void *v; const DWORD *dw; } data = { pPropData };
TRACE("Flags: 0x%lx\n", *data.dw);
prim->deferred.fxslot[idx].props.dwFlags = *data.dw;
FXSLOT_SET_DIRTY(prim->dirty.bit, idx, FXSLOT_FLAGS_BIT);
return DS_OK;
}
return DSERR_INVALIDPARAM;
}
FIXME("Unhandled propid: 0x%08lx\n", propid);
return E_PROP_ID_UNSUPPORTED;
}
HRESULT EAX4Slot_Get(DSPrimary *prim, LONG idx, DWORD propid, void *pPropData, ULONG cbPropData, ULONG *pcbReturned)
{
if(prim->auxslot[idx] == 0)
return E_PROP_ID_UNSUPPORTED;
if(propid < EAXFXSLOT_NONE)
{
if(prim->deferred.fxslot[idx].effect_type == FXSLOT_EFFECT_REVERB)
return EAXReverb_Get(prim, idx, propid, pPropData, cbPropData, pcbReturned);
if(prim->deferred.fxslot[idx].effect_type == FXSLOT_EFFECT_CHORUS)
return EAXChorus_Get(prim, idx, propid, pPropData, cbPropData, pcbReturned);
ERR("Unexpected null effect propid 0x%08lx\n", propid);
return E_PROP_ID_UNSUPPORTED;
}
switch(propid)
{
case EAXFXSLOT_NONE:
*pcbReturned = 0;
return DS_OK;
case EAXFXSLOT_ALLPARAMETERS:
GET_PROP(prim->current.fxslot[idx].props, EAXFXSLOTPROPERTIES);
case EAXFXSLOT_LOADEFFECT:
GET_PROP(prim->current.fxslot[idx].props.guidLoadEffect, GUID);
case EAXFXSLOT_VOLUME:
GET_PROP(prim->current.fxslot[idx].props.lVolume, long);
case EAXFXSLOT_LOCK:
GET_PROP(prim->current.fxslot[idx].props.lLock, long);
case EAXFXSLOT_FLAGS:
GET_PROP(prim->current.fxslot[idx].props.dwFlags, DWORD);
}
FIXME("Unhandled propid: 0x%08lx\n", propid);
return E_PROP_ID_UNSUPPORTED;
}
#define APPLY_DRY_PARAMS (1<<EAX_MAX_FXSLOTS)
#define APPLY_ALLWET_PARAMS (APPLY_DRY_PARAMS-1)
#define APPLY_ALL_PARAMS (APPLY_DRY_PARAMS | APPLY_ALLWET_PARAMS)
static void ApplyFilterParams(DSBuffer *buf, const EAXSOURCEPROPERTIES *props, int apply)
{
/* The LFRatio properties determine how much the given level applies to low
* frequencies as well as high frequencies. Technically, given that the
* obstruction/occlusion/exclusion levels are the absolute level applied to
* high frequencies (relative to full-scale, according to the EAX 2.0 spec)
* while the HF filter gains are relative to the low, the HF gains should
* increase as LFRatio increases.
*
* However it seems Creative was either wrong when writing out the spec,
* or implemented it incorrectly, as the HF filter still applies in full
* regardless of the LFRatio. So to replicate the hardware behavior, we do
* the same here.
*/
/* The interaction of ratios is pretty wierd. The typical combination of
* the two act as a minimal baseline, while the sum minus one is used when
* larger. This creates a more linear change with the individual ratios as
* Direct/RoomRatio goes beyond 1, but eases down as the two ratios go
* toward 0.
*/
float dryoccl = maxF(props->flOcclusionLFRatio+props->flOcclusionDirectRatio-1.0f,
props->flOcclusionLFRatio*props->flOcclusionDirectRatio) *
props->lOcclusion;
float dryocclhf = props->lOcclusion*props->flOcclusionDirectRatio;
float room_mb = props->lRoom + props->lExclusion*props->flExclusionLFRatio +
maxF(props->flOcclusionLFRatio+props->flOcclusionRoomRatio-1.0f,
props->flOcclusionLFRatio*props->flOcclusionRoomRatio) * props->lOcclusion;
float room_mbhf = props->lRoomHF + props->lExclusion +
props->lOcclusion*props->flOcclusionRoomRatio;
int i;
for(i = 0;i < EAX_MAX_FXSLOTS;i++)
{
const struct Send *send = &buf->deferred.send[i];
if((apply&(1<<i)) && buf->filter[1+i])
{
/* Add the main room occlusion and exclusion properties with the
* sends', or take the minimum or maximum?
*/
float mb = room_mb + send->lExclusion*send->flExclusionLFRatio +
maxF(send->flOcclusionLFRatio+send->flOcclusionRoomRatio-1.0f,
send->flOcclusionLFRatio*send->flOcclusionRoomRatio)*send->lOcclusion;
float mbhf = room_mbhf + send->lExclusion +
send->lOcclusion*send->flOcclusionRoomRatio;
alFilterf(buf->filter[1+i], AL_LOWPASS_GAIN, mB_to_gain(minF(mb, buf->filter_mBLimit)));
alFilterf(buf->filter[1+i], AL_LOWPASS_GAINHF, mB_to_gain(mbhf));
}
/* Take the minimum, maximum, or average of the sends' direct occlusion with the main
* property?
*/
dryoccl = minF(dryoccl,
maxF(send->flOcclusionLFRatio+send->flOcclusionDirectRatio-1.0f,
send->flOcclusionLFRatio*send->flOcclusionDirectRatio) * send->lOcclusion
);
dryocclhf = minF(dryocclhf, send->lOcclusion*send->flOcclusionDirectRatio);
}
if((apply&APPLY_DRY_PARAMS) && buf->filter[0])
{
float mb = props->lDirect + props->lObstruction*props->flObstructionLFRatio + dryoccl;
float mbhf = props->lDirectHF + props->lObstruction + dryocclhf;
alFilterf(buf->filter[0], AL_LOWPASS_GAIN, mB_to_gain(minF(mb, buf->filter_mBLimit)));
alFilterf(buf->filter[0], AL_LOWPASS_GAINHF, mB_to_gain(mbhf));
}
checkALError();
}
static EAXOBSTRUCTIONPROPERTIES EAXSourceObstruction(const EAXSOURCEPROPERTIES *props)
{
EAXOBSTRUCTIONPROPERTIES ret;
ret.lObstruction = props->lObstruction;
ret.flObstructionLFRatio = props->flObstructionLFRatio;
return ret;
}
static EAXOCCLUSIONPROPERTIES EAXSourceOcclusion(const EAXSOURCEPROPERTIES *props)
{
EAXOCCLUSIONPROPERTIES ret;
ret.lOcclusion = props->lOcclusion;
ret.flOcclusionLFRatio = props->flOcclusionLFRatio;
ret.flOcclusionRoomRatio = props->flOcclusionRoomRatio;
ret.flOcclusionDirectRatio = props->flOcclusionDirectRatio;
return ret;
}
static EAXEXCLUSIONPROPERTIES EAXSourceExclusion(const EAXSOURCEPROPERTIES *props)
{
EAXEXCLUSIONPROPERTIES ret;
ret.lExclusion = props->lExclusion;
ret.flExclusionLFRatio = props->flExclusionLFRatio;
return ret;
}
static struct Send *FindCurrentSend(DSBuffer *buf, const GUID *guid)
{
if(IsEqualGUID(guid, &EAXPROPERTYID_EAX40_FXSlot0))
return &buf->current.send[0];
if(IsEqualGUID(guid, &EAXPROPERTYID_EAX40_FXSlot1))
return &buf->current.send[1];
if(IsEqualGUID(guid, &EAXPROPERTYID_EAX40_FXSlot2))
return &buf->current.send[2];
if(IsEqualGUID(guid, &EAXPROPERTYID_EAX40_FXSlot3))
return &buf->current.send[3];
return NULL;
}
static struct Send *FindDeferredSend(DSBuffer *buf, const GUID *guid)
{
if(IsEqualGUID(guid, &EAXPROPERTYID_EAX40_FXSlot0))
return &buf->deferred.send[0];
if(IsEqualGUID(guid, &EAXPROPERTYID_EAX40_FXSlot1))
return &buf->deferred.send[1];
if(IsEqualGUID(guid, &EAXPROPERTYID_EAX40_FXSlot2))
return &buf->deferred.send[2];
if(IsEqualGUID(guid, &EAXPROPERTYID_EAX40_FXSlot3))
return &buf->deferred.send[3];
return NULL;
}
HRESULT EAX4Source_Query(DSBuffer *buf, DWORD propid, ULONG *pTypeSupport)
{
if(!HAS_EXTENSION(buf->share, EXT_EFX))
return E_PROP_ID_UNSUPPORTED;
switch((propid&~EAXSOURCE_PARAMETER_DEFERRED))
{
case EAXSOURCE_NONE:
case EAXSOURCE_ALLPARAMETERS:
case EAXSOURCE_OBSTRUCTIONPARAMETERS:
case EAXSOURCE_OCCLUSIONPARAMETERS:
case EAXSOURCE_EXCLUSIONPARAMETERS:
case EAXSOURCE_DIRECT:
case EAXSOURCE_DIRECTHF:
case EAXSOURCE_ROOM:
case EAXSOURCE_ROOMHF:
case EAXSOURCE_OBSTRUCTION:
case EAXSOURCE_OBSTRUCTIONLFRATIO:
case EAXSOURCE_OCCLUSION:
case EAXSOURCE_OCCLUSIONLFRATIO:
case EAXSOURCE_OCCLUSIONROOMRATIO:
case EAXSOURCE_OCCLUSIONDIRECTRATIO:
case EAXSOURCE_EXCLUSION:
case EAXSOURCE_EXCLUSIONLFRATIO:
case EAXSOURCE_OUTSIDEVOLUMEHF:
case EAXSOURCE_DOPPLERFACTOR:
case EAXSOURCE_ROLLOFFFACTOR:
case EAXSOURCE_ROOMROLLOFFFACTOR:
case EAXSOURCE_AIRABSORPTIONFACTOR:
case EAXSOURCE_FLAGS:
case EAXSOURCE_SENDPARAMETERS:
case EAXSOURCE_ALLSENDPARAMETERS:
case EAXSOURCE_OCCLUSIONSENDPARAMETERS:
case EAXSOURCE_EXCLUSIONSENDPARAMETERS:
case EAXSOURCE_ACTIVEFXSLOTID:
*pTypeSupport = KSPROPERTY_SUPPORT_GET | KSPROPERTY_SUPPORT_SET;
return DS_OK;
}
FIXME("Unhandled propid: 0x%08lx\n", propid);
return E_PROP_ID_UNSUPPORTED;
}
HRESULT EAX4Source_Set(DSBuffer *buf, DWORD propid, void *pPropData, ULONG cbPropData)
{
if(!HAS_EXTENSION(buf->share, EXT_EFX))
return E_PROP_ID_UNSUPPORTED;
switch(propid)
{
case EAXSOURCE_NONE:
return DS_OK;
case EAXSOURCE_ALLPARAMETERS:
if(cbPropData >= sizeof(EAXSOURCEPROPERTIES))
{
union {
const void *v;
const EAXSOURCEPROPERTIES *props;
} data = { pPropData };
TRACE("Parameters:\n\tDirect: %ld\n\tDirect HF: %ld\n\tRoom: %ld\n\tRoom HF: %ld\n\t"
"Obstruction: %ld\n\tObstruction LF Ratio: %f\n\tOcclusion: %ld\n\t"
"Occlusion LF Ratio: %f\n\tOcclusion Room Ratio: %f\n\t"
"Occlusion Direct Ratio: %f\n\tExclusion: %ld\n\tExclusion LF Ratio: %f\n\t"
"Outside Volume HF: %ld\n\tDoppler Factor: %f\n\tRolloff Factor: %f\n\t"
"Room Rolloff Factor: %f\n\tAir Absorb Factor: %f\n\tFlags: 0x%02lx\n",
data.props->lDirect, data.props->lDirectHF, data.props->lRoom, data.props->lRoomHF,
data.props->lObstruction, data.props->flObstructionLFRatio, data.props->lOcclusion,
data.props->flOcclusionLFRatio, data.props->flOcclusionRoomRatio,
data.props->flOcclusionDirectRatio, data.props->lExclusion,
data.props->flExclusionLFRatio, data.props->lOutsideVolumeHF,
data.props->flDopplerFactor, data.props->flRolloffFactor,
data.props->flRoomRolloffFactor, data.props->flAirAbsorptionFactor,
data.props->dwFlags
);
buf->deferred.eax = *data.props;
ApplyFilterParams(buf, data.props, APPLY_ALL_PARAMS);
buf->dirty.bit.dry_filter = 1;
buf->dirty.bit.send_filters = 1;
buf->dirty.bit.doppler = 1;
buf->dirty.bit.rolloff = 1;
buf->dirty.bit.room_rolloff = 1;
buf->dirty.bit.cone_outsidevolumehf = 1;
buf->dirty.bit.air_absorb = 1;
buf->dirty.bit.flags = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_OBSTRUCTIONPARAMETERS:
if(cbPropData >= sizeof(EAXOBSTRUCTIONPROPERTIES))
{
union {
const void *v;
const EAXOBSTRUCTIONPROPERTIES *props;
} data = { pPropData };
TRACE("Parameters:\n\tObstruction: %ld\n\tObstruction LF Ratio: %f\n",
data.props->lObstruction, data.props->flObstructionLFRatio);
buf->deferred.eax.lObstruction = data.props->lObstruction;
buf->deferred.eax.flObstructionLFRatio = data.props->flObstructionLFRatio;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_DRY_PARAMS);
buf->dirty.bit.dry_filter = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_OCCLUSIONPARAMETERS:
if(cbPropData >= sizeof(EAXOCCLUSIONPROPERTIES))
{
union {
const void *v;
const EAXOCCLUSIONPROPERTIES *props;
} data = { pPropData };
TRACE("Parameters:\n\tOcclusion: %ld\n\tOcclusion LF Ratio: %f\n\t"
"Occlusion Room Ratio: %f\n\tOcclusion Direct Ratio: %f\n",
data.props->lOcclusion, data.props->flOcclusionLFRatio,
data.props->flOcclusionRoomRatio, data.props->flOcclusionDirectRatio
);
buf->deferred.eax.lOcclusion = data.props->lOcclusion;
buf->deferred.eax.flOcclusionLFRatio = data.props->flOcclusionLFRatio;
buf->deferred.eax.flOcclusionRoomRatio = data.props->flOcclusionRoomRatio;
buf->deferred.eax.flOcclusionDirectRatio = data.props->flOcclusionDirectRatio;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_ALL_PARAMS);
buf->dirty.bit.dry_filter = 1;
buf->dirty.bit.send_filters = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_EXCLUSIONPARAMETERS:
if(cbPropData >= sizeof(EAXEXCLUSIONPROPERTIES))
{
union {
const void *v;
const EAXEXCLUSIONPROPERTIES *props;
} data = { pPropData };
TRACE("Parameters:\n\tExclusion: %ld\n\tExclusion LF Ratio: %f\n",
data.props->lExclusion, data.props->flExclusionLFRatio);
buf->deferred.eax.lExclusion = data.props->lExclusion;
buf->deferred.eax.flExclusionLFRatio = data.props->flExclusionLFRatio;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_ALLWET_PARAMS);
buf->dirty.bit.send_filters = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_DIRECT:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Direct: %ld\n", *data.l);
buf->deferred.eax.lDirect = *data.l;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_DRY_PARAMS);
buf->dirty.bit.dry_filter = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_DIRECTHF:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Direct HF: %ld\n", *data.l);
buf->deferred.eax.lDirectHF = *data.l;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_DRY_PARAMS);
buf->dirty.bit.dry_filter = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_ROOM:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Room: %ld\n", *data.l);
buf->deferred.eax.lRoom = *data.l;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_ALLWET_PARAMS);
buf->dirty.bit.send_filters = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_ROOMHF:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Room HF: %ld\n", *data.l);
buf->deferred.eax.lRoomHF = *data.l;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_ALLWET_PARAMS);
buf->dirty.bit.send_filters = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_OBSTRUCTION:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Obstruction: %ld\n", *data.l);
buf->deferred.eax.lObstruction = *data.l;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_DRY_PARAMS);
buf->dirty.bit.dry_filter = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_OBSTRUCTIONLFRATIO:
if(cbPropData >= sizeof(float))
{
union { const void *v; const float *fl; } data = { pPropData };
TRACE("Obstruction LF Ratio: %f\n", *data.fl);
buf->deferred.eax.flObstructionLFRatio = *data.fl;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_DRY_PARAMS);
buf->dirty.bit.dry_filter = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_OCCLUSION:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Occlusion: %ld\n", *data.l);
buf->deferred.eax.lOcclusion = *data.l;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_ALL_PARAMS);
buf->dirty.bit.dry_filter = 1;
buf->dirty.bit.send_filters = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_OCCLUSIONLFRATIO:
if(cbPropData >= sizeof(float))
{
union { const void *v; const float *fl; } data = { pPropData };
TRACE("Occlusion LF Ratio: %f\n", *data.fl);
buf->deferred.eax.flOcclusionLFRatio = *data.fl;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_ALL_PARAMS);
buf->dirty.bit.dry_filter = 1;
buf->dirty.bit.send_filters = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_OCCLUSIONROOMRATIO:
if(cbPropData >= sizeof(float))
{
union { const void *v; const float *fl; } data = { pPropData };
TRACE("Occlusion Room Ratio: %f\n", *data.fl);
buf->deferred.eax.flOcclusionRoomRatio = *data.fl;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_ALLWET_PARAMS);
buf->dirty.bit.send_filters = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_OCCLUSIONDIRECTRATIO:
if(cbPropData >= sizeof(float))
{
union { const void *v; const float *fl; } data = { pPropData };
TRACE("Occlusion Direct Ratio: %f\n", *data.fl);
buf->deferred.eax.flOcclusionDirectRatio = *data.fl;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_DRY_PARAMS);
buf->dirty.bit.dry_filter = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_EXCLUSION:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Exclusion: %ld\n", *data.l);
buf->deferred.eax.lExclusion = *data.l;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_ALLWET_PARAMS);
buf->dirty.bit.send_filters = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_EXCLUSIONLFRATIO:
if(cbPropData >= sizeof(float))
{
union { const void *v; const float *fl; } data = { pPropData };
TRACE("Exclusion LF Ratio: %f\n", *data.fl);
buf->deferred.eax.flExclusionLFRatio = *data.fl;
ApplyFilterParams(buf, &buf->deferred.eax, APPLY_ALLWET_PARAMS);
buf->dirty.bit.send_filters = 1;
return DS_OK;
}
return DSERR_INVALIDPARAM;
case EAXSOURCE_OUTSIDEVOLUMEHF:
if(cbPropData >= sizeof(long))
{
union { const void *v; const long *l; } data = { pPropData };
TRACE("Outisde Volume HF: %ld\n", *data.l);
buf->deferred.eax.lOutsideVolumeHF = *data.l;
buf->dirty.bit.cone_outsidevolumehf = 1;