Check-in [c6e3704ca9]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added Muzic compatible MIDI sound package
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c6e3704ca9d276334771cfa4112f6a1070628efa
User & Date: chw 2015-06-04 21:16:09
Context
2015-06-06
06:34
refactored Muzic compatible MIDI sound package check-in: 517936c1f6 user: chw tags: trunk
2015-06-04
21:16
added Muzic compatible MIDI sound package check-in: c6e3704ca9 user: chw tags: trunk
2015-06-02
05:14
improved short UUIDs in ble command check-in: 5b26cee2b1 user: chw tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to hellotcltk/libs/tcltkapplib.jar.

cannot compute difference between binary files

jni/sdl2tk/sdl/agg-2.4/examples/blend_color.cpp became a regular file.

jni/sdl2tk/unix/configure.in became a regular file.

jni/sdl2tk/win/buildall.vc.bat became executable.

Changes to jni/src/Android.mk.

17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32

LOCAL_SRC_FILES := \
	../SDL2/src/main/android/SDL_android_main.c \
	tkBorg.c \
	tclRfcomm.c \
	tclUsbserial.c \
	tclBLE.c \

	tkAppInit.c

LOCAL_CFLAGS := $(tcl_cflags) $(tk_cflags)

LOCAL_SHARED_LIBRARIES := libtcl libSDL2 libtk

LOCAL_LDLIBS := -ldl -lGLESv1_CM -llog

include $(BUILD_SHARED_LIBRARY)







>









17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

LOCAL_SRC_FILES := \
	../SDL2/src/main/android/SDL_android_main.c \
	tkBorg.c \
	tclRfcomm.c \
	tclUsbserial.c \
	tclBLE.c \
	tclMuzic.c \
	tkAppInit.c

LOCAL_CFLAGS := $(tcl_cflags) $(tk_cflags)

LOCAL_SHARED_LIBRARIES := libtcl libSDL2 libtk

LOCAL_LDLIBS := -ldl -lGLESv1_CM -llog

include $(BUILD_SHARED_LIBRARY)

Added jni/src/eas.h.













































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
/*----------------------------------------------------------------------------
 *
 * File:
 * eas.h
 *
 * Contents and purpose:
 * The public interface header for the EAS synthesizer.
 *
 * This header only contains declarations that are specific
 * to this implementation.
 *
 * DO NOT MODIFY THIS FILE!
 *
 * Copyright Sonic Network Inc. 2005, 2006

 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *----------------------------------------------------------------------------
 * Revision Control:
 *   $Revision: 852 $
 *   $Date: 2007-09-04 11:43:49 -0700 (Tue, 04 Sep 2007) $
 *----------------------------------------------------------------------------
*/

#ifndef _EAS_H
#define _EAS_H

#include "eas_types.h"

/* for C++ linkage */
#ifdef __cplusplus
extern "C" {
#endif

/* library version macro */
#define MAKE_LIB_VERSION(a,b,c,d) (((((((EAS_U32) a <<8) | (EAS_U32) b) << 8) | (EAS_U32) c) << 8) | (EAS_U32) d)
#define LIB_VERSION MAKE_LIB_VERSION(3, 6, 10, 14)

typedef struct
{
    EAS_U32     libVersion;
    EAS_BOOL    checkedVersion;
    EAS_I32     maxVoices;
    EAS_I32     numChannels;
    EAS_I32     sampleRate;
    EAS_I32     mixBufferSize;
    EAS_BOOL    filterEnabled;
    EAS_U32     buildTimeStamp;
    EAS_CHAR    *buildGUID;
} S_EAS_LIB_CONFIG;

/* enumerated effects module numbers for configuration */
typedef enum
{
    EAS_MODULE_ENHANCER = 0,
    EAS_MODULE_COMPRESSOR,
    EAS_MODULE_REVERB,
    EAS_MODULE_CHORUS,
    EAS_MODULE_WIDENER,
    EAS_MODULE_GRAPHIC_EQ,
    EAS_MODULE_WOW,
    EAS_MODULE_MAXIMIZER,
    EAS_MODULE_TONECONTROLEQ,
    NUM_EFFECTS_MODULES
} E_FX_MODULES;

/* enumerated optional module numbers for configuration */
typedef enum
{
    EAS_MODULE_MMAPI_TONE_CONTROL = 0,
    EAS_MODULE_METRICS
} E_OPT_MODULES;
#define NUM_OPTIONAL_MODULES    2

/* enumerated audio decoders for configuration */
typedef enum
{
    EAS_DECODER_PCM = 0,
    EAS_DECODER_SMAF_ADPCM,
    EAS_DECODER_IMA_ADPCM,
    EAS_DECODER_7BIT_SMAF_ADPCM,
    EAS_DECODER_NOT_SUPPORTED
} E_DECODER_MODULES;
#define NUM_DECODER_MODULES     4

/* defines for EAS_PEOpenStream flags parameter */
#define PCM_FLAGS_STEREO        0x00000100  /* stream is stereo */
#define PCM_FLAGS_8_BIT         0x00000001  /* 8-bit format */
#define PCM_FLAGS_UNSIGNED      0x00000010  /* unsigned format */
#define PCM_FLAGS_STREAMING     0x80000000  /* streaming mode */

/* maximum volume setting */
#define EAS_MAX_VOLUME          100

/*----------------------------------------------------------------------------
 * EAS_Init()
 *----------------------------------------------------------------------------
 * Purpose:
 * Initialize the synthesizer library
 *
 * Inputs:
 *  polyphony       - number of voices to play (dynamic memory model only)
 *  ppLibData       - pointer to data handle variable for this instance
 *
 * Outputs:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_Init (EAS_DATA_HANDLE *ppEASData);

/*----------------------------------------------------------------------------
 * EAS_Config()
 *----------------------------------------------------------------------------
 * Purpose:
 * Returns a pointer to a structure containing the configuration options
 * in this library build.
 *
 * Inputs:
 *
 * Outputs:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC const S_EAS_LIB_CONFIG *EAS_Config (void);

/*----------------------------------------------------------------------------
 * EAS_Shutdown()
 *----------------------------------------------------------------------------
 * Purpose:
 * Shuts down the library. Deallocates any memory associated with the
 * synthesizer (dynamic memory model only)
 *
 * Inputs:
 *  pEASData        - handle to data for this instance
 *
 * Outputs:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_Shutdown (EAS_DATA_HANDLE pEASData);

/*----------------------------------------------------------------------------
 * EAS_Render()
 *----------------------------------------------------------------------------
 * Purpose:
 * Parse the Midi data and render PCM audio data.
 *
 * Inputs:
 *  pEASData        - buffer for internal EAS data
 *  pOut            - output buffer pointer
 *  nNumRequested   - requested num samples to generate
 *  pnNumGenerated  - actual number of samples generated
 *
 * Outputs:
 *  EAS_SUCCESS if PCM data was successfully rendered
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_Render (EAS_DATA_HANDLE pEASData, EAS_PCM *pOut, EAS_I32 numRequested, EAS_I32 *pNumGenerated);

/*----------------------------------------------------------------------------
 * EAS_SetRepeat()
 *----------------------------------------------------------------------------
 * Purpose:
 * Set the selected stream to repeat.
 *
 * Inputs:
 *  pEASData        - handle to data for this instance
 *  streamHandle    - handle to stream
 *  repeatCount     - repeat count (0 = no repeat, -1 = repeat forever)
 *
 * Outputs:
 *
 * Side Effects:
 *
 * Notes:
 *  0 = no repeat
 *  1 = repeat once, i.e. play through twice
 *  -1 = repeat forever
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetRepeat (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 repeatCount);

/*----------------------------------------------------------------------------
 * EAS_GetRepeat()
 *----------------------------------------------------------------------------
 * Purpose:
 * Gets the current repeat count for the selected stream.
 *
 * Inputs:
 *  pEASData        - handle to data for this instance
 *  streamHandle    - handle to stream
 *  pRrepeatCount   - pointer to variable to hold repeat count
 *
 * Outputs:
 *
 * Side Effects:
 *
 * Notes:
 *  0 = no repeat
 *  1 = repeat once, i.e. play through twice
 *  -1 = repeat forever
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetRepeat (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 *pRepeatCount);

/*----------------------------------------------------------------------------
 * EAS_SetPlaybackRate()
 *----------------------------------------------------------------------------
 * Purpose:
 * Set the playback rate.
 *
 * Inputs:
 *  pEASData        - handle to data for this instance
 *  streamHandle    - handle to stream
 *  rate            - rate (28-bit fractional amount)
 *
 * Outputs:
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetPlaybackRate (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_U32 rate);
#define MAX_PLAYBACK_RATE   (EAS_U32)(1L << 29)
#define MIN_PLAYBACK_RATE   (EAS_U32)(1L << 27)

/*----------------------------------------------------------------------------
 * EAS_SetTransposition)
 *----------------------------------------------------------------------------
 * Purpose:
 * Sets the key tranposition for the synthesizer. Transposes all
 * melodic instruments by the specified amount. Range is limited
 * to +/-12 semitones.
 *
 * Inputs:
 *  pEASData        - handle to data for this instance
 *  streamHandle    - handle to stream
 *  transposition   - +/-12 semitones
 *
 * Outputs:
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetTransposition (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 transposition);
#define MAX_TRANSPOSE       12

/*----------------------------------------------------------------------------
 * EAS_SetSynthPolyphony()
 *----------------------------------------------------------------------------
 * Purpose:
 * Set the polyphony of the synthesizer. Value must be >= 1 and <= the
 * maximum number of voices. This function will pin the polyphony
 * at those limits
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * synthNum         - synthesizer number (0 = onboard, 1 = DSP)
 * polyphonyCount   - the desired polyphony count
 *
 * Outputs:
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetSynthPolyphony (EAS_DATA_HANDLE pEASData, EAS_I32 synthNum, EAS_I32 polyphonyCount);

/*----------------------------------------------------------------------------
 * EAS_GetSynthPolyphony()
 *----------------------------------------------------------------------------
 * Purpose:
 * Returns the current polyphony setting of the synthesizer
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * synthNum         - synthesizer number (0 = onboard, 1 = DSP)
 * pPolyphonyCount  - pointer to variable to receive polyphony count
 *
 * Outputs:
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetSynthPolyphony (EAS_DATA_HANDLE pEASData, EAS_I32 synthNum, EAS_I32 *pPolyphonyCount);

/*----------------------------------------------------------------------------
 * EAS_SetPolyphony()
 *----------------------------------------------------------------------------
 * Purpose:
 * Set the polyphony of the stream. Value must be >= 1 and <= the
 * maximum number of voices. This function will pin the polyphony
 * at those limits
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - handle returned by EAS_OpenFile
 * polyphonyCount   - the desired polyphony count
 *
 * Outputs:
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetPolyphony (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 polyphonyCount);

/*----------------------------------------------------------------------------
 * EAS_GetPolyphony()
 *----------------------------------------------------------------------------
 * Purpose:
 * Returns the current polyphony setting of the stream
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - handle returned by EAS_OpenFile
 * pPolyphonyCount  - pointer to variable to receive polyphony count
 *
 * Outputs:
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetPolyphony (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 *pPolyphonyCount);

/*----------------------------------------------------------------------------
 * EAS_SetPriority()
 *----------------------------------------------------------------------------
 * Purpose:
 * Set the priority of the stream. Determines which stream's voices
 * are stolen when there are insufficient voices for all notes.
 * Value must be in the range of 1-255, lower values are higher
 * priority. The default priority is 50.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - handle returned by EAS_OpenFile
 * polyphonyCount   - the desired polyphony count
 *
 * Outputs:
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetPriority (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 priority);

/*----------------------------------------------------------------------------
 * EAS_GetPriority()
 *----------------------------------------------------------------------------
 * Purpose:
 * Returns the current priority setting of the stream
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - handle returned by EAS_OpenFile
 * pPriority        - pointer to variable to receive priority
 *
 * Outputs:
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetPriority (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 *pPriority);

/*----------------------------------------------------------------------------
 * EAS_SetVolume()
 *----------------------------------------------------------------------------
 * Purpose:
 * Set the master volume for the mixer. The default volume setting is
 * 90 (-10 dB). The volume range is 0 to 100 in 1dB increments.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * volume           - the desired master volume
 *
 * Outputs:
 *
 *
 * Side Effects:
 * overrides any previously set master volume from sysex
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetVolume (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 volume);

/*----------------------------------------------------------------------------
 * EAS_GetVolume()
 *----------------------------------------------------------------------------
 * Purpose:
 * Returns the master volume for the mixer in 1dB increments.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * volume           - the desired master volume
 *
 * Outputs:
 *
 *
 * Side Effects:
 * overrides any previously set master volume from sysex
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_I32 EAS_GetVolume (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle);

/*----------------------------------------------------------------------------
 * EAS_SetMaxLoad()
 *----------------------------------------------------------------------------
 * Purpose:
 * Sets the maximum workload the parsers will do in a single call to
 * EAS_Render. The units are currently arbitrary, but should correlate
 * well to the actual CPU cycles consumed. The primary effect is to
 * reduce the occasional peaks in CPU cycles consumed when parsing
 * dense parts of a MIDI score. Setting maxWorkLoad to zero disables
 * the workload limiting function.
 *
 * Inputs:
 *  pEASData        - handle to data for this instance
 *  maxLoad         - the desired maximum workload
 *
 * Outputs:
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetMaxLoad (EAS_DATA_HANDLE pEASData, EAS_I32 maxLoad);

/*----------------------------------------------------------------------------
 * EAS_SetMaxPCMStreams()
 *----------------------------------------------------------------------------
 * Sets the maximum number of PCM streams allowed in parsers that
 * use PCM streaming.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - handle returned by EAS_OpenFile
 * maxNumStreams    - maximum number of PCM streams
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetMaxPCMStreams (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream, EAS_I32 maxNumStreams);

/*----------------------------------------------------------------------------
 * EAS_OpenFile()
 *----------------------------------------------------------------------------
 * Purpose:
 * Opens a file for audio playback.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * locator          - pointer to filename or other locating information
 * pStreamHandle    - pointer to stream handle variable
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_OpenFile (EAS_DATA_HANDLE pEASData, EAS_FILE_LOCATOR locator, EAS_HANDLE *pStreamHandle);

#ifdef MMAPI_SUPPORT
/*----------------------------------------------------------------------------
 * EAS_MMAPIToneControl()
 *----------------------------------------------------------------------------
 * Purpose:
 * Opens a ToneControl file for audio playback.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * locator          - pointer to filename or other locating information
 * pStreamHandle    - pointer to stream handle variable
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_MMAPIToneControl (EAS_DATA_HANDLE pEASData, EAS_FILE_LOCATOR locator, EAS_HANDLE *pStreamHandle);

/*----------------------------------------------------------------------------
 * EAS_GetWaveFmtChunk
 *----------------------------------------------------------------------------
 * Helper function to retrieve WAVE file fmt chunk for MMAPI
 *----------------------------------------------------------------------------
 * pEASData         - pointer to EAS persistent data object
 * streamHandle     - stream handle
 * pFmtChunk        - pointer to pointer to FMT chunk data
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetWaveFmtChunk (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_VOID_PTR *ppFmtChunk);
#endif

/*----------------------------------------------------------------------------
 * EAS_GetFileType
 *----------------------------------------------------------------------------
 * Returns the file type (see eas_types.h for enumerations)
 *----------------------------------------------------------------------------
 * pEASData         - pointer to EAS persistent data object
 * streamHandle     - stream handle
 * pFileType        - pointer to variable to receive file type
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetFileType (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 *pFileType);

/*----------------------------------------------------------------------------
 * EAS_ParseMetaData()
 *----------------------------------------------------------------------------
 * Purpose:
 *
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 * playLength       - pointer to variable to store the play length (in msecs)
 *
 * Outputs:
 *
 *
 * Side Effects:
 *                  - resets the parser to the start of the file
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_ParseMetaData (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 *pPlayLength);

/*----------------------------------------------------------------------------
 * EAS_Prepare()
 *----------------------------------------------------------------------------
 * Purpose:
 * Prepares the synthesizer to play the file or stream. Parses the first
 * frame of data from the file and arms the synthesizer.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_Prepare (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle);

/*----------------------------------------------------------------------------
 * EAS_State()
 *----------------------------------------------------------------------------
 * Purpose:
 * Returns the state of an audio file or stream.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_State (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_STATE *pState);

/*----------------------------------------------------------------------------
 * EAS_RegisterMetaDataCallback()
 *----------------------------------------------------------------------------
 * Purpose:
 * Registers a metadata callback function for parsed metadata. To
 * de-register the callback, call this function again with parameter
 * cbFunc set to NULL.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 * cbFunc           - pointer to host callback function
 * metaDataBuffer   - pointer to metadata buffer
 * metaDataBufSize  - maximum size of the metadata buffer
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_RegisterMetaDataCallback (
    EAS_DATA_HANDLE pEASData,
    EAS_HANDLE streamHandle,
    EAS_METADATA_CBFUNC cbFunc,
    char *metaDataBuffer,
    EAS_I32 metaDataBufSize,
    EAS_VOID_PTR pUserData);

/*----------------------------------------------------------------------------
 * EAS_GetNoteCount ()
 *----------------------------------------------------------------------------
 * Returns the total number of notes played in this stream
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 * pNoteCount       - pointer to variable to receive note count
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetNoteCount (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream, EAS_I32 *pNoteCount);

/*----------------------------------------------------------------------------
 * EAS_CloseFile()
 *----------------------------------------------------------------------------
 * Purpose:
 * Closes an audio file or stream. Playback should have either paused or
 * completed (EAS_State returns EAS_PAUSED or EAS_STOPPED).
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_CloseFile (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle);

/*----------------------------------------------------------------------------
 * EAS_OpenMIDIStream()
 *----------------------------------------------------------------------------
 * Purpose:
 * Opens a raw MIDI stream allowing the host to route MIDI cable data directly to the synthesizer
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * pStreamHandle    - pointer to variable to hold file or stream handle
 * streamHandle     - open stream or NULL for new synthesizer instance
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_OpenMIDIStream (EAS_DATA_HANDLE pEASData, EAS_HANDLE *pStreamHandle, EAS_HANDLE streamHandle);

/*----------------------------------------------------------------------------
 * EAS_WriteMIDIStream()
 *----------------------------------------------------------------------------
 * Purpose:
 * Send data to the MIDI stream device
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - stream handle
 * pBuffer          - pointer to buffer
 * count            - number of bytes to write
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_WriteMIDIStream(EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_U8 *pBuffer, EAS_I32 count);

/*----------------------------------------------------------------------------
 * EAS_CloseMIDIStream()
 *----------------------------------------------------------------------------
 * Purpose:
 * Closes a raw MIDI stream
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - stream handle
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_CloseMIDIStream (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle);

/*----------------------------------------------------------------------------
 * EAS_Locate()
 *----------------------------------------------------------------------------
 * Purpose:
 * Locate into the file associated with the handle.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file handle
 * milliseconds     - playback offset from start of file in milliseconds
 *
 * Outputs:
 *
 *
 * Side Effects:
 * the actual offset will be quantized to the closest update period, typically
 * a resolution of 5.9ms. Notes that are started prior to this time will not
 * sound. Any notes currently playing will be shut off.
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_Locate (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 milliseconds, EAS_BOOL offset);

/*----------------------------------------------------------------------------
 * EAS_GetRenderTime()
 *----------------------------------------------------------------------------
 * Purpose:
 * Returns the current playback offset
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 *
 * Outputs:
 * Gets the render time clock in msecs.
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetRenderTime (EAS_DATA_HANDLE pEASData, EAS_I32 *pTime);

/*----------------------------------------------------------------------------
 * EAS_GetLocation()
 *----------------------------------------------------------------------------
 * Purpose:
 * Returns the current playback offset
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file handle
 *
 * Outputs:
 * The offset in milliseconds from the start of the current sequence, quantized
 * to the nearest update period. Actual resolution is typically 5.9 ms.
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetLocation (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_I32 *pTime);

/*----------------------------------------------------------------------------
 * EAS_Pause()
 *----------------------------------------------------------------------------
 * Purpose:
 * Pauses the playback of the data associated with this handle. The audio
 * is gracefully ramped down to prevent clicks and pops. It may take several
 * buffers of audio before the audio is muted.
 *
 * Inputs:
 * psEASData        - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_Pause (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle);

/*----------------------------------------------------------------------------
 * EAS_Resume()
 *----------------------------------------------------------------------------
 * Purpose:
 * Resumes the playback of the data associated with this handle. The audio
 * is gracefully ramped up to prevent clicks and pops.
 *
 * Inputs:
 * psEASData        - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_Resume (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle);

/*----------------------------------------------------------------------------
 * EAS_GetParameter()
 *----------------------------------------------------------------------------
 * Purpose:
 * Set the parameter of a module. See E_MODULES for a list of modules
 * and the header files of the modules for a list of parameters.
 *
 * Inputs:
 * psEASData        - pointer to overall EAS data structure
 * module           - enumerated module number
 * param            - enumerated parameter number
 * pValue           - pointer to variable to receive parameter value
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetParameter (EAS_DATA_HANDLE pEASData, EAS_I32 module, EAS_I32 param, EAS_I32 *pValue);

/*----------------------------------------------------------------------------
 * EAS_SetParameter()
 *----------------------------------------------------------------------------
 * Purpose:
 * Set the parameter of a module. See E_MODULES for a list of modules
 * and the header files of the modules for a list of parameters.
 *
 * Inputs:
 * psEASData        - pointer to overall EAS data structure
 * handle           - file or stream handle
 * module           - enumerated module number
 * param            - enumerated parameter number
 * value            - new parameter value
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetParameter (EAS_DATA_HANDLE pEASData, EAS_I32 module, EAS_I32 param, EAS_I32 value);

#ifdef _METRICS_ENABLED
/*----------------------------------------------------------------------------
 * EAS_MetricsReport()
 *----------------------------------------------------------------------------
 * Purpose:
 * Displays the current metrics through the EAS_Report interface.
 *
 * Inputs:
 * pEASData             - instance data handle
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_MetricsReport (EAS_DATA_HANDLE pEASData);

/*----------------------------------------------------------------------------
 * EAS_MetricsReset()
 *----------------------------------------------------------------------------
 * Purpose:
 * Displays the current metrics through the EAS_Report interface.
 *
 * Inputs:
 * pEASData             - instance data handle
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_MetricsReset (EAS_DATA_HANDLE pEASData);
#endif

/*----------------------------------------------------------------------------
 * EAS_SetSoundLibrary()
 *----------------------------------------------------------------------------
 * Purpose:
 * Sets the location of the sound library.
 *
 * Inputs:
 * pEASData             - instance data handle
 * streamHandle         - file or stream handle
 * pSoundLib            - pointer to sound library
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetSoundLibrary (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_SNDLIB_HANDLE pSndLib);

/*----------------------------------------------------------------------------
 * EAS_SetHeaderSearchFlag()
 *----------------------------------------------------------------------------
 * By default, when EAS_OpenFile is called, the parsers check the
 * first few bytes of the file looking for a specific header. Some
 * mobile devices may add a header to the start of a file, which
 * will prevent the parser from recognizing the file. If the
 * searchFlag is set to EAS_TRUE, the parser will search the entire
 * file looking for the header. This may enable EAS to recognize
 * some files that it would ordinarily reject. The negative is that
 * it make take slightly longer to process the EAS_OpenFile request.
 *
 * Inputs:
 * pEASData             - instance data handle
 * searchFlag           - search flag (EAS_TRUE or EAS_FALSE)
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetHeaderSearchFlag (EAS_DATA_HANDLE pEASData, EAS_BOOL searchFlag);

/*----------------------------------------------------------------------------
 * EAS_SetPlayMode()
 *----------------------------------------------------------------------------
 * Some file formats support special play modes, such as iMode partial
 * play mode. This call can be used to change the play mode. The
 * default play mode (usually straight playback) is always zero.
 *
 * Inputs:
 * pEASData             - instance data handle
 * handle               - file or stream handle
 * playMode             - play mode (see eas_types.h for enumerations)
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetPlayMode (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream, EAS_I32 playMode);

#ifdef DLS_SYNTHESIZER
/*----------------------------------------------------------------------------
 * EAS_LoadDLSCollection()
 *----------------------------------------------------------------------------
 * Purpose:
 * Downloads a DLS collection
 *
 * Inputs:
 * pEASData             - instance data handle
 * streamHandle         - file or stream handle
 * locator              - file locator
 *
 * Outputs:
 *
 *
 * Side Effects:
 * May overlay instruments in the GM sound set
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_LoadDLSCollection (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_FILE_LOCATOR locator);
#endif

/*----------------------------------------------------------------------------
 * EAS_SetFrameBuffer()
 *----------------------------------------------------------------------------
 * Purpose:
 * Sets the frame buffer pointer passed to the IPC communications functions
 *
 * Inputs:
 * pEASData             - instance data handle
 * locator              - file locator
 *
 * Outputs:
 *
 *
 * Side Effects:
 * May overlay instruments in the GM sound set
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_SetFrameBuffer (EAS_DATA_HANDLE pEASData, EAS_FRAME_BUFFER_HANDLE pFrameBuffer);

#ifdef EXTERNAL_AUDIO
/*----------------------------------------------------------------------------
 * EAS_RegExtAudioCallback()
 *----------------------------------------------------------------------------
 * Purpose:
 * Registers callback functions for audio events.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 * cbProgChgFunc    - pointer to host callback function for program change
 * cbEventFunc      - pointer to host callback functio for note events
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_RegExtAudioCallback (EAS_DATA_HANDLE pEASData,
    EAS_HANDLE streamHandle,
    EAS_VOID_PTR pInstData,
    EAS_EXT_PRG_CHG_FUNC cbProgChgFunc,
    EAS_EXT_EVENT_FUNC cbEventFunc);

/*----------------------------------------------------------------------------
 * EAS_GetMIDIControllers()
 *----------------------------------------------------------------------------
 * Purpose:
 * Returns the current state of MIDI controllers on the requested channel.
 *
 * Inputs:
 * pEASData         - pointer to overall EAS data structure
 * streamHandle     - file or stream handle
 * pControl         - pointer to structure to receive data
 *
 * Outputs:
 *
 *
 * Side Effects:
 *
 *----------------------------------------------------------------------------
*/
EAS_PUBLIC EAS_RESULT EAS_GetMIDIControllers (EAS_DATA_HANDLE pEASData, EAS_HANDLE streamHandle, EAS_U8 channel, S_MIDI_CONTROLLERS *pControl);
#endif

/*----------------------------------------------------------------------------
 * EAS_SearchFile
 *----------------------------------------------------------------------------
 * Search file for specific sequence starting at current file
 * position. Returns offset to start of sequence.
 *
 * Inputs:
 * pEASData         - pointer to EAS persistent data object
 * fileHandle       - file handle
 * searchString     - pointer to search sequence
 * len              - length of search sequence
 * pOffset          - pointer to variable to store offset to sequence
 *
 * Returns EAS_EOF if end-of-file is reached
 *----------------------------------------------------------------------------
*/
EAS_RESULT EAS_SearchFile (EAS_DATA_HANDLE pEASData, EAS_FILE_HANDLE fileHandle, const EAS_U8 *searchString, EAS_I32 len, EAS_I32 *pOffset);

#ifdef __cplusplus
} /* end extern "C" */
#endif

#endif /* #ifndef _EAS_H */

Added jni/src/eas_reverb.h.













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*----------------------------------------------------------------------------
 *
 * File:
 * eas_reverb.h
 *
 * Contents and purpose:
 * Contains parameter enumerations for the Reverb effect
 *
 *
 * Copyright Sonic Network Inc. 2006

 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *----------------------------------------------------------------------------
 * Revision Control:
 *   $Revision: 300 $
 *   $Date: 2006-09-11 17:37:20 -0700 (Mon, 11 Sep 2006) $
 *----------------------------------------------------------------------------
*/

#ifndef _EAS_REVERB_H
#define _EAS_REVERB_H


/* enumerated parameter settings for Reverb effect */
typedef enum
{
    EAS_PARAM_REVERB_BYPASS,
    EAS_PARAM_REVERB_PRESET,
    EAS_PARAM_REVERB_WET,
    EAS_PARAM_REVERB_DRY
} E_REVERB_PARAMS;


typedef enum
{
    EAS_PARAM_REVERB_LARGE_HALL,
    EAS_PARAM_REVERB_HALL,
    EAS_PARAM_REVERB_CHAMBER,
    EAS_PARAM_REVERB_ROOM,
} E_REVERB_PRESETS;


#endif /* _REVERB_H */

Added jni/src/eas_types.h.

































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*----------------------------------------------------------------------------
 *
 * File:
 * eas_types.h
 *
 * Contents and purpose:
 * The public interface header for the EAS synthesizer.
 *
 * This header only contains declarations that are specific
 * to this implementation.
 *
 * DO NOT MODIFY THIS FILE!
 *
 * Copyright Sonic Network Inc. 2004

 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *----------------------------------------------------------------------------
 * Revision Control:
 *   $Revision: 726 $
 *   $Date: 2007-06-14 23:10:46 -0700 (Thu, 14 Jun 2007) $
 *----------------------------------------------------------------------------
*/

#ifndef _EAS_TYPES_H
#define _EAS_TYPES_H

/* EAS_RESULT return codes */
typedef long EAS_RESULT;
#define EAS_SUCCESS                         0
#define EAS_FAILURE                         -1
#define EAS_ERROR_INVALID_MODULE            -2
#define EAS_ERROR_MALLOC_FAILED             -3
#define EAS_ERROR_FILE_POS                  -4
#define EAS_ERROR_INVALID_FILE_MODE         -5
#define EAS_ERROR_FILE_SEEK                 -6
#define EAS_ERROR_FILE_LENGTH               -7
#define EAS_ERROR_NOT_IMPLEMENTED           -8
#define EAS_ERROR_CLOSE_FAILED              -9
#define EAS_ERROR_FILE_OPEN_FAILED          -10
#define EAS_ERROR_INVALID_HANDLE            -11
#define EAS_ERROR_NO_MIX_BUFFER             -12
#define EAS_ERROR_PARAMETER_RANGE           -13
#define EAS_ERROR_MAX_FILES_OPEN            -14
#define EAS_ERROR_UNRECOGNIZED_FORMAT       -15
#define EAS_BUFFER_SIZE_MISMATCH            -16
#define EAS_ERROR_FILE_FORMAT               -17
#define EAS_ERROR_SMF_NOT_INITIALIZED       -18
#define EAS_ERROR_LOCATE_BEYOND_END         -19
#define EAS_ERROR_INVALID_PCM_TYPE          -20
#define EAS_ERROR_MAX_PCM_STREAMS           -21
#define EAS_ERROR_NO_VOICE_ALLOCATED        -22
#define EAS_ERROR_INVALID_CHANNEL           -23
#define EAS_ERROR_ALREADY_STOPPED           -24
#define EAS_ERROR_FILE_READ_FAILED          -25
#define EAS_ERROR_HANDLE_INTEGRITY          -26
#define EAS_ERROR_MAX_STREAMS_OPEN          -27
#define EAS_ERROR_INVALID_PARAMETER         -28
#define EAS_ERROR_FEATURE_NOT_AVAILABLE     -29
#define EAS_ERROR_SOUND_LIBRARY             -30
#define EAS_ERROR_NOT_VALID_IN_THIS_STATE   -31
#define EAS_ERROR_NO_VIRTUAL_SYNTHESIZER    -32
#define EAS_ERROR_FILE_ALREADY_OPEN         -33
#define EAS_ERROR_FILE_ALREADY_CLOSED       -34
#define EAS_ERROR_INCOMPATIBLE_VERSION      -35
#define EAS_ERROR_QUEUE_IS_FULL             -36
#define EAS_ERROR_QUEUE_IS_EMPTY            -37
#define EAS_ERROR_FEATURE_ALREADY_ACTIVE    -38

/* special return codes */
#define EAS_EOF                             3
#define EAS_STREAM_BUFFERING                4
#define EAS_BUFFER_FULL                     5

/* EAS_STATE return codes */
typedef long EAS_STATE;
typedef enum
{
    EAS_STATE_READY = 0,
    EAS_STATE_PLAY,
    EAS_STATE_STOPPING,
    EAS_STATE_PAUSING,
    EAS_STATE_STOPPED,
    EAS_STATE_PAUSED,
    EAS_STATE_OPEN,
    EAS_STATE_ERROR,
    EAS_STATE_EMPTY
} E_EAS_STATE;

/* constants */
#ifndef EAS_CONST
#define EAS_CONST const
#endif

/* definition for public interface functions */
#ifndef EAS_PUBLIC
#define EAS_PUBLIC
#endif

/* boolean values */
typedef unsigned EAS_BOOL;
typedef unsigned char EAS_BOOL8;

#define EAS_FALSE   0
#define EAS_TRUE    1

/* scalar variable definitions */
typedef unsigned char EAS_U8;
typedef signed char EAS_I8;
typedef char EAS_CHAR;

typedef unsigned short EAS_U16;
typedef short EAS_I16;

typedef unsigned long EAS_U32;
typedef long EAS_I32;

typedef unsigned EAS_UINT;
typedef int EAS_INT;
typedef long EAS_LONG;

/* audio output type */
typedef short EAS_PCM;

/* file open modes */
typedef EAS_I32 EAS_FILE_MODE;
#define EAS_FILE_READ   1
#define EAS_FILE_WRITE  2

/* file locator e.g. filename or memory pointer */
typedef struct s_eas_file_tag {
    void *handle;
    int(*readAt)(void *handle, void *buf, int offset, int size);
    int(*size)(void *handle);
} EAS_FILE, *EAS_FILE_LOCATOR;

/* handle to stream */
typedef struct s_eas_stream_tag *EAS_HANDLE;

/* handle to file */
typedef struct eas_hw_file_tag *EAS_FILE_HANDLE;

/* handle for synthesizer data */
typedef struct s_eas_data_tag *EAS_DATA_HANDLE;

/* handle to persistent data for host wrapper interface */
typedef struct eas_hw_inst_data_tag *EAS_HW_DATA_HANDLE;

/* handle to sound library */
typedef struct s_eas_sndlib_tag *EAS_SNDLIB_HANDLE;
typedef struct s_eas_dls_tag *EAS_DLSLIB_HANDLE;

/* pointer to frame buffer - used in split architecture only */
typedef struct s_eas_frame_buffer_tag *EAS_FRAME_BUFFER_HANDLE;

/* untyped pointer for instance data */
typedef void *EAS_VOID_PTR;

/* inline functions */
#ifndef EAS_INLINE
#if defined (__XCC__)
#define EAS_INLINE __inline__
#elif defined (__GNUC__)
#define EAS_INLINE inline static
#else
#define EAS_INLINE __inline
#endif
#endif

/* define NULL value */
#ifndef NULL
#define NULL 0
#endif

/* metadata types for metadata return codes */
typedef enum
{
    EAS_METADATA_UNKNOWN = 0,
    EAS_METADATA_TITLE,
    EAS_METADATA_AUTHOR,
    EAS_METADATA_COPYRIGHT,
    EAS_METADATA_LYRIC,
    EAS_METADATA_TEXT
} E_EAS_METADATA_TYPE;

/* metadata callback function */
typedef void (*EAS_METADATA_CBFUNC) (E_EAS_METADATA_TYPE metaDataType, char *metaDataBuf, EAS_VOID_PTR pUserData);

/* file types for metadata return codes */
typedef enum
{
    EAS_FILE_UNKNOWN = 0,
    EAS_FILE_SMF0,
    EAS_FILE_SMF1,
    EAS_FILE_SMAF_UNKNOWN,
    EAS_FILE_SMAF_MA2,
    EAS_FILE_SMAF_MA3,
    EAS_FILE_SMAF_MA5,
    EAS_FILE_CMX,
    EAS_FILE_MFI,
    EAS_FILE_OTA,
    EAS_FILE_IMELODY,
    EAS_FILE_RTTTL,
    EAS_FILE_XMF0,
    EAS_FILE_XMF1,
    EAS_FILE_WAVE_PCM,
    EAS_FILE_WAVE_IMA_ADPCM,
    EAS_FILE_MMAPI_TONE_CONTROL
} E_EAS_FILE_TYPE;

/* enumeration for synthesizers */
typedef enum
{
    EAS_MCU_SYNTH = 0,
    EAS_DSP_SYNTH
} E_SYNTHESIZER;

/* external audio callback program change */
typedef struct s_ext_audio_prg_chg_tag
{
    EAS_U16     bank;
    EAS_U8      program;
    EAS_U8      channel;
} S_EXT_AUDIO_PRG_CHG;

/* external audio callback event */
typedef struct s_ext_audio_event_tag
{
    EAS_U8      channel;
    EAS_U8      note;
    EAS_U8      velocity;
    EAS_BOOL8   noteOn;
} S_EXT_AUDIO_EVENT;

typedef struct s_midi_controllers_tag
{
    EAS_U8      modWheel;           /* CC1 */
    EAS_U8      volume;             /* CC7 */
    EAS_U8      pan;                /* CC10 */
    EAS_U8      expression;         /* CC11 */
    EAS_U8      channelPressure;    /* MIDI channel pressure */

#ifdef  _REVERB
    EAS_U8      reverbSend;         /* CC91 */
#endif

#ifdef  _CHORUS
    EAS_U8      chorusSend;         /* CC93 */
#endif
} S_MIDI_CONTROLLERS;

/* iMode play modes enumeration for EAS_SetPlayMode */
typedef enum
{
    IMODE_PLAY_ALL = 0,
    IMODE_PLAY_PARTIAL
} E_I_MODE_PLAY_MODE;

typedef EAS_BOOL (*EAS_EXT_PRG_CHG_FUNC) (EAS_VOID_PTR pInstData, S_EXT_AUDIO_PRG_CHG *pPrgChg);
typedef EAS_BOOL (*EAS_EXT_EVENT_FUNC) (EAS_VOID_PTR pInstData, S_EXT_AUDIO_EVENT *pEvent);

#endif /* #ifndef _EAS_TYPES_H */

Added jni/src/tclMuzic.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
/* 
 *      This file contains the implementation of the "muzic::*" Tcl built-in
 *      commands. These commands deals with MIDI music output.
 *
 * Copyright (C) 2015 Christian Werner <chw@ch-werner.de>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tclInt.h"

#include <dlfcn.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <poll.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <alloca.h>
#include <pthread.h>
#include <jni.h>
#include <android/log.h>

#include "tkBorg.h"

#include "eas.h"
#include "eas_reverb.h"

#ifdef VERBOSE_LOGGING
#define LOG(...) \
    __android_log_print(ANDROID_LOG_VERBOSE,"tclMuzic/C",__VA_ARGS__)
#else
#define LOG(...)
#endif

static pthread_mutex_t init_mut = PTHREAD_MUTEX_INITIALIZER;
static int initialized = 0;
static void *L_SoniVox = NULL;
static jclass C_Muzic = NULL;

typedef struct MIDIMsg {
    struct MIDIMsg *nextPtr;
    unsigned char data[3];
} MIDIMsg;

typedef struct ThreadSpecificData {
    int initialized;			/* True when initialized. */
    int pfd[2];				/* Pipe for IPC with playback side. */
    Tcl_ThreadId tid;			/* Thread for playback. */
    Tcl_Mutex mutex;			/* Mutex for message queue. */
    MIDIMsg *firstMsg, *lastMsg;	/* Message queue, items malloc()'ed. */
    MIDIMsg *freeMsg;			/* Message free list. */
} ThreadSpecificData;

static Tcl_ThreadDataKey dataKey;

typedef struct {
    int initialized;
    EAS_DATA_HANDLE data;
    const S_EAS_LIB_CONFIG *config;
    EAS_HANDLE midi;
    const S_EAS_LIB_CONFIG *(*Config)(void);
    EAS_RESULT (*Init)(EAS_DATA_HANDLE *);
    EAS_RESULT (*Shutdown)(EAS_DATA_HANDLE);
    EAS_RESULT (*Render)(EAS_DATA_HANDLE, EAS_PCM *, EAS_I32, EAS_I32 *);
    EAS_RESULT (*SetParameter)(EAS_DATA_HANDLE, EAS_I32, EAS_I32, EAS_I32);
    EAS_RESULT (*OpenMIDIStream)(EAS_DATA_HANDLE, EAS_HANDLE *, EAS_HANDLE);
    EAS_RESULT (*CloseMIDIStream)(EAS_DATA_HANDLE, EAS_HANDLE);
    EAS_RESULT (*WriteMIDIStream)(EAS_DATA_HANDLE, EAS_HANDLE, EAS_U8 *,
				  EAS_I32);
} EASVec;

static JNIEnv *
GetJNIEnv(void)
{
    JNIEnv *env = Borg_JNIEnv();
    jclass jcls;

    if (env == NULL) {
	return NULL;
    }
    if (!initialized) {
	pthread_mutex_lock(&init_mut);
	if (!initialized) {
	    dlerror();
	    L_SoniVox = dlopen("/system/lib/libsonivox.so", RTLD_NOW);
	    if (L_SoniVox == NULL) {
		LOG("failed to load libsonivox: %s", dlerror());
		goto done;
	    }
	    jcls = (*env)->FindClass(env, "tk/tcl/wish/Muzic");
	    if (jcls != NULL) {
		C_Muzic = (*env)->NewGlobalRef(env, jcls);
		(*env)->DeleteLocalRef(env, jcls);
	    } else {
		LOG("failed to resolve class tk/tcl/wish/Muzic");
	    }
done:
	    initialized = 1;
	}
	pthread_mutex_unlock(&init_mut);
    }
    if ((L_SoniVox == NULL) || (C_Muzic == NULL)) {
	return NULL;
    }
    return env;
}

static void
FinalizeTSD(ClientData clientData)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) clientData;

    Tcl_MutexLock(&tsdPtr->mutex);
    if (tsdPtr->pfd[0] >= 0) {
	close(tsdPtr->pfd[0]);
	tsdPtr->pfd[0] = -1;
    }
    if (tsdPtr->pfd[1] >= 0) {
	close(tsdPtr->pfd[1]);
	tsdPtr->pfd[1] = -1;
    }
    while (tsdPtr->firstMsg != NULL) {
	MIDIMsg *msgPtr = tsdPtr->firstMsg;

	tsdPtr->firstMsg = msgPtr->nextPtr;
	msgPtr->nextPtr = tsdPtr->freeMsg;
	tsdPtr->freeMsg = msgPtr;
    }
    tsdPtr->firstMsg = tsdPtr->lastMsg = NULL;
    while (tsdPtr->freeMsg != NULL) {
	MIDIMsg *msgPtr = tsdPtr->freeMsg;

	tsdPtr->freeMsg = msgPtr->nextPtr;
	free(msgPtr);
    }
    Tcl_MutexUnlock(&tsdPtr->mutex);
    if (tsdPtr->tid != NULL) {
	Tcl_JoinThread(tsdPtr->tid, NULL);
	tsdPtr->tid = NULL;
    }
    Tcl_MutexFinalize(&tsdPtr->mutex);
    tsdPtr->initialized = 0;
}

static ThreadSpecificData *
GetTSD(void)
{
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

    if (!tsdPtr->initialized) {
	tsdPtr->pfd[0] = tsdPtr->pfd[1] = -1;
	tsdPtr->tid = NULL;
        Tcl_CreateThreadExitHandler(FinalizeTSD, tsdPtr);
	Tcl_MutexLock(&tsdPtr->mutex);
	tsdPtr->firstMsg = tsdPtr->lastMsg = NULL;
	tsdPtr->freeMsg = NULL;
	Tcl_MutexUnlock(&tsdPtr->mutex);
        tsdPtr->initialized = 1;
    }
    return tsdPtr;
}

static int
Enqueue(ThreadSpecificData *tsdPtr, char b1, char b2, char b3)
{
    int ret = 0;

    Tcl_MutexLock(&tsdPtr->mutex);
    if (tsdPtr->pfd[1] >= 0) {
	MIDIMsg *msgPtr = tsdPtr->freeMsg;

	if (msgPtr == NULL) {
	    msgPtr = ckalloc(sizeof (MIDIMsg));
	} else {
	    tsdPtr->freeMsg = msgPtr->nextPtr;
	}
	msgPtr->nextPtr = NULL;
	msgPtr->data[0] = b1;
	msgPtr->data[1] = b2;
	msgPtr->data[2] = b3;
	if (tsdPtr->lastMsg != NULL) {
	    tsdPtr->lastMsg->nextPtr = msgPtr;
	    tsdPtr->lastMsg = msgPtr;
	} else {
	    tsdPtr->firstMsg = tsdPtr->lastMsg = msgPtr;
	    send(tsdPtr->pfd[1], "M", 1, MSG_NOSIGNAL);
	}
	ret = 1;
    }
    Tcl_MutexUnlock(&tsdPtr->mutex);
    return ret;
}

static void
TimerHandler(ClientData clientData)
{
    ThreadSpecificData *tsdPtr = GetTSD();
    MIDIMsg *msgPtr = (MIDIMsg *) clientData;

    Tcl_MutexLock(&tsdPtr->mutex);
    if (tsdPtr->pfd[1] >= 0) {
	if (tsdPtr->lastMsg != NULL) {
	    tsdPtr->lastMsg->nextPtr = msgPtr;
	    tsdPtr->lastMsg = msgPtr;
	} else {
	    tsdPtr->firstMsg = tsdPtr->lastMsg = msgPtr;
	    send(tsdPtr->pfd[1], "M", 1, MSG_NOSIGNAL);
	}
    } else {
	msgPtr->nextPtr = tsdPtr->freeMsg;
	tsdPtr->freeMsg = msgPtr;
    }
    Tcl_MutexUnlock(&tsdPtr->mutex);
}

static void
EnqueueAfter(ThreadSpecificData *tsdPtr, char b1, char b2, char b3, int dur)
{
    MIDIMsg *msgPtr = NULL;

    Tcl_MutexLock(&tsdPtr->mutex);
    if (tsdPtr->pfd[1] >= 0) {
	msgPtr = tsdPtr->freeMsg;
	if (msgPtr == NULL) {
	    msgPtr = ckalloc(sizeof (MIDIMsg));
	} else {
	    tsdPtr->freeMsg = msgPtr->nextPtr;
	}
    }
    Tcl_MutexUnlock(&tsdPtr->mutex);
    if (msgPtr != NULL) {
	msgPtr->nextPtr = NULL;
	msgPtr->data[0] = b1;
	msgPtr->data[1] = b2;
	msgPtr->data[2] = b3;
	Tcl_CreateTimerHandler(dur, TimerHandler, (ClientData) msgPtr);
    }
}

static int
EASInit(EASVec *eas)
{
    EAS_RESULT ret;

    memset(eas, 0, sizeof (*eas));
    eas->Config = dlsym(L_SoniVox, "EAS_Config");
    eas->Init = dlsym(L_SoniVox, "EAS_Init");
    eas->Shutdown = dlsym(L_SoniVox, "EAS_Shutdown");
    eas->Render = dlsym(L_SoniVox, "EAS_Render");
    eas->SetParameter = dlsym(L_SoniVox, "EAS_SetParameter");
    eas->OpenMIDIStream = dlsym(L_SoniVox, "EAS_OpenMIDIStream");
    eas->CloseMIDIStream = dlsym(L_SoniVox, "EAS_CloseMIDIStream");
    eas->WriteMIDIStream = dlsym(L_SoniVox, "EAS_WriteMIDIStream");
    if (eas->Config == NULL) {
	return -1;
    }
    eas->config = eas->Config();
    if (eas->config == NULL) {
	return -1;
    }
    if (eas->Init == NULL) {
	return -1;
    }
    ret = eas->Init(&eas->data);
    if (ret != EAS_SUCCESS) {
	return -1;
    }
    if (eas->OpenMIDIStream == NULL) {
	return -1;
    }
    if (eas->SetParameter != NULL) {
	eas->SetParameter(eas->data, EAS_MODULE_REVERB,
			  EAS_PARAM_REVERB_PRESET, EAS_PARAM_REVERB_CHAMBER);
	eas->SetParameter(eas->data, EAS_MODULE_REVERB,
			  EAS_PARAM_REVERB_BYPASS, EAS_FALSE);
    }
    ret = eas->OpenMIDIStream(eas->data, &eas->midi, NULL);
    if (ret != EAS_SUCCESS) {
	if (eas->Shutdown != NULL) {
	    eas->Shutdown(eas->data);
	}
	return -1;
    }
    eas->initialized = 1;
    return 0;
}

static void
EASClose(EASVec *eas)
{
    if (eas->initialized) {
	if ((eas->midi != NULL) && (eas->CloseMIDIStream != NULL)) {
	    eas->CloseMIDIStream(eas->data, eas->midi);
	}
	if ((eas->data != NULL) && (eas->Shutdown != NULL)) {
	    eas->Shutdown(eas->data);
	}
	memset(eas, 0, sizeof (*eas));
    }
}

static void
PlayThread(ClientData clientData)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) clientData;
    JNIEnv *env = GetJNIEnv();
    jmethodID mid;
    jobject jmuzic = NULL;
    EAS_I32 bufSize, count;
    EAS_PCM *buf;
    EASVec eas;

    LOG("PlayThread entry");
    if (env == NULL) {
	goto closeDown0;
    }
    if (EASInit(&eas) < 0) {
	goto closeDown;
    }
    mid = (*env)->GetStaticMethodID(env, C_Muzic,
				    "open", "(III)Ltk/tcl/wish/Muzic;");
    if (mid == NULL) {
	goto closeDown;
    }
    jmuzic = (*env)->CallStaticObjectMethod(env, C_Muzic, mid,
					    eas.config->numChannels,
					    eas.config->sampleRate,
					    eas.config->mixBufferSize);
    if (jmuzic == NULL) {
	goto closeDown;
    }
    bufSize = eas.config->mixBufferSize * eas.config->numChannels * 4;
    buf = (EAS_PCM *) alloca(sizeof (EAS_PCM) * bufSize);
    mid = (*env)->GetMethodID(env, C_Muzic, "write", "([SI)I");
    LOG("PlayThread mainloop");
    while (1) {
	MIDIMsg *msgPtr;

	Tcl_MutexLock(&tsdPtr->mutex);
	if (tsdPtr->pfd[0] < 0) {
	    Tcl_MutexUnlock(&tsdPtr->mutex);
	    break;
	}
	msgPtr = tsdPtr->firstMsg;
	if (msgPtr != NULL) {
	    tsdPtr->firstMsg = tsdPtr->lastMsg = NULL;
	}
	Tcl_MutexUnlock(&tsdPtr->mutex);
	if (msgPtr == NULL) {
	    struct pollfd plfd[1];
	    int ret;

	    plfd[0].fd = tsdPtr->pfd[0];
	    plfd[0].events = POLLHUP | POLLERR | POLLIN | POLLNVAL;
	    plfd[0].revents = 0;
	    ret = poll(plfd, 1, 20);
	    if (ret < 0) {
		break;
	    }
	    Tcl_MutexLock(&tsdPtr->mutex);
	    if (plfd[0].revents & POLLIN) {
		recv(tsdPtr->pfd[0], buf, bufSize, MSG_NOSIGNAL);
	    }
	    msgPtr = tsdPtr->firstMsg;
	    if (msgPtr != NULL) {
		tsdPtr->firstMsg = tsdPtr->lastMsg = NULL;
	    }
	    Tcl_MutexUnlock(&tsdPtr->mutex);
	}
	while (msgPtr != NULL) {
	    MIDIMsg *nextPtr = msgPtr->nextPtr;
	    int len;

	    LOG("PlayThread data %02X %02X %02X",
		msgPtr->data[0], msgPtr->data[1], msgPtr->data[2]);
	    len = (msgPtr->data[0] >= 0xC0) ? 2 : 3;
	    eas.WriteMIDIStream(eas.data, eas.midi, msgPtr->data, len);
	    Tcl_MutexLock(&tsdPtr->mutex);
	    msgPtr->nextPtr = tsdPtr->freeMsg;
	    tsdPtr->freeMsg = msgPtr;
	    Tcl_MutexUnlock(&tsdPtr->mutex);
	    msgPtr = nextPtr;
	}
	count = 0;
	while (count < bufSize) {
	    EAS_I32 nOut;
	    EAS_RESULT result;

	    result = eas.Render(eas.data, buf + count,
				eas.config->mixBufferSize, &nOut);
	    if (result != EAS_SUCCESS) {
		break;
	    }
	    count += nOut * eas.config->numChannels;
	}
	if (count > 0) {
	    jshortArray jbuf = (*env)->NewShortArray(env, count);

	    (*env)->SetShortArrayRegion(env, jbuf, 0, count, buf);
	    (*env)->CallIntMethod(env, jmuzic, mid, jbuf, count);
	    (*env)->DeleteLocalRef(env, jbuf);
	}
    }
    LOG("PlayThread end mainloop");
closeDown:
    LOG("PlayThread closing");
    if (jmuzic != NULL) {
	mid = (*env)->GetMethodID(env, C_Muzic, "close", "()V");
	(*env)->CallVoidMethod(env, jmuzic, mid);
	(*env)->DeleteLocalRef(env, jmuzic);
    }
    EASClose(&eas);
closeDown0:
    if (tsdPtr->initialized) {
	Tcl_MutexLock(&tsdPtr->mutex);
	if (tsdPtr->pfd[0] >= 0) {
	    close(tsdPtr->pfd[0]);
	    tsdPtr->pfd[0] = -1;
	}
	if (tsdPtr->pfd[1] >= 0) {
	    close(tsdPtr->pfd[1]);
	    tsdPtr->pfd[1] = -1;
	}
	while (tsdPtr->firstMsg != NULL) {
	    MIDIMsg *msgPtr = tsdPtr->firstMsg;

	    tsdPtr->firstMsg = msgPtr->nextPtr;
	    msgPtr->nextPtr = tsdPtr->freeMsg;
	    tsdPtr->freeMsg = msgPtr;
	}
	tsdPtr->firstMsg = tsdPtr->lastMsg = NULL;
	Tcl_MutexUnlock(&tsdPtr->mutex);
    }
    LOG("PlayThread finished");
    Borg_JNIFin();
}

static int
MuzicInitObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
		Tcl_Obj *const objv[])
{
    ThreadSpecificData *tsdPtr = GetTSD();
    char *name = NULL;
    int retval = 0;

    if (objc > 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "?settings?");
	return TCL_ERROR;
    }
    Tcl_MutexLock(&tsdPtr->mutex);
    if (tsdPtr->pfd[0] < 0) {
	socketpair(AF_LOCAL, SOCK_STREAM, 0, tsdPtr->pfd);
	if (tsdPtr->pfd[0] > -1) {
	    fcntl(tsdPtr->pfd[0], F_SETFD, FD_CLOEXEC);
	    fcntl(tsdPtr->pfd[0], F_SETFL, O_NONBLOCK);
	    fcntl(tsdPtr->pfd[1], F_SETFD, FD_CLOEXEC);
	    fcntl(tsdPtr->pfd[1], F_SETFL, O_NONBLOCK);
            if (TclpThreadCreate(&tsdPtr->tid, PlayThread, tsdPtr,
				 TCL_THREAD_STACK_DEFAULT,
				 TCL_THREAD_JOINABLE) == TCL_OK) {
		retval = 1;
	    } else {
		close(tsdPtr->pfd[0]);
		close(tsdPtr->pfd[1]);
		tsdPtr->pfd[0] = tsdPtr->pfd[1] = -1;
		tsdPtr->tid = NULL;
	    }
	}
    }
    Tcl_MutexUnlock(&tsdPtr->mutex);
    Tcl_SetObjResult(interp, Tcl_NewIntObj(retval));
    return TCL_OK;
}

static int
MuzicSoundFontObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
		     Tcl_Obj *const objv[])
{
    ThreadSpecificData *tsdPtr = GetTSD();
    char *name = NULL;
    int retval = 0;

    if (objc > 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "?fontname?");
	return TCL_ERROR;
    }
    if (objc > 1) {
	name = Tcl_GetString(objv[1]);
    }
    if ((name == NULL) || (name[0] == '\0') || (strcmp(name, "builtin") == 0)) {
	retval = 1;
    }
    Tcl_SetObjResult(interp, Tcl_NewIntObj(retval));
    return TCL_OK;
}

static int
MuzicPlaynoteObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
		    Tcl_Obj *const objv[])
{
    ThreadSpecificData *tsdPtr = GetTSD();
    int channel, pitch, velocity, duration = 500, retval = 0;

    if (objc < 4 || objc > 5) {
	Tcl_WrongNumArgs(interp, 1, objv, "channel pitch velocity ?duration?");
	return TCL_ERROR;
    }
    if (Tcl_GetIntFromObj(interp, objv[1], &channel) != TCL_OK) {
	return TCL_ERROR;
    }
    if (Tcl_GetIntFromObj(interp, objv[2], &pitch) != TCL_OK) {
	return TCL_ERROR;
    }
    if (Tcl_GetIntFromObj(interp, objv[3], &velocity) != TCL_OK) {
	return TCL_ERROR;
    }
    if ((objc > 4) &&
	(Tcl_GetIntFromObj(interp, objv[4], &duration) != TCL_OK)) {
	return TCL_ERROR;
    }
    velocity = velocity * 127 / 100;
    if (velocity < 0) {
	velocity = 0;
    }
    if (duration < 0) {
	duration = 0;
    }
    if (channel >= 0 && channel <= 15) {
	channel |= 0x90;
	retval = Enqueue(tsdPtr, channel, pitch, velocity);
	if ((retval != 0) && (velocity != 0)) {
	    EnqueueAfter(tsdPtr, channel, pitch, 0, duration);
	}
    }
    Tcl_SetObjResult(interp, Tcl_NewIntObj(retval));
    return TCL_OK;
}

static int
MuzicChannelObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
		   Tcl_Obj *const objv[])
{
    ThreadSpecificData *tsdPtr = GetTSD();
    int channel, instrument, retval = 0;

    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "channel instrument");
	return TCL_ERROR;
    }
    if (Tcl_GetIntFromObj(interp, objv[1], &channel) != TCL_OK) {
	return TCL_ERROR;
    }
    if (Tcl_GetIntFromObj(interp, objv[2], &instrument) != TCL_OK) {
	return TCL_ERROR;
    }
    if (channel >= 0 && channel <= 31) {
	channel |= 0xC0;
	retval = Enqueue(tsdPtr, channel, instrument, 0);
    }
    Tcl_SetObjResult(interp, Tcl_NewIntObj(retval));
    return TCL_OK;
}

static int
MuzicCloseObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
		 Tcl_Obj *const objv[])
{
    ThreadSpecificData *tsdPtr = GetTSD();

    if (objc != 1) {
	Tcl_WrongNumArgs(interp, 1, objv, "");
	return TCL_ERROR;
    }
    Tcl_MutexLock(&tsdPtr->mutex);
    if (tsdPtr->pfd[0] >= 0) {
	close(tsdPtr->pfd[0]);
	tsdPtr->pfd[0] = -1;
    }
    if (tsdPtr->pfd[1] >= 0) {
	close(tsdPtr->pfd[1]);
	tsdPtr->pfd[1] = -1;
    }
    while (tsdPtr->firstMsg != NULL) {
	MIDIMsg *msgPtr = tsdPtr->firstMsg;

	tsdPtr->firstMsg = msgPtr->nextPtr;
	msgPtr->nextPtr = tsdPtr->freeMsg;
	tsdPtr->freeMsg = msgPtr;
    }
    tsdPtr->firstMsg = tsdPtr->lastMsg = NULL;
    Tcl_MutexUnlock(&tsdPtr->mutex);
    if (tsdPtr->tid != NULL) {
	Tcl_JoinThread(tsdPtr->tid, NULL);
	tsdPtr->tid = NULL;
    }
}

int
Muzic_Init(Tcl_Interp *interp)
{
    JNIEnv *env = GetJNIEnv();

    if (Tcl_CreateObjCommand(interp, "muzic::init", MuzicInitObjCmd,
	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL) == NULL) {
	return TCL_ERROR;
    }
    if (Tcl_CreateObjCommand(interp, "muzic::soundfont", MuzicSoundFontObjCmd,
	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL) == NULL) {
	return TCL_ERROR;
    }
    if (Tcl_CreateObjCommand(interp, "muzic::playnote", MuzicPlaynoteObjCmd,
	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL) == NULL) {
	return TCL_ERROR;
    }
    if (Tcl_CreateObjCommand(interp, "muzic::channel", MuzicChannelObjCmd,
	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL) == NULL) {
	return TCL_ERROR;
    }
    if (Tcl_CreateObjCommand(interp, "muzic::close", MuzicCloseObjCmd,
	    (ClientData) 0, (Tcl_CmdDeleteProc *) NULL) == NULL) {
	return TCL_ERROR;
    }
    Tcl_SetVar(interp, "::muzic::builtin", "1", TCL_GLOBAL_ONLY);
    Tcl_PkgProvide(interp, "muzic", "1.0");
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * tab-width: 8
 * End:
 */

Added jni/src/tclMuzic.h.





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * tclMuzic.h --
 *
 *      This header file contains the visible interface of the "muzic::*"
 *      Tcl built-in commands to deal with MIDI playback.
 *
 * Copyright (c) 2015 Christian Werner <chw@ch-werner.de>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#ifndef _TCLMUZIC_H_
#define _TCLMUZIC_H_

EXTERN int	Muzic_Init(Tcl_Interp *interp);

#endif

Changes to jni/src/tkAppInit.c.

19
20
21
22
23
24
25

26
27
28
29
30
31
32
#ifdef ANDROID
#include <time.h>
#include <sys/system_properties.h>
#include <jni.h>
#include "tclRfcomm.h"
#include "tclUsbserial.h"
#include "tclBLE.h"

#include "tkBorg.h"
#endif

#ifdef TK_TEST
extern Tcl_PackageInitProc Tktest_Init;
#endif /* TK_TEST */








>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifdef ANDROID
#include <time.h>
#include <sys/system_properties.h>
#include <jni.h>
#include "tclRfcomm.h"
#include "tclUsbserial.h"
#include "tclBLE.h"
#include "tclMuzic.h"
#include "tkBorg.h"
#endif

#ifdef TK_TEST
extern Tcl_PackageInitProc Tktest_Init;
#endif /* TK_TEST */

476
477
478
479
480
481
482



483
484
485
486
487

488
489
490
491
492
493
494
	return TCL_ERROR;
    }
    if (Usbserial_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    if (Ble_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;



    }
    Tcl_StaticPackage(interp, "borg", Borg_Init, NULL);
    Tcl_StaticPackage(interp, "rfcomm", Rfcomm_Init, NULL);
    Tcl_StaticPackage(interp, "usbserial", Usbserial_Init, NULL);
    Tcl_StaticPackage(interp, "ble", Ble_Init, NULL);

#endif

#ifdef PLATFORM_SDL
    if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
#endif







>
>
>





>







477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
	return TCL_ERROR;
    }
    if (Usbserial_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    if (Ble_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    if (Muzic_Init(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
    Tcl_StaticPackage(interp, "borg", Borg_Init, NULL);
    Tcl_StaticPackage(interp, "rfcomm", Rfcomm_Init, NULL);
    Tcl_StaticPackage(interp, "usbserial", Usbserial_Init, NULL);
    Tcl_StaticPackage(interp, "ble", Ble_Init, NULL);
    Tcl_StaticPackage(interp, "muzic", Muzic_Init, NULL);
#endif

#ifdef PLATFORM_SDL
    if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }
#endif

Changes to jni/src/tkBorg.c.

4278
4279
4280
4281
4282
4283
4284








4285
4286
4287
4288
4289
4290
4291
}

JNIEnv *
Borg_JNIEnv(void)
{
    return GetJNIEnv();
}









jclass *
Borg_Activity(void)
{
    if (GetJNIEnv() != NULL) {
	return jactivity;
    }







>
>
>
>
>
>
>
>







4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
}

JNIEnv *
Borg_JNIEnv(void)
{
    return GetJNIEnv();
}

void
Borg_JNIFin(void)
{
    if (jvm != NULL) {
	(*jvm)->DetachCurrentThread(jvm);
    }
}

jclass *
Borg_Activity(void)
{
    if (GetJNIEnv() != NULL) {
	return jactivity;
    }

Changes to jni/src/tkBorg.h.

12
13
14
15
16
17
18

19
20
21
22

#ifndef _TKBORG_H_
#define _TKBORG_H_

#include <jni.h>

EXTERN JNIEnv  *Borg_JNIEnv(void);

EXTERN jclass  *Borg_Activity(void);
EXTERN int	Borg_Init(Tcl_Interp *interp);

#endif







>




12
13
14
15
16
17
18
19
20
21
22
23

#ifndef _TKBORG_H_
#define _TKBORG_H_

#include <jni.h>

EXTERN JNIEnv  *Borg_JNIEnv(void);
EXTERN void     Borg_JNIFin(void);
EXTERN jclass  *Borg_Activity(void);
EXTERN int	Borg_Init(Tcl_Interp *interp);

#endif

jni/tcl/library/tzdata/Africa/Asmara became a regular file.

jni/tcl/library/tzdata/Europe/Volgograd became a regular file.

jni/tcl/unix/configure.in became a regular file.

jni/tcl/win/tclWinFile.c became executable.

jni/tkimg/ico/configure became executable.

jni/tkimg/png/configure became executable.

jni/tkimg/tiff/configure became executable.

Added src/tk/tcl/wish/Muzic.java.



















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * Muzic.java --
 *
 *	Audio interface class for MIDI playback.
 *
 * Copyright (c) 2015 Christian Werner <chw@ch-werner.de>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

package tk.tcl.wish;

import java.io.*;
import java.nio.*;
import android.os.*;
import android.util.*;
import android.media.*;

public class Muzic {

    static final String TAG = "tclMuzic";

    AudioTrack mOut;

    public Muzic(AudioTrack out) {
	mOut = out;
    }

    public static Muzic open(int nChan, int rate, int bufSize) {
	int conf = (nChan > 1) ? 0x000C : 0x0004;
	int n = AudioTrack.getMinBufferSize(rate, conf,
					    AudioFormat.ENCODING_PCM_16BIT);
	Log.v(TAG, "channels: " + nChan);
	Log.v(TAG, "sample rate: " + rate);
	Log.v(TAG, "midi bufsize: " + bufSize);
	Log.v(TAG, "play bufsize: " + n);
	if (n <= 0) {
	    return null;
	}
	AudioTrack out = new AudioTrack(AudioManager.STREAM_MUSIC,
					rate, conf,
					AudioFormat.ENCODING_PCM_16BIT,
					n * 8,
					AudioTrack.MODE_STREAM);
	if (out.getState() != AudioTrack.STATE_INITIALIZED) {
	    Log.e(TAG, "play not in STATE_INITIALIZED");
	    out = null;
	    return null;
	}
	android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
	return new Muzic(out);
    }

    public void close() {
	Log.v(TAG, "close");
	mOut.pause();
	mOut.flush();
	mOut.release();
	mOut = null;
    }

    public int write(short[] buffer, int count) {
	if (mOut == null) {
	    return -1;
	}
	if (mOut.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) {
	    mOut.play();
	}
	return mOut.write(buffer, 0, count);
    }

}

Added tcltkapplib/src/tk/tcl/wish/Muzic.java.



















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * Muzic.java --
 *
 *	Audio interface class for MIDI playback.
 *
 * Copyright (c) 2015 Christian Werner <chw@ch-werner.de>
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

package tk.tcl.wish;

import java.io.*;
import java.nio.*;
import android.os.*;
import android.util.*;
import android.media.*;

public class Muzic {

    static final String TAG = "tclMuzic";

    AudioTrack mOut;

    public Muzic(AudioTrack out) {
	mOut = out;
    }

    public static Muzic open(int nChan, int rate, int bufSize) {
	int conf = (nChan > 1) ? 0x000C : 0x0004;
	int n = AudioTrack.getMinBufferSize(rate, conf,
					    AudioFormat.ENCODING_PCM_16BIT);
	Log.v(TAG, "channels: " + nChan);
	Log.v(TAG, "sample rate: " + rate);
	Log.v(TAG, "midi bufsize: " + bufSize);
	Log.v(TAG, "play bufsize: " + n);
	if (n <= 0) {
	    return null;
	}
	AudioTrack out = new AudioTrack(AudioManager.STREAM_MUSIC,
					rate, conf,
					AudioFormat.ENCODING_PCM_16BIT,
					n * 8,
					AudioTrack.MODE_STREAM);
	if (out.getState() != AudioTrack.STATE_INITIALIZED) {
	    Log.e(TAG, "play not in STATE_INITIALIZED");
	    out = null;
	    return null;
	}
	android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
	return new Muzic(out);
    }

    public void close() {
	Log.v(TAG, "close");
	mOut.pause();
	mOut.flush();
	mOut.release();
	mOut = null;
    }

    public int write(short[] buffer, int count) {
	if (mOut == null) {
	    return -1;
	}
	if (mOut.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) {
	    mOut.play();
	}
	return mOut.write(buffer, 0, count);
    }

}

Changes to tkchat/libs/tcltkapplib.jar.

cannot compute difference between binary files