FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/modules/dasAudio/src/dasAudio.cpp at master · WhyNot135/daScript · GitHub
WhyNot135
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
modules
/
dasAudio
/
src
/
dasAudio.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
1423 lines (1291 loc) · 75.6 KB
Breadcrumbs
daScript
/
modules
/
dasAudio
/
src
/
dasAudio.cpp
Copy path
File metadata and controls
1423 lines (1291 loc) · 75.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/ast/ast.h
"
#
include
"
daScript/ast/ast_interop.h
"
#
include
"
daScript/ast/ast_typefactory_bind.h
"
#
include
"
daScript/ast/ast_handle.h
"
#
include
"
daScript/simulate/bind_enum.h
"
#
include
<
atomic
>
//
include vorbis extras before miniaudio
#
define
STB_VORBIS_HEADER_ONLY
#
ifdef
__forceinline
#
undef
__forceinline
#
define
__forceinline
inline
#
endif
#
include
<
extras/stb_vorbis.c
>
/*
Enables Vorbis decoding.
*/
#
ifdef
_MSC_VER
#
pragma
warning(push)
#
pragma
warning(disable:4755)
#
pragma
warning(disable:4701)
#
endif
#
ifdef
__APPLE__
#
define
MA_NO_RUNTIME_LINKING
#
endif
#
define
MINIAUDIO_IMPLEMENTATION
#
define
MA_USE_STDINT
#
include
<
miniaudio.h
>
#
ifdef
_MSC_VER
#
pragma
warning(pop)
#
endif
#
include
"
volume_mixer.h
"
#
include
"
hrtf.h
"
#
define
I3DL32_REVERB_IMPLEMENTATION
1
#
include
"
reverb.h
"
#
define
MA_CHORUS_IMPLEMENTATION
#
include
"
chorus.h
"
#
define
CONVOLUTION_REVERB_IMPLEMENTATION
#
include
"
convolution_reverb.h
"
#
define
MA_EFFECTS_IMPLEMENTATION
#
include
"
effects.h
"
#
define
MA_PHASER_IMPLEMENTATION
#
include
"
phaser.h
"
#
define
MA_TREMOLO_IMPLEMENTATION
#
include
"
tremolo.h
"
#
define
MA_COMPRESSOR_IMPLEMENTATION
#
include
"
compressor.h
"
#
include
"
dasAudio.h
"
#
ifndef
HRTF_SAMPLE_RATE
#
define
HRTF_SAMPLE_RATE
48000
#
endif
//
Non-static wrapper for ma_sf2_biquad_tick (static in sf2_voice.h)
float
das_ma_sf2_biquad_tick
( ma_sf2_biquad * bq,
float
input ) {
return
ma_sf2_biquad_tick
(bq, input);
}
MAKE_EXTERNAL_TYPE_FACTORY
(Context,Context);
das::Context*
get_clone_context
( das::Context * ctx,
uint32_t
category );
//
link time resolved dependencies
MAKE_TYPE_FACTORY
(ma_resampler_config,ma_resampler_config);
MAKE_TYPE_FACTORY
(ma_resampler,ma_resampler);
MAKE_TYPE_FACTORY
(ma_channel_converter_config,ma_channel_converter_config);
MAKE_TYPE_FACTORY
(ma_channel_converter,ma_channel_converter);
MAKE_TYPE_FACTORY
(ma_volume_mixer,ma_volume_mixer);
MAKE_TYPE_FACTORY
(ma_decoder_config,ma_decoder_config);
MAKE_TYPE_FACTORY
(ma_decoder,ma_decoder);
MAKE_TYPE_FACTORY
(ma_limiter,ma_limiter);
MAKE_TYPE_FACTORY
(ma_sf2_envelope,ma_sf2_envelope);
MAKE_TYPE_FACTORY
(ma_sf2_biquad,ma_sf2_biquad);
MAKE_TYPE_FACTORY
(ma_sf2_voice,ma_sf2_voice);
MAKE_TYPE_FACTORY
(ma_chorus_config,ma_chorus_config);
MAKE_TYPE_FACTORY
(ma_chorus,ma_chorus);
MAKE_TYPE_FACTORY
(ma_delay,ma_delay);
MAKE_TYPE_FACTORY
(ma_bitcrush,ma_bitcrush);
MAKE_TYPE_FACTORY
(ma_waveshaper,ma_waveshaper);
MAKE_TYPE_FACTORY
(ma_djfilter,ma_djfilter);
MAKE_TYPE_FACTORY
(ma_bandpass,ma_bandpass);
MAKE_TYPE_FACTORY
(ma_phaser,ma_phaser);
MAKE_TYPE_FACTORY
(ma_tremolo,ma_tremolo);
MAKE_TYPE_FACTORY
(ma_compressor,ma_compressor);
DAS_BASE_BIND_ENUM
( ma_format, ma_format, \
ma_format_unknown, \
ma_format_u8, \
ma_format_s16, \
ma_format_s24, \
ma_format_s32, \
ma_format_f32 \
);
DAS_BIND_ENUM_CAST
( ma_format );
DAS_BASE_BIND_ENUM
( ma_resample_algorithm, ma_resample_algorithm, \
ma_resample_algorithm_linear, \
ma_resample_algorithm_custom \
);
DAS_BIND_ENUM_CAST
( ma_resample_algorithm );
DAS_BASE_BIND_ENUM
( ma_channel_mix_mode, ma_channel_mix_mode, \
ma_channel_mix_mode_rectangular, \
ma_channel_mix_mode_simple, \
ma_channel_mix_mode_custom_weights, \
ma_channel_mix_mode_default \
);
DAS_BIND_ENUM_CAST
( ma_channel_mix_mode );
DAS_BASE_BIND_ENUM
( ma_dither_mode, ma_dither_mode, \
ma_dither_mode_none, \
ma_dither_mode_rectangle, \
ma_dither_mode_triangle \
);
DAS_BIND_ENUM_CAST
( ma_dither_mode );
DAS_BASE_BIND_ENUM
( ma_result, ma_result, \
MA_SUCCESS
,\
MA_ERROR
,\
MA_INVALID_ARGS
,\
MA_INVALID_OPERATION
,\
MA_OUT_OF_MEMORY
,\
MA_OUT_OF_RANGE
,\
MA_ACCESS_DENIED
,\
MA_DOES_NOT_EXIST
,\
MA_ALREADY_EXISTS
,\
MA_TOO_MANY_OPEN_FILES
,\
MA_INVALID_FILE
,\
MA_TOO_BIG
,\
MA_PATH_TOO_LONG
,\
MA_NAME_TOO_LONG
,\
MA_NOT_DIRECTORY
,\
MA_IS_DIRECTORY
,\
MA_DIRECTORY_NOT_EMPTY
,\
MA_AT_END
,\
MA_NO_SPACE
,\
MA_BUSY
,\
MA_IO_ERROR
,\
MA_INTERRUPT
,\
MA_UNAVAILABLE
,\
MA_ALREADY_IN_USE
,\
MA_BAD_ADDRESS
,\
MA_BAD_SEEK
,\
MA_BAD_PIPE
,\
MA_DEADLOCK
,\
MA_TOO_MANY_LINKS
,\
MA_NOT_IMPLEMENTED
,\
MA_NO_MESSAGE
,\
MA_BAD_MESSAGE
,\
MA_NO_DATA_AVAILABLE
,\
MA_INVALID_DATA
,\
MA_TIMEOUT
,\
MA_NO_NETWORK
,\
MA_NOT_UNIQUE
,\
MA_NOT_SOCKET
,\
MA_NO_ADDRESS
,\
MA_BAD_PROTOCOL
,\
MA_PROTOCOL_UNAVAILABLE
,\
MA_PROTOCOL_NOT_SUPPORTED
,\
MA_PROTOCOL_FAMILY_NOT_SUPPORTED
,\
MA_ADDRESS_FAMILY_NOT_SUPPORTED
,\
MA_SOCKET_NOT_SUPPORTED
,\
MA_CONNECTION_RESET
,\
MA_ALREADY_CONNECTED
,\
MA_NOT_CONNECTED
,\
MA_CONNECTION_REFUSED
,\
MA_NO_HOST
,\
MA_IN_PROGRESS
,\
MA_CANCELLED
,\
MA_MEMORY_ALREADY_MAPPED
,\
MA_FORMAT_NOT_SUPPORTED
,\
MA_DEVICE_TYPE_NOT_SUPPORTED
,\
MA_SHARE_MODE_NOT_SUPPORTED
,\
MA_NO_BACKEND
,\
MA_NO_DEVICE
,\
MA_API_NOT_FOUND
,\
MA_INVALID_DEVICE_CONFIG
,\
MA_LOOP
,\
MA_DEVICE_NOT_INITIALIZED
,\
MA_DEVICE_ALREADY_INITIALIZED
,\
MA_DEVICE_NOT_STARTED
,\
MA_DEVICE_NOT_STOPPED
,\
MA_FAILED_TO_INIT_BACKEND
,\
MA_FAILED_TO_OPEN_BACKEND_DEVICE
,\
MA_FAILED_TO_START_BACKEND_DEVICE
,\
MA_FAILED_TO_STOP_BACKEND_DEVICE
\
);
DAS_BIND_ENUM_CAST
( ma_result );
DAS_BASE_BIND_ENUM
( das::I3DL2Preset, I3DL2Preset, \
Generic, \
PaddedCell, \
Room, \
Bathroom, \
LivingRoom, \
StoneRoom, \
Auditorium, \
ConcertHall, \
Cave, \
Arena, \
Hangar, \
CarpetedHallway, \
Hallway, \
StoneCorridor, \
Alley, \
Forest, \
City, \
Mountains, \
Quarry, \
Plain, \
ParkingLot, \
SewerPipe, \
Underwater \
);
DAS_BIND_ENUM_CAST
( das::I3DL2Preset );
//
ConvReverbQualityEnum is defined in dasAudio.h (das-facing names for the C ConvReverbQuality enum)
DAS_BASE_BIND_ENUM
( ConvReverbQualityEnum, ConvReverbQuality, high, medium, low );
DAS_BIND_ENUM_CAST
( ConvReverbQualityEnum );
MAKE_TYPE_FACTORY
(I3DL2ReverbProperties,I3DL2ReverbProperties);
MAKE_TYPE_FACTORY
(I3DL2Reverb,I3DL2Reverb);
MAKE_TYPE_FACTORY
(ma_hrtf,ma_hrtf);
MAKE_TYPE_FACTORY
(ConvolutionReverb,ConvolutionReverb);
namespace
das
{
static
ma_device g_device;
static
ma_log g_ma_log_struct;
static
shared_ptr<Context> g_mixer_context;
static
daScriptEnvironment * g_mixer_env =
nullptr
;
static
Func g_mixer_function = (
void
*)
nullptr
;
static
bool
g_mixer_initialized =
false
;
static
int
g_rate =
0
;
static
int
g_channels =
0
;
//
Null-backend mode (for headless tests / CI): force miniaudio's ma_backend_null
//
so the device + audio thread run without real hardware. Set via sound_set_null_device.
static
bool
g_force_null_backend =
false
;
static
ma_context g_null_context;
static
bool
g_null_context_inited =
false
;
//
Recorded at dasAudio_init: whether this audio system came up single-threaded —
//
i.e. the device callback (command_processor) runs on the MAIN thread, with no
//
separate audio thread to drain the command queue. The teardown reads this to
//
decide whether it must drain the queue itself (single-thread) or wait for the
//
audio thread (multi-thread, the original path). Today it's the emscripten
//
no-pthread build (ScriptProcessor callback on main); kept as a runtime flag,
//
not a compile-time check at the call sites, so the audio code asks "how was I
//
initialized" rather than "what platform is this".
static
bool
g_audio_single_threaded =
false
;
//
---- capture (microphone) ----
//
A capture device independent of the playback device above: recording has its own lifecycle, so
//
it does not share g_device / g_mixer_context. The RT capture callback writes interleaved f32 into
//
g_capture_rb (a lock-free single-producer/single-consumer ring); scripts drain it on the main
//
thread via dasAudio_record_read. No daScript code runs on the audio thread — that is what lets
//
captured data cross into a context safely (see the threading notes in the module docs).
static
ma_context g_capture_context;
static
bool
g_capture_context_inited =
false
;
static
bool
g_capture_context_is_null =
false
;
//
which backend g_capture_context was built with (tracks g_force_null_backend)
static
ma_device g_capture_device;
static
ma_pcm_rb g_capture_rb;
static
bool
g_capture_initialized =
false
;
static
int
g_capture_channels =
0
;
//
Frames dropped because the ring was full when the callback tried to write (drain loop too slow).
//
Written on the audio thread, read on the main thread — atomic to stay data-race-clean under TSAN.
static
std::atomic<
uint64_t
> g_capture_overflow_frames {
0
};
//
Value-copies of the last capture enumeration, so device names/ids survive past the context-internal
//
buffer that ma_context_get_devices returns. Populated by dasAudio_record_device_count (main thread).
static
vector<ma_device_info> g_capture_device_cache;
void
dasAudio_set_null_device
(
bool
enabled ) {
g_force_null_backend = enabled;
//
The capture context is rebuilt lazily in ensure_capture_context when its backend no longer
//
matches this flag — so a toggle here (even mid-capture) takes effect on the next idle use.
}
bool
dasAudio_is_single_threaded
() {
return
g_audio_single_threaded;
}
void
on_error_log
(
void
* , ma_uint32 level,
const
char
* message ) {
if
(level <=
1
) {
LOG
(LogLevel::error) << message;
}
else
{
LOG
(LogLevel::info) << message;
}
}
void
data_callback
(ma_device*,
void
* pOutput,
const
void
*, ma_uint32 frameCount) {
float
fdt =
1
.
0f
/
float
(g_rate);
Array buffer;
array_mark_locked
(buffer, pOutput, frameCount * g_channels);
lock_guard<recursive_mutex>
guard
(*g_mixer_context->
contextMutex
);
auto
saved =
daScriptEnvironment::exchangeBound
(g_mixer_env);
g_mixer_context->
restart
();
if
( !g_mixer_context.
get
()->
runWithCatch
([&](){
das_invoke_function<
void
>::invoke<Array&,
int32_t
,
int32_t
>(g_mixer_context.
get
(),
nullptr
,g_mixer_function,buffer,g_channels,g_rate,fdt);
}) ) {
g_mixer_context->
to_err
(&g_mixer_context->
exceptionAt
, g_mixer_context->
getException
());
g_mixer_context->
clearException
();
}
daScriptEnvironment::setBound
(saved);
}
Context &
dasAudio_mixerContext
( Context * context, LineInfoArg * at ) {
if
( !g_mixer_context ) context->
throw_error_at
(at,
"
sound mixer is not initialized
"
);
return
*g_mixer_context;
}
bool
dasAudio_init
( TFunc<
void
,TTemporary<TArray<
float
>>,
int32_t
,
int32_t
,
float
> mixer,
int32_t
rate,
int32_t
channels, Context & context ) {
g_mixer_initialized =
false
;
//
Record how this audio system comes up: single-threaded (device callback on
//
the main thread, no separate audio thread) vs threaded. See g_audio_single_threaded.
#
if
defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__)
g_audio_single_threaded =
true
;
#
else
g_audio_single_threaded =
false
;
#
endif
g_rate = rate;
g_channels = channels;
//
log
ma_log_init
(
nullptr
, &g_ma_log_struct);
ma_log_register_callback
(&g_ma_log_struct, {on_error_log,
nullptr
});
//
device
ma_device_config deviceConfig;
deviceConfig =
ma_device_config_init
(ma_device_type_playback);
deviceConfig.
playback
.
format
= ma_format_f32;
deviceConfig.
playback
.
channels
= g_channels;
deviceConfig.
sampleRate
= g_rate;
deviceConfig.
dataCallback
= data_callback;
deviceConfig.
pUserData
=
NULL
;
ma_context * pContext =
nullptr
;
if
( g_force_null_backend ) {
//
Restrict to the null backend (timer-driven callback, no hardware).
ma_backend nullBackend = ma_backend_null;
if
(
ma_context_init
(&nullBackend,
1
,
nullptr
, &g_null_context) !=
MA_SUCCESS
) {
LOG
(LogLevel::error) <<
"
failed to init null audio context.
\n
"
;
return
false
;
}
g_null_context_inited =
true
;
pContext = &g_null_context;
}
if
(
ma_device_init
(pContext, &deviceConfig, &g_device) !=
MA_SUCCESS
) {
LOG
(LogLevel::error) <<
"
failed to open playback device.
\n
"
;
if
( g_null_context_inited ) {
ma_context_uninit
(&g_null_context); g_null_context_inited =
false
; }
return
false
;
}
g_mixer_context.
reset
(
get_clone_context
(&context,
uint32_t
(ContextCategory::audio_context)));
g_mixer_context->
verySafeContext
=
false
;
g_mixer_function = mixer;
g_mixer_env =
daScriptEnvironment::getBound
();
if
(
ma_device_start
(&g_device) !=
MA_SUCCESS
) {
ma_device_uninit
(&g_device);
if
( g_null_context_inited ) {
ma_context_uninit
(&g_null_context); g_null_context_inited =
false
; }
g_mixer_context.
reset
();
return
false
;
}
g_mixer_initialized =
true
;
return
true
;
}
//
Bring up a persistent context for capture: enumeration hands back an opaque, context-owned
//
ma_device_id, and the device we later open on it must outlive that context — so we keep one
//
around rather than the transient (pContext==nullptr) form the playback path uses. Honors the
//
null-backend override so headless/CI runs enumerate+capture without real hardware.
static
bool
ensure_capture_context
() {
//
If the cached context was built for a different backend than currently requested (e.g.
//
sound_set_null_device was toggled since), drop it and rebuild — but only while idle; a live
//
capture device holds this context, so a mismatch during recording waits until the next use.
if
( g_capture_context_inited && g_capture_context_is_null != g_force_null_backend && !g_capture_initialized ) {
ma_context_uninit
(&g_capture_context);
g_capture_context_inited =
false
;
g_capture_device_cache.
clear
();
}
if
( g_capture_context_inited )
return
true
;
ma_result r;
if
( g_force_null_backend ) {
ma_backend nullBackend = ma_backend_null;
r =
ma_context_init
(&nullBackend,
1
,
nullptr
, &g_capture_context);
}
else
{
r =
ma_context_init
(
nullptr
,
0
,
nullptr
, &g_capture_context);
}
if
( r !=
MA_SUCCESS
) {
LOG
(LogLevel::error) <<
"
failed to init capture context.
\n
"
;
return
false
;
}
g_capture_context_inited =
true
;
g_capture_context_is_null = g_force_null_backend;
return
true
;
}
void
dasAudio_finalize
(
void
) {
if
( g_mixer_initialized ) {
ma_device_uninit
(&g_device);
g_mixer_context.
reset
();
g_mixer_initialized =
false
;
}
//
capture teardown, in case a script never called sound_record_stop
if
( g_capture_initialized ) {
ma_device_uninit
(&g_capture_device);
g_capture_initialized =
false
;
ma_pcm_rb_uninit
(&g_capture_rb);
}
if
( g_capture_context_inited ) {
ma_context_uninit
(&g_capture_context);
g_capture_context_inited =
false
;
}
g_capture_device_cache.
clear
();
if
( g_null_context_inited ) {
ma_context_uninit
(&g_null_context);
g_null_context_inited =
false
;
}
}
//
RT-thread capture callback: append the just-captured interleaved f32 frames to the ring. Pure
//
C++ — no daScript, no allocation, no lock. On overflow (drain loop fell behind) the excess is
//
dropped and counted; recording never blocks the audio thread.
static
void
capture_callback
( ma_device *,
void
*,
const
void
* pInput, ma_uint32 frameCount ) {
if
( !g_capture_initialized || pInput ==
nullptr
)
return
;
const
float
* src = (
const
float
*) pInput;
ma_uint32 channels = (ma_uint32) g_capture_channels;
ma_uint32 framesLeft = frameCount;
ma_uint32 srcFrame =
0
;
while
( framesLeft >
0
) {
ma_uint32 chunk = framesLeft;
void
* pWrite =
nullptr
;
if
(
ma_pcm_rb_acquire_write
(&g_capture_rb, &chunk, &pWrite) !=
MA_SUCCESS
)
break
;
if
( chunk ==
0
) {
ma_pcm_rb_commit_write
(&g_capture_rb,
0
);
g_capture_overflow_frames.
fetch_add
(framesLeft, std::memory_order_relaxed);
break
;
}
memcpy
(pWrite, src + (
size_t
)srcFrame * channels, (
size_t
)chunk * channels *
sizeof
(
float
));
ma_pcm_rb_commit_write
(&g_capture_rb, chunk);
srcFrame += chunk;
framesLeft -= chunk;
}
}
bool
dasAudio_record_start
(
int32_t
rate,
int32_t
channels,
int32_t
rb_frames,
int32_t
device_index, Context * context, LineInfoArg * at ) {
if
( g_capture_initialized ) context->
throw_error_at
(at,
"
already recording; call sound_record_stop first
"
);
if
( rate <=
0
|| channels <=
0
) context->
throw_error_at
(at,
"
record rate and channels must be positive
"
);
if
( rb_frames <=
0
) rb_frames = rate;
//
~1s ring by default
if
( !
ensure_capture_context
() )
return
false
;
if
(
ma_pcm_rb_init
(ma_format_f32, (ma_uint32)channels, (ma_uint32)rb_frames,
nullptr
,
nullptr
, &g_capture_rb) !=
MA_SUCCESS
) {
LOG
(LogLevel::error) <<
"
failed to init capture ring buffer.
\n
"
;
return
false
;
}
ma_device_config cfg =
ma_device_config_init
(ma_device_type_capture);
cfg.
capture
.
format
= ma_format_f32;
cfg.
capture
.
channels
= (ma_uint32)channels;
cfg.
sampleRate
= (ma_uint32)rate;
cfg.
dataCallback
= capture_callback;
cfg.
pUserData
=
nullptr
;
if
( device_index >=
0
) {
//
Re-enumerate for a fresh, valid id; the pointer only needs to survive until ma_device_init copies it.
ma_device_info * pCapture =
nullptr
;
ma_uint32 captureCount =
0
;
if
(
ma_context_get_devices
(&g_capture_context,
nullptr
,
nullptr
, &pCapture, &captureCount) ==
MA_SUCCESS
&& device_index < (
int32_t
)captureCount ) {
cfg.
capture
.
pDeviceID
= &pCapture[device_index].
id
;
}
else
{
LOG
(LogLevel::error) <<
"
capture device index out of range; falling back to default device.
\n
"
;
}
}
g_capture_overflow_frames.
store
(
0
, std::memory_order_relaxed);
if
(
ma_device_init
(&g_capture_context, &cfg, &g_capture_device) !=
MA_SUCCESS
) {
LOG
(LogLevel::error) <<
"
failed to open capture device.
\n
"
;
ma_pcm_rb_uninit
(&g_capture_rb);
return
false
;
}
g_capture_channels = channels;
g_capture_initialized =
true
;
//
set before start: the callback may fire immediately
if
(
ma_device_start
(&g_capture_device) !=
MA_SUCCESS
) {
LOG
(LogLevel::error) <<
"
failed to start capture device.
\n
"
;
g_capture_initialized =
false
;
ma_device_uninit
(&g_capture_device);
ma_pcm_rb_uninit
(&g_capture_rb);
return
false
;
}
return
true
;
}
void
dasAudio_record_stop
(
void
) {
if
( !g_capture_initialized )
return
;
ma_device_uninit
(&g_capture_device);
//
stops the device and joins the audio thread
g_capture_initialized =
false
;
ma_pcm_rb_uninit
(&g_capture_rb);
}
//
Drain up to out's length of interleaved f32 from the ring into out; returns FRAMES read
//
(0 if not recording or nothing buffered). out is caller-sized; frames = out.size / channels.
int32_t
dasAudio_record_read
( TArray<
float
> & out, Context *, LineInfoArg * ) {
if
( !g_capture_initialized )
return
0
;
ma_uint32 channels = (ma_uint32) g_capture_channels;
if
( channels ==
0
|| out.
size
==
0
)
return
0
;
ma_uint32 wantFrames = (ma_uint32)(out.
size
/ channels);
float
* dst = (
float
*) out.
data
;
ma_uint32 framesRead =
0
;
while
( framesRead < wantFrames ) {
ma_uint32 chunk = wantFrames - framesRead;
void
* pRead =
nullptr
;
if
(
ma_pcm_rb_acquire_read
(&g_capture_rb, &chunk, &pRead) !=
MA_SUCCESS
)
break
;
if
( chunk ==
0
) {
ma_pcm_rb_commit_read
(&g_capture_rb,
0
);
break
; }
memcpy
(dst + (
size_t
)framesRead * channels, pRead, (
size_t
)chunk * channels *
sizeof
(
float
));
ma_pcm_rb_commit_read
(&g_capture_rb, chunk);
framesRead += chunk;
}
return
(
int32_t
) framesRead;
}
int32_t
dasAudio_record_available
(
void
) {
if
( !g_capture_initialized )
return
0
;
return
(
int32_t
)
ma_pcm_rb_available_read
(&g_capture_rb);
}
bool
dasAudio_is_recording
(
void
) {
return
g_capture_initialized;
}
int64_t
dasAudio_record_overflow_frames
(
void
) {
return
(
int64_t
) g_capture_overflow_frames.
load
(std::memory_order_relaxed);
}
int32_t
dasAudio_record_device_count
( Context *, LineInfoArg * ) {
g_capture_device_cache.
clear
();
//
a failed enumeration must not leave stale devices readable by name/is_default
if
( !
ensure_capture_context
() )
return
0
;
ma_device_info * pCapture =
nullptr
;
ma_uint32 captureCount =
0
;
if
(
ma_context_get_devices
(&g_capture_context,
nullptr
,
nullptr
, &pCapture, &captureCount) !=
MA_SUCCESS
)
return
0
;
g_capture_device_cache.
assign
(pCapture, pCapture + captureCount);
//
value-copy; ids survive next enumeration
return
(
int32_t
) captureCount;
}
char
*
dasAudio_record_device_name
(
int32_t
index, Context * context, LineInfoArg * at ) {
if
( index <
0
|| index >= (
int32_t
) g_capture_device_cache.
size
() )
return
nullptr
;
const
char
* name = g_capture_device_cache[index].
name
;
return
context->
allocateString
(name, (
uint64_t
)
strlen
(name), at);
}
bool
dasAudio_record_device_is_default
(
int32_t
index ) {
if
( index <
0
|| index >= (
int32_t
) g_capture_device_cache.
size
() )
return
false
;
return
g_capture_device_cache[index].
isDefault
!=
0
;
}
MA_API
ma_result
dasAudio_ma_resampler_init
(
const
ma_resampler_config* pConfig, ma_resampler* pResampler) {
return
ma_resampler_init
(pConfig,
nullptr
, pResampler);
}
MA_API
void
dasAudio_ma_resampler_uninit
(ma_resampler* pResampler) {
return
ma_resampler_uninit
(pResampler,
nullptr
);
}
MA_API
ma_result
dasAudio_ma_channel_converter_init
(
const
ma_channel_converter_config* pConfig, ma_channel_converter* pConverter) {
return
ma_channel_converter_init
(pConfig,
nullptr
, pConverter);
}
MA_API
void
dasAudio_ma_channel_converter_uninit
(ma_channel_converter* pConverter) {
return
ma_channel_converter_uninit
(pConverter,
nullptr
);
}
MA_API
ma_uint64
dasAudio_ma_resampler_get_required_input_frame_count
(
const
ma_resampler* pResampler, ma_uint64 outputFrameCount) {
ma_uint64 inputFrameCount =
0ul
;
ma_resampler_get_required_input_frame_count
(pResampler, outputFrameCount, &inputFrameCount);
return
inputFrameCount;
}
MA_API
ma_uint64
dasAudio_ma_resampler_get_expected_output_frame_count
(
const
ma_resampler* pResampler, ma_uint64 inputFrameCount) {
ma_uint64 outputFrameCount =
0ul
;
ma_resampler_get_expected_output_frame_count
(pResampler, inputFrameCount, &outputFrameCount);
return
outputFrameCount;
}
MA_API
ma_result
dasAudio_ma_decoder_init_memory
(
const
void
* pData, ma_uint64 dataSize,
const
ma_decoder_config* pConfig, ma_decoder* pDecoder) {
return
ma_decoder_init_memory
(pData, (
size_t
)dataSize, pConfig, pDecoder);
}
MA_API
ma_uint64
dasAudio_ma_decoder_get_length_in_pcm_frames
(ma_decoder* pDecoder) {
ma_uint64 frameCount =
0
;
ma_decoder_get_length_in_pcm_frames
(pDecoder, &frameCount);
return
frameCount;
}
MA_API
ma_uint64
dasAudio_ma_decoder_read_pcm_frames
(ma_decoder* pDecoder,
void
* pFramesOut, ma_uint64 frameCount) {
ma_uint64 framesRead =
0
;
ma_decoder_read_pcm_frames
(pDecoder, pFramesOut, frameCount, &framesRead);
return
framesRead;
}
struct
MAResamplerConfigAnnotation
: ManagedStructureAnnotation<ma_resampler_config> {
MAResamplerConfigAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_resampler_config
"
, mlib,
"
ma_resampler_config
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(format)>(
"
format
"
,
"
format
"
);
addField<
DAS_BIND_MANAGED_FIELD
(channels)>(
"
channels
"
,
"
channels
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sampleRateIn)>(
"
sampleRateIn
"
,
"
sampleRateIn
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sampleRateOut)>(
"
sampleRateOut
"
,
"
sampleRateOut
"
);
/*
addField<DAS_BIND_MANAGED_FIELD(lpfOrder)>("lpfOrder","lpfOrder");
addField<DAS_BIND_MANAGED_FIELD(lpfNyquistFactor)>("lpfNyquistFactor","lpfNyquistFactor");
addField<DAS_BIND_MANAGED_FIELD(quality)>("quality","quality");
*/
}
};
struct
MAResamplerAnnotation
: ManagedStructureAnnotation<ma_resampler> {
MAResamplerAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_resampler
"
, mlib,
"
ma_resampler
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(format)>(
"
format
"
,
"
format
"
);
addField<
DAS_BIND_MANAGED_FIELD
(channels)>(
"
channels
"
,
"
channels
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sampleRateIn)>(
"
sampleRateIn
"
,
"
sampleRateIn
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sampleRateOut)>(
"
sampleRateOut
"
,
"
sampleRateOut
"
);
//
addField<DAS_BIND_MANAGED_FIELD(state)>("state","state");
}
};
struct
MAChannelConvertorConfigAnnotation
: ManagedStructureAnnotation<ma_channel_converter_config> {
MAChannelConvertorConfigAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_channel_converter_config
"
, mlib,
"
ma_channel_converter_config
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(format)>(
"
format
"
,
"
format
"
);
addField<
DAS_BIND_MANAGED_FIELD
(channelsIn)>(
"
channelsIn
"
,
"
channelsIn
"
);
addField<
DAS_BIND_MANAGED_FIELD
(channelsOut)>(
"
channelsOut
"
,
"
channelsOut
"
);
addField<
DAS_BIND_MANAGED_FIELD
(pChannelMapIn)>(
"
channelMapIn
"
,
"
channelMapIn
"
);
addField<
DAS_BIND_MANAGED_FIELD
(pChannelMapOut)>(
"
channelMapOut
"
,
"
channelMapOut
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mixingMode)>(
"
mixingMode
"
,
"
mixingMode
"
);
addField<
DAS_BIND_MANAGED_FIELD
(ppWeights)>(
"
weights
"
,
"
weights
"
);
}
};
struct
MAChannelConverterAnnotation
: ManagedStructureAnnotation<ma_channel_converter> {
MAChannelConverterAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_channel_converter
"
, mlib,
"
ma_channel_converter
"
) {
}
};
struct
MAVolumeMixerAnnotation
: ManagedStructureAnnotation<ma_volume_mixer> {
MAVolumeMixerAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_volume_mixer
"
, mlib,
"
ma_volume_mixer
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(volume)>(
"
volume
"
,
"
volume
"
);
addField<
DAS_BIND_MANAGED_FIELD
(dvolume)>(
"
dvolume
"
,
"
dvolume
"
);
addField<
DAS_BIND_MANAGED_FIELD
(tvolume)>(
"
tvolume
"
,
"
tvolume
"
);
addField<
DAS_BIND_MANAGED_FIELD
(pan)>(
"
pan
"
,
"
pan
"
);
addField<
DAS_BIND_MANAGED_FIELD
(nChannels)>(
"
channels
"
,
"
nChannels
"
);
}
};
struct
MADecoderConfigAnnotation
: ManagedStructureAnnotation<ma_decoder_config> {
MADecoderConfigAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_decoder_config
"
, mlib,
"
ma_decoder_config
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(format)>(
"
format
"
,
"
format
"
);
addField<
DAS_BIND_MANAGED_FIELD
(channels)>(
"
channels
"
,
"
channels
"
);
addField<
DAS_BIND_MANAGED_FIELD
(pChannelMap)>(
"
channelMap
"
,
"
channelMap
"
);
addField<
DAS_BIND_MANAGED_FIELD
(channelMixMode)>(
"
channelMixMode
"
,
"
channelMixMode
"
);
addField<
DAS_BIND_MANAGED_FIELD
(ditherMode)>(
"
ditherMode
"
,
"
ditherMode
"
);
}
};
struct
MADecoderAnnotation
: ManagedStructureAnnotation<ma_decoder> {
MADecoderAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_decoder
"
, mlib,
"
ma_decoder
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(outputFormat)>(
"
outputFormat
"
,
"
outputFormat
"
);
addField<
DAS_BIND_MANAGED_FIELD
(outputChannels)>(
"
outputChannels
"
,
"
outputChannels
"
);
addField<
DAS_BIND_MANAGED_FIELD
(outputSampleRate)>(
"
outputSampleRate
"
,
"
outputSampleRate
"
);
}
};
struct
MALimiterAnnotation
: ManagedStructureAnnotation<ma_limiter> {
MALimiterAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_limiter
"
, mlib,
"
ma_limiter
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(gain)>(
"
gain
"
,
"
gain
"
);
addField<
DAS_BIND_MANAGED_FIELD
(nChannels)>(
"
nChannels
"
,
"
nChannels
"
);
addField<
DAS_BIND_MANAGED_FIELD
(attack_samples)>(
"
attack_samples
"
,
"
attack_samples
"
);
addField<
DAS_BIND_MANAGED_FIELD
(threshold)>(
"
threshold
"
,
"
threshold
"
);
addField<
DAS_BIND_MANAGED_FIELD
(attack_coeff)>(
"
attack_coeff
"
,
"
attack_coeff
"
);
addField<
DAS_BIND_MANAGED_FIELD
(release_coeff)>(
"
release_coeff
"
,
"
release_coeff
"
);
addField<
DAS_BIND_MANAGED_FIELD
(linear_limiter)>(
"
linear_limiter
"
,
"
linear_limiter
"
);
}
};
//
SF2 voice
struct
MASF2EnvelopeAnnotation
: ManagedStructureAnnotation<ma_sf2_envelope> {
MASF2EnvelopeAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_sf2_envelope
"
, mlib,
"
ma_sf2_envelope
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(stage)>(
"
stage
"
,
"
stage
"
);
addField<
DAS_BIND_MANAGED_FIELD
(level)>(
"
level
"
,
"
level
"
);
addField<
DAS_BIND_MANAGED_FIELD
(release_level)>(
"
release_level
"
,
"
release_level
"
);
addField<
DAS_BIND_MANAGED_FIELD
(slope)>(
"
slope
"
,
"
slope
"
);
addField<
DAS_BIND_MANAGED_FIELD
(is_exponential)>(
"
is_exponential
"
,
"
is_exponential
"
);
addField<
DAS_BIND_MANAGED_FIELD
(is_amp_env)>(
"
is_amp_env
"
,
"
is_amp_env
"
);
addField<
DAS_BIND_MANAGED_FIELD
(midi_velocity)>(
"
midi_velocity
"
,
"
midi_velocity
"
);
addField<
DAS_BIND_MANAGED_FIELD
(samples_until_next)>(
"
samples_until_next
"
,
"
samples_until_next
"
);
addField<
DAS_BIND_MANAGED_FIELD
(delay_sec)>(
"
delay_sec
"
,
"
delay_sec
"
);
addField<
DAS_BIND_MANAGED_FIELD
(attack_sec)>(
"
attack_sec
"
,
"
attack_sec
"
);
addField<
DAS_BIND_MANAGED_FIELD
(hold_sec)>(
"
hold_sec
"
,
"
hold_sec
"
);
addField<
DAS_BIND_MANAGED_FIELD
(decay_sec)>(
"
decay_sec
"
,
"
decay_sec
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sustain_level)>(
"
sustain_level
"
,
"
sustain_level
"
);
addField<
DAS_BIND_MANAGED_FIELD
(release_sec)>(
"
release_sec
"
,
"
release_sec
"
);
}
};
struct
MASF2BiquadAnnotation
: ManagedStructureAnnotation<ma_sf2_biquad> {
MASF2BiquadAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_sf2_biquad
"
, mlib,
"
ma_sf2_biquad
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(q_inv)>(
"
q_inv
"
,
"
q_inv
"
);
addField<
DAS_BIND_MANAGED_FIELD
(a0)>(
"
a0
"
,
"
a0
"
);
addField<
DAS_BIND_MANAGED_FIELD
(a1)>(
"
a1
"
,
"
a1
"
);
addField<
DAS_BIND_MANAGED_FIELD
(b1)>(
"
b1
"
,
"
b1
"
);
addField<
DAS_BIND_MANAGED_FIELD
(b2)>(
"
b2
"
,
"
b2
"
);
addField<
DAS_BIND_MANAGED_FIELD
(z1)>(
"
z1
"
,
"
z1
"
);
addField<
DAS_BIND_MANAGED_FIELD
(z2)>(
"
z2
"
,
"
z2
"
);
addField<
DAS_BIND_MANAGED_FIELD
(active)>(
"
active
"
,
"
active
"
);
}
};
struct
MASF2VoiceAnnotation
: ManagedStructureAnnotation<ma_sf2_voice> {
MASF2VoiceAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_sf2_voice
"
, mlib,
"
ma_sf2_voice
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(sample_start)>(
"
sample_start
"
,
"
sample_start
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sample_end)>(
"
sample_end
"
,
"
sample_end
"
);
addField<
DAS_BIND_MANAGED_FIELD
(loop_start)>(
"
loop_start
"
,
"
loop_start
"
);
addField<
DAS_BIND_MANAGED_FIELD
(loop_end)>(
"
loop_end
"
,
"
loop_end
"
);
addField<
DAS_BIND_MANAGED_FIELD
(loop_mode)>(
"
loop_mode
"
,
"
loop_mode
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sample_start_r)>(
"
sample_start_r
"
,
"
sample_start_r
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sample_end_r)>(
"
sample_end_r
"
,
"
sample_end_r
"
);
addField<
DAS_BIND_MANAGED_FIELD
(loop_start_r)>(
"
loop_start_r
"
,
"
loop_start_r
"
);
addField<
DAS_BIND_MANAGED_FIELD
(loop_end_r)>(
"
loop_end_r
"
,
"
loop_end_r
"
);
addField<
DAS_BIND_MANAGED_FIELD
(stereo)>(
"
stereo
"
,
"
stereo
"
);
addField<
DAS_BIND_MANAGED_FIELD
(position)>(
"
position
"
,
"
position
"
);
addField<
DAS_BIND_MANAGED_FIELD
(phase_inc)>(
"
phase_inc
"
,
"
phase_inc
"
);
addField<
DAS_BIND_MANAGED_FIELD
(vol_env)>(
"
vol_env
"
,
"
vol_env
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_env)>(
"
mod_env
"
,
"
mod_env
"
);
addField<
DAS_BIND_MANAGED_FIELD
(filter)>(
"
filter
"
,
"
filter
"
);
addField<
DAS_BIND_MANAGED_FIELD
(filter_r)>(
"
filter_r
"
,
"
filter_r
"
);
addField<
DAS_BIND_MANAGED_FIELD
(initial_filter_fc)>(
"
initial_filter_fc
"
,
"
initial_filter_fc
"
);
addField<
DAS_BIND_MANAGED_FIELD
(initial_filter_q)>(
"
initial_filter_q
"
,
"
initial_filter_q
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_env_to_pitch)>(
"
mod_env_to_pitch
"
,
"
mod_env_to_pitch
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_lfo_to_pitch)>(
"
mod_lfo_to_pitch
"
,
"
mod_lfo_to_pitch
"
);
addField<
DAS_BIND_MANAGED_FIELD
(vib_lfo_to_pitch)>(
"
vib_lfo_to_pitch
"
,
"
vib_lfo_to_pitch
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_env_to_filter_fc)>(
"
mod_env_to_filter_fc
"
,
"
mod_env_to_filter_fc
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_lfo_to_filter_fc)>(
"
mod_lfo_to_filter_fc
"
,
"
mod_lfo_to_filter_fc
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_lfo_to_volume)>(
"
mod_lfo_to_volume
"
,
"
mod_lfo_to_volume
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_lfo_phase)>(
"
mod_lfo_phase
"
,
"
mod_lfo_phase
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_lfo_freq)>(
"
mod_lfo_freq
"
,
"
mod_lfo_freq
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_lfo_delay)>(
"
mod_lfo_delay
"
,
"
mod_lfo_delay
"
);
addField<
DAS_BIND_MANAGED_FIELD
(mod_lfo_elapsed)>(
"
mod_lfo_elapsed
"
,
"
mod_lfo_elapsed
"
);
addField<
DAS_BIND_MANAGED_FIELD
(vib_lfo_phase)>(
"
vib_lfo_phase
"
,
"
vib_lfo_phase
"
);
addField<
DAS_BIND_MANAGED_FIELD
(vib_lfo_freq)>(
"
vib_lfo_freq
"
,
"
vib_lfo_freq
"
);
addField<
DAS_BIND_MANAGED_FIELD
(vib_lfo_delay)>(
"
vib_lfo_delay
"
,
"
vib_lfo_delay
"
);
addField<
DAS_BIND_MANAGED_FIELD
(vib_lfo_elapsed)>(
"
vib_lfo_elapsed
"
,
"
vib_lfo_elapsed
"
);
addField<
DAS_BIND_MANAGED_FIELD
(pitch_bend_cents)>(
"
pitch_bend_cents
"
,
"
pitch_bend_cents
"
);
addField<
DAS_BIND_MANAGED_FIELD
(attenuation)>(
"
attenuation
"
,
"
attenuation
"
);
addField<
DAS_BIND_MANAGED_FIELD
(pan)>(
"
pan
"
,
"
pan
"
);
addField<
DAS_BIND_MANAGED_FIELD
(released)>(
"
released
"
,
"
released
"
);
addField<
DAS_BIND_MANAGED_FIELD
(finished)>(
"
finished
"
,
"
finished
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sample_rate)>(
"
sample_rate
"
,
"
sample_rate
"
);
}
};
struct
I3DL2ReverbPropertiesAnnotation
: ManagedStructureAnnotation<I3DL2ReverbProperties> {
I3DL2ReverbPropertiesAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
I3DL2ReverbProperties
"
, mlib,
"
I3DL2ReverbProperties
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(lRoom)>(
"
lRoom
"
,
"
lRoom
"
);
addField<
DAS_BIND_MANAGED_FIELD
(lRoomHF)>(
"
lRoomHF
"
,
"
lRoomHF
"
);
addField<
DAS_BIND_MANAGED_FIELD
(flDecayTime)>(
"
flDecayTime
"
,
"
flDecayTime
"
);
addField<
DAS_BIND_MANAGED_FIELD
(flDecayHFRatio)>(
"
flDecayHFRatio
"
,
"
flDecayHFRatio
"
);
addField<
DAS_BIND_MANAGED_FIELD
(lReflections)>(
"
lReflections
"
,
"
lReflections
"
);
addField<
DAS_BIND_MANAGED_FIELD
(flReflectionsDelay)>(
"
flReflectionsDelay
"
,
"
flReflectionsDelay
"
);
addField<
DAS_BIND_MANAGED_FIELD
(lReverb)>(
"
lReverb
"
,
"
lReverb
"
);
addField<
DAS_BIND_MANAGED_FIELD
(flReverbDelay)>(
"
flReverbDelay
"
,
"
flReverbDelay
"
);
addField<
DAS_BIND_MANAGED_FIELD
(flDiffusion)>(
"
flDiffusion
"
,
"
flDiffusion
"
);
addField<
DAS_BIND_MANAGED_FIELD
(flDensity)>(
"
flDensity
"
,
"
flDensity
"
);
}
};
struct
I3DL2ReverbAnnotation
: ManagedStructureAnnotation<I3DL2Reverb,
true
,
true
> {
I3DL2ReverbAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
I3DL2Reverb
"
, mlib,
"
I3DL2Reverb
"
) {
}
};
//
─── Chorus ───
struct
MaChorusConfigAnnotation
: ManagedStructureAnnotation<ma_chorus_config> {
MaChorusConfigAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_chorus_config
"
, mlib,
"
ma_chorus_config
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(rate)>(
"
rate
"
,
"
rate
"
);
addField<
DAS_BIND_MANAGED_FIELD
(depth)>(
"
depth
"
,
"
depth
"
);
addField<
DAS_BIND_MANAGED_FIELD
(feedback)>(
"
feedback
"
,
"
feedback
"
);
addField<
DAS_BIND_MANAGED_FIELD
(delay_ms)>(
"
delay_ms
"
,
"
delay_ms
"
);
addField<
DAS_BIND_MANAGED_FIELD
(wet)>(
"
wet
"
,
"
wet
"
);
}
};
struct
MaChorusAnnotation
: ManagedStructureAnnotation<ma_chorus,
true
,
true
> {
MaChorusAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_chorus
"
, mlib,
"
ma_chorus
"
) {
}
};
void
dasAudio_chorusInit
( ma_chorus * chorus,
float
sample_rate, Context * context, LineInfoArg * at ) {
if
( !chorus ) context->
throw_error_at
(at,
"
chorus is null
"
);
ma_chorus_init
(chorus, sample_rate);
}
void
dasAudio_chorusProcess
( ma_chorus * chorus,
float
* input,
float
* output,
int
nSamples, Context * context, LineInfoArg * at ) {
if
( !chorus ) context->
throw_error_at
(at,
"
chorus is null
"
);
ma_chorus_process
(chorus, input, output, nSamples);
}
void
dasAudio_chorusSetConfig
( ma_chorus * chorus,
const
ma_chorus_config & config, Context * context, LineInfoArg * at ) {
if
( !chorus ) context->
throw_error_at
(at,
"
chorus is null
"
);
ma_chorus_set_config
(chorus, &config);
}
ma_chorus_config
dasAudio_chorusConfigDefault
( ) {
return
ma_chorus_config_default
();
}
//
─── Effects (bitcrush, waveshaper, djfilter, bandpass) ───
struct
MaBitcrushAnnotation
: ManagedStructureAnnotation<ma_bitcrush,
true
,
true
> {
MaBitcrushAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_bitcrush
"
, mlib,
"
ma_bitcrush
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(bits)>(
"
bits
"
,
"
bits
"
);
addField<
DAS_BIND_MANAGED_FIELD
(coarse)>(
"
coarse
"
,
"
coarse
"
);
}
};
struct
MaWaveshaperAnnotation
: ManagedStructureAnnotation<ma_waveshaper,
true
,
true
> {
MaWaveshaperAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_waveshaper
"
, mlib,
"
ma_waveshaper
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(drive)>(
"
drive
"
,
"
drive
"
);
}
};
struct
MaDjfilterAnnotation
: ManagedStructureAnnotation<ma_djfilter,
true
,
true
> {
MaDjfilterAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_djfilter
"
, mlib,
"
ma_djfilter
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(position)>(
"
position
"
,
"
position
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sample_rate)>(
"
sample_rate
"
,
"
sample_rate
"
);
}
};
struct
MaBandpassAnnotation
: ManagedStructureAnnotation<ma_bandpass,
true
,
true
> {
MaBandpassAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_bandpass
"
, mlib,
"
ma_bandpass
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(freq)>(
"
freq
"
,
"
freq
"
);
addField<
DAS_BIND_MANAGED_FIELD
(q)>(
"
q
"
,
"
q
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sample_rate)>(
"
sample_rate
"
,
"
sample_rate
"
);
}
};
void
dasAudio_bitcrushInit
( ma_bitcrush * bc, Context * context, LineInfoArg * at ) {
if
( !bc ) context->
throw_error_at
(at,
"
bitcrush is null
"
);
ma_bitcrush_init
(bc);
}
void
dasAudio_bitcrushProcess
( ma_bitcrush * bc,
float
* buf,
int
nFrames, Context * context, LineInfoArg * at ) {
if
( !bc ) context->
throw_error_at
(at,
"
bitcrush is null
"
);
ma_bitcrush_process
(bc, buf, nFrames);
}
void
dasAudio_waveshaperInit
( ma_waveshaper * ws, Context * context, LineInfoArg * at ) {
if
( !ws ) context->
throw_error_at
(at,
"
waveshaper is null
"
);
ma_waveshaper_init
(ws);
}
void
dasAudio_waveshaperProcess
( ma_waveshaper * ws,
float
* buf,
int
nFrames, Context * context, LineInfoArg * at ) {
if
( !ws ) context->
throw_error_at
(at,
"
waveshaper is null
"
);
ma_waveshaper_process
(ws, buf, nFrames);
}
void
dasAudio_djfilterInit
( ma_djfilter * dj,
float
sample_rate, Context * context, LineInfoArg * at ) {
if
( !dj ) context->
throw_error_at
(at,
"
djfilter is null
"
);
ma_djfilter_init
(dj, sample_rate);
}
void
dasAudio_djfilterProcess
( ma_djfilter * dj,
float
* buf,
int
nFrames, Context * context, LineInfoArg * at ) {
if
( !dj ) context->
throw_error_at
(at,
"
djfilter is null
"
);
ma_djfilter_process
(dj, buf, nFrames);
}
void
dasAudio_bandpassInit
( ma_bandpass * bp,
float
sample_rate, Context * context, LineInfoArg * at ) {
if
( !bp ) context->
throw_error_at
(at,
"
bandpass is null
"
);
ma_bandpass_init
(bp, sample_rate);
}
void
dasAudio_bandpassSetup
( ma_bandpass * bp,
float
freq,
float
q, Context * context, LineInfoArg * at ) {
if
( !bp ) context->
throw_error_at
(at,
"
bandpass is null
"
);
ma_bandpass_setup
(bp, freq, q);
}
void
dasAudio_bandpassProcess
( ma_bandpass * bp,
float
* buf,
int
nFrames, Context * context, LineInfoArg * at ) {
if
( !bp ) context->
throw_error_at
(at,
"
bandpass is null
"
);
ma_bandpass_process
(bp, buf, nFrames);
}
//
─── Phaser / Tremolo / Compressor ───
struct
MaPhaserAnnotation
: ManagedStructureAnnotation<ma_phaser,
true
,
true
> {
MaPhaserAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_phaser
"
, mlib,
"
ma_phaser
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(rate)>(
"
rate
"
,
"
rate
"
);
addField<
DAS_BIND_MANAGED_FIELD
(depth)>(
"
depth
"
,
"
depth
"
);
addField<
DAS_BIND_MANAGED_FIELD
(center)>(
"
center
"
,
"
center
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sweep)>(
"
sweep
"
,
"
sweep
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sample_rate)>(
"
sample_rate
"
,
"
sample_rate
"
);
}
};
struct
MaTremoloAnnotation
: ManagedStructureAnnotation<ma_tremolo,
true
,
true
> {
MaTremoloAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_tremolo
"
, mlib,
"
ma_tremolo
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(rate)>(
"
rate
"
,
"
rate
"
);
addField<
DAS_BIND_MANAGED_FIELD
(depth)>(
"
depth
"
,
"
depth
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sample_rate)>(
"
sample_rate
"
,
"
sample_rate
"
);
}
};
struct
MaCompressorAnnotation
: ManagedStructureAnnotation<ma_compressor,
true
,
true
> {
MaCompressorAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_compressor
"
, mlib,
"
ma_compressor
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(threshold_db)>(
"
threshold_db
"
,
"
threshold_db
"
);
addField<
DAS_BIND_MANAGED_FIELD
(ratio)>(
"
ratio
"
,
"
ratio
"
);
addField<
DAS_BIND_MANAGED_FIELD
(knee_db)>(
"
knee_db
"
,
"
knee_db
"
);
addField<
DAS_BIND_MANAGED_FIELD
(attack)>(
"
attack
"
,
"
attack
"
);
addField<
DAS_BIND_MANAGED_FIELD
(release)>(
"
release
"
,
"
release
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sample_rate)>(
"
sample_rate
"
,
"
sample_rate
"
);
}
};
void
dasAudio_phaserInit
( ma_phaser * ph,
float
sample_rate, Context * context, LineInfoArg * at ) {
if
( !ph ) context->
throw_error_at
(at,
"
phaser is null
"
);
ma_phaser_init
(ph, sample_rate);
}
void
dasAudio_phaserProcess
( ma_phaser * ph,
float
* buf,
int
nFrames, Context * context, LineInfoArg * at ) {
if
( !ph ) context->
throw_error_at
(at,
"
phaser is null
"
);
ma_phaser_process
(ph, buf, nFrames);
}
void
dasAudio_tremoloInit
( ma_tremolo * tr,
float
sample_rate, Context * context, LineInfoArg * at ) {
if
( !tr ) context->
throw_error_at
(at,
"
tremolo is null
"
);
ma_tremolo_init
(tr, sample_rate);
}
void
dasAudio_tremoloProcess
( ma_tremolo * tr,
float
* buf,
int
nFrames, Context * context, LineInfoArg * at ) {
if
( !tr ) context->
throw_error_at
(at,
"
tremolo is null
"
);
ma_tremolo_process
(tr, buf, nFrames);
}
void
dasAudio_compressorInit
( ma_compressor * c,
float
sample_rate, Context * context, LineInfoArg * at ) {
if
( !c ) context->
throw_error_at
(at,
"
compressor is null
"
);
ma_compressor_init
(c, sample_rate);
}
void
dasAudio_compressorProcess
( ma_compressor * c,
float
* buf,
int
nFrames, Context * context, LineInfoArg * at ) {
if
( !c ) context->
throw_error_at
(at,
"
compressor is null
"
);
ma_compressor_process
(c, buf, nFrames);
}
struct
MAHrtfAnnotation
: ManagedStructureAnnotation<ma_hrtf> {
MAHrtfAnnotation
( ModuleLibrary & mlib )
: ManagedStructureAnnotation(
"
ma_hrtf
"
, mlib,
"
ma_hrtf
"
) {
addField<
DAS_BIND_MANAGED_FIELD
(taps)>(
"
taps
"
,
"
taps
"
);
addField<
DAS_BIND_MANAGED_FIELD
(azimuth)>(
"
azimuth
"
,
"
azimuth
"
);
addField<
DAS_BIND_MANAGED_FIELD
(elevation)>(
"
elevation
"
,
"
elevation
"
);
addField<
DAS_BIND_MANAGED_FIELD
(sampleRate)>(
"
sampleRate
"
,
"
sampleRate
"
);
addField<
DAS_BIND_MANAGED_FIELD
(leftfip)>(
"
leftfip
"
,
"
leftfip
"
);
addField<
DAS_BIND_MANAGED_FIELD
(rightfip)>(
"
rightfip
"
,
"
rightfip
"
);
addField<
DAS_BIND_MANAGED_FIELD
(fft_size)>(
"
fft_size
"
,
"
fft_size
"
);
}
};
void
dasAudio_setSampleRate
( I3DL2Reverb * reverb,
float
rate, Context * context, LineInfoArg * at ) {
if
( !reverb ) context->
throw_error_at
(at,
"
reverb is null
"
);
reverb->
SetSampleRate
(rate);
}
void
dasAudio_setProperties
( I3DL2Reverb * reverb,
const
I3DL2ReverbProperties & props, Context * context, LineInfoArg * at ) {
if
( !reverb ) context->
throw_error_at
(at,
"
reverb is null
"
);
reverb->
SetReverbProperties
(props);
}
void
dasAudio_process
( I3DL2Reverb * reverb,
float
* buffer,
float
* outBuffer,
int
nSamples, Context * context, LineInfoArg * at ) {
if
( !reverb ) context->
throw_error_at
(at,
"
reverb is null
"
);
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL