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
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
|
-- Programmed by Jedidiah Barber
-- Released into the public domain
with
Ada.Assertions,
Ada.Strings.Fixed,
Interfaces.C.Strings,
System;
use type
Interfaces.C.int,
Interfaces.Unsigned_32;
package body Libsndfile.Commands is
------------------------
-- Constants From C --
------------------------
sfc_get_lib_version : constant Interfaces.C.int;
pragma Import (C, sfc_get_lib_version, "sfc_get_lib_version");
sfc_get_log_info : constant Interfaces.C.int;
pragma Import (C, sfc_get_log_info, "sfc_get_log_info");
sfc_calc_signal_max : constant Interfaces.C.int;
pragma Import (C, sfc_calc_signal_max, "sfc_calc_signal_max");
sfc_calc_norm_signal_max : constant Interfaces.C.int;
pragma Import (C, sfc_calc_norm_signal_max, "sfc_calc_norm_signal_max");
sfc_calc_max_all_channels : constant Interfaces.C.int;
pragma Import (C, sfc_calc_max_all_channels, "sfc_calc_max_all_channels");
sfc_calc_norm_max_all_channels : constant Interfaces.C.int;
pragma Import (C, sfc_calc_norm_max_all_channels, "sfc_calc_norm_max_all_channels");
sfc_get_signal_max : constant Interfaces.C.int;
pragma Import (C, sfc_get_signal_max, "sfc_get_signal_max");
sfc_get_max_all_channels : constant Interfaces.C.int;
pragma Import (C, sfc_get_max_all_channels, "sfc_get_max_all_channels");
sfc_set_norm_float : constant Interfaces.C.int;
pragma Import (C, sfc_set_norm_float, "sfc_set_norm_float");
sfc_set_norm_double : constant Interfaces.C.int;
pragma Import (C, sfc_set_norm_double, "sfc_set_norm_double");
sfc_get_norm_float : constant Interfaces.C.int;
pragma Import (C, sfc_get_norm_float, "sfc_get_norm_float");
sfc_get_norm_double : constant Interfaces.C.int;
pragma Import (C, sfc_get_norm_double, "sfc_get_norm_double");
sfc_set_scale_float_int_read : constant Interfaces.C.int;
pragma Import (C, sfc_set_scale_float_int_read, "sfc_set_scale_float_int_read");
sfc_set_scale_int_float_write : constant Interfaces.C.int;
pragma Import (C, sfc_set_scale_int_float_write, "sfc_set_scale_int_float_write");
sfc_get_simple_format_count : constant Interfaces.C.int;
pragma Import (C, sfc_get_simple_format_count, "sfc_get_simple_format_count");
sfc_get_simple_format : constant Interfaces.C.int;
pragma Import (C, sfc_get_simple_format, "sfc_get_simple_format");
sfc_get_format_info : constant Interfaces.C.int;
pragma Import (C, sfc_get_format_info, "sfc_get_format_info");
sfc_get_format_major_count : constant Interfaces.C.int;
pragma Import (C, sfc_get_format_major_count, "sfc_get_format_major_count");
sfc_get_format_major : constant Interfaces.C.int;
pragma Import (C, sfc_get_format_major, "sfc_get_format_major");
sfc_get_format_subtype_count : constant Interfaces.C.int;
pragma Import (C, sfc_get_format_subtype_count, "sfc_get_format_subtype_count");
sfc_get_format_subtype : constant Interfaces.C.int;
pragma Import (C, sfc_get_format_subtype, "sfc_get_format_subtype");
sfc_set_add_peak_chunk : constant Interfaces.C.int;
pragma Import (C, sfc_set_add_peak_chunk, "sfc_set_add_peak_chunk");
sfc_update_header_now : constant Interfaces.C.int;
pragma Import (C, sfc_update_header_now, "sfc_update_header_now");
sfc_set_update_header_auto : constant Interfaces.C.int;
pragma Import (C, sfc_set_update_header_auto, "sfc_set_update_header_auto");
sfc_set_clipping : constant Interfaces.C.int;
pragma Import (C, sfc_set_clipping, "sfc_set_clipping");
sfc_get_clipping : constant Interfaces.C.int;
pragma Import (C, sfc_get_clipping, "sfc_get_clipping");
sfc_wavex_get_ambisonic : constant Interfaces.C.int;
pragma Import (C, sfc_wavex_get_ambisonic, "sfc_wavex_get_ambisonic");
sfc_wavex_set_ambisonic : constant Interfaces.C.int;
pragma Import (C, sfc_wavex_set_ambisonic, "sfc_wavex_set_ambisonic");
sfc_set_vbr_encoding_quality : constant Interfaces.C.int;
pragma Import (C, sfc_set_vbr_encoding_quality, "sfc_set_vbr_encoding_quality");
sfc_set_ogg_page_latency_ms : constant Interfaces.C.int;
pragma Import (C, sfc_set_ogg_page_latency_ms, "sfc_set_ogg_page_latency_ms");
sfc_get_ogg_stream_serialno : constant Interfaces.C.int;
pragma Import (C, sfc_get_ogg_stream_serialno, "sfc_get_ogg_stream_serialno");
sfc_set_compression_level : constant Interfaces.C.int;
pragma Import (C, sfc_set_compression_level, "sfc_set_compression_level");
sfc_raw_data_needs_endswap : constant Interfaces.C.int;
pragma Import (C, sfc_raw_data_needs_endswap, "sfc_raw_data_needs_endswap");
sfc_get_broadcast_info : constant Interfaces.C.int;
pragma Import (C, sfc_get_broadcast_info, "sfc_get_broadcast_info");
sfc_set_broadcast_info : constant Interfaces.C.int;
pragma Import (C, sfc_set_broadcast_info, "sfc_set_broadcast_info");
sfc_get_channel_map_info : constant Interfaces.C.int;
pragma Import (C, sfc_get_channel_map_info, "sfc_get_channel_map_info");
sfc_set_channel_map_info : constant Interfaces.C.int;
pragma Import (C, sfc_set_channel_map_info, "sfc_set_channel_map_info");
-- ...
sfc_get_cue_count : constant Interfaces.C.int;
pragma Import (C, sfc_get_cue_count, "sfc_get_cue_count");
-- ...
sfc_rf64_auto_downgrade : constant Interfaces.C.int;
pragma Import (C, sfc_rf64_auto_downgrade, "sfc_rf64_auto_downgrade");
sfc_get_original_samplerate : constant Interfaces.C.int;
pragma Import (C, sfc_get_original_samplerate, "sfc_get_original_samplerate");
sfc_set_original_samplerate : constant Interfaces.C.int;
pragma Import (C, sfc_set_original_samplerate, "sfc_set_original_samplerate");
sfc_get_bitrate_mode : constant Interfaces.C.int;
pragma Import (C, sfc_get_bitrate_mode, "sfc_get_bitrate_mode");
sfc_set_bitrate_mode : constant Interfaces.C.int;
pragma Import (C, sfc_set_bitrate_mode, "sfc_set_bitrate_mode");
sf_ambisonic_none : constant Interfaces.C.int;
pragma Import (C, sf_ambisonic_none, "sf_ambisonic_none");
sf_ambisonic_b_format : constant Interfaces.C.int;
pragma Import (C, sf_ambisonic_b_format, "sf_ambisonic_b_format");
sf_bitrate_mode_constant : constant Interfaces.C.int;
pragma Import (C, sf_bitrate_mode_constant, "sf_bitrate_mode_constant");
sf_bitrate_mode_average : constant Interfaces.C.int;
pragma Import (C, sf_bitrate_mode_average, "sf_bitrate_mode_average");
sf_bitrate_mode_variable : constant Interfaces.C.int;
pragma Import (C, sf_bitrate_mode_variable, "sf_bitrate_mode_variable");
sf_format_typemask : constant Interfaces.Unsigned_32;
pragma Import (C, sf_format_typemask, "sf_format_typemask");
sf_format_submask : constant Interfaces.Unsigned_32;
pragma Import (C, sf_format_submask, "sf_format_submask");
sf_format_endmask : constant Interfaces.Unsigned_32;
pragma Import (C, sf_format_endmask, "sf_format_endmask");
------------------------
-- Functions From C --
------------------------
function sf_command
(File : in System.Address;
Cmd : in Interfaces.C.int;
Data : in System.Address;
Size : in Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, sf_command, "sf_command");
function asfc_get_current_sf_info
(File : in System.Address;
Info : out File_Info)
return Interfaces.C.int;
pragma Import (C, asfc_get_current_sf_info, "asfc_get_current_sf_info");
function asfc_file_truncate
(File : in System.Address;
Pos : in Interfaces.Integer_64)
return Interfaces.C.int;
pragma Import (C, asfc_file_truncate, "asfc_file_truncate");
function asfc_set_raw_start_offset
(File : in System.Address;
Pos : in Interfaces.Integer_64)
return Interfaces.C.int;
pragma Import (C, asfc_set_raw_start_offset, "asfc_set_raw_start_offset");
function asfc_get_embed_file_info
(File : in System.Address;
Info : in out Embedded_Info)
return Interfaces.C.int;
pragma Import (C, asfc_get_embed_file_info, "asfc_get_embed_file_info");
----------------------------------
-- Data Structure Subprograms --
----------------------------------
function Major
(Info : in Format_Info)
return Major_Format
is
Raw : Interfaces.Unsigned_32 :=
Interfaces.Unsigned_32 (Info.My_Format) and sf_format_typemask;
begin
return To_Major (Interfaces.C.int (Raw));
end Major;
function Minor
(Info : in Format_Info)
return Minor_Format
is
Raw : Interfaces.Unsigned_32 :=
Interfaces.Unsigned_32 (Info.My_Format) and sf_format_submask;
begin
return To_Minor (Interfaces.C.int (Raw));
end Minor;
function Endian
(Info : in Format_Info)
return Endianness
is
Raw : Interfaces.Unsigned_32 :=
Interfaces.Unsigned_32 (Info.My_Format) and sf_format_endmask;
begin
return To_Endian (Interfaces.C.int (Raw));
end Endian;
function Name
(Info : in Format_Info)
return String is
begin
return Interfaces.C.Strings.Value (Info.My_Name);
end Name;
function Extension
(Info : in Format_Info)
return String is
begin
return Interfaces.C.Strings.Value (Info.My_Extension);
end Extension;
function Offset
(Info : in Embedded_Info)
return Count_Type is
begin
return Count_Type (Info.My_Offset);
end Offset;
function Length
(Info : in Embedded_Info)
return Count_Type is
begin
return Count_Type (Info.My_Length);
end Length;
function Create
(Description : in String;
Originator : in String;
Originator_Reference : in String;
Origination_Date : in String;
Origination_Time : in String;
Time_Reference_Low : in Interfaces.Unsigned_32;
Time_Reference_High : in Interfaces.Unsigned_32;
Version : in Short_Integer;
Umid : in String;
Reserved : in String;
Coding_History_Size : in Interfaces.Unsigned_32;
Coding_History : in String)
return Broadcast_Info
is
Buffer : String (1 .. 256);
function Pad
(Input : in String;
Size : in Natural)
return String is
begin
Ada.Strings.Fixed.Move (Source => Input, Target => Buffer, Pad => Character'Val (0));
return Buffer (1 .. Size);
end Pad;
begin
return
(My_Description => Interfaces.C.To_C (Pad (Description, 256), False),
My_Originator => Interfaces.C.To_C (Pad (Originator, 32), False),
My_Originator_Reference => Interfaces.C.To_C (Pad (Originator_Reference, 32), False),
My_Origination_Date => Interfaces.C.To_C (Pad (Origination_Date, 10), False),
My_Origination_Time => Interfaces.C.To_C (Pad (Origination_Time, 8), False),
My_Time_Reference_Low => Interfaces.C.unsigned (Time_Reference_Low),
My_Time_Reference_High => Interfaces.C.unsigned (Time_Reference_High),
My_Version => Interfaces.C.short (Version),
My_Umid => Interfaces.C.To_C (Pad (Umid, 64), False),
My_Reserved => Interfaces.C.To_C (Pad (Reserved, 190), False),
My_Coding_History_Size => Interfaces.C.unsigned (Coding_History_Size),
My_Coding_History => Interfaces.C.To_C (Pad (Coding_History, 256), False));
end Create;
function Description
(Info : in Broadcast_Info)
return String is
begin
return Interfaces.C.To_Ada
(Info.My_Description,
Interfaces.C.Is_Nul_Terminated (Info.My_Description));
end Description;
function Originator
(Info : in Broadcast_Info)
return String is
begin
return Interfaces.C.To_Ada
(Info.My_Originator,
Interfaces.C.Is_Nul_Terminated (Info.My_Originator));
end Originator;
function Originator_Reference
(Info : in Broadcast_Info)
return String is
begin
return Interfaces.C.To_Ada
(Info.My_Originator_Reference,
Interfaces.C.Is_Nul_Terminated (Info.My_Originator_Reference));
end Originator_Reference;
function Origination_Date
(Info : in Broadcast_Info)
return String is
begin
return Interfaces.C.To_Ada
(Info.My_Origination_Date,
Interfaces.C.Is_Nul_Terminated (Info.My_Origination_Date));
end Origination_Date;
function Origination_Time
(Info : in Broadcast_Info)
return String is
begin
return Interfaces.C.To_Ada
(Info.My_Origination_Time,
Interfaces.C.Is_Nul_Terminated (Info.My_Origination_Time));
end Origination_Time;
function Time_Reference_Low
(Info : in Broadcast_Info)
return Interfaces.Unsigned_32 is
begin
return Interfaces.Unsigned_32 (Info.My_Time_Reference_Low);
end Time_Reference_Low;
function Time_Reference_High
(Info : in Broadcast_Info)
return Interfaces.Unsigned_32 is
begin
return Interfaces.Unsigned_32 (Info.My_Time_Reference_High);
end Time_Reference_High;
function Version
(Info : in Broadcast_Info)
return Short_Integer is
begin
return Short_Integer (Info.My_Version);
end Version;
function Umid
(Info : in Broadcast_Info)
return String is
begin
return Interfaces.C.To_Ada
(Info.My_Umid,
Interfaces.C.Is_Nul_Terminated (Info.My_Umid));
end Umid;
function Reserved
(Info : in Broadcast_Info)
return String is
begin
return Interfaces.C.To_Ada
(Info.My_Reserved,
Interfaces.C.Is_Nul_Terminated (Info.My_Reserved));
end Reserved;
function Coding_History_Size
(Info : in Broadcast_Info)
return Interfaces.Unsigned_32 is
begin
return Interfaces.Unsigned_32 (Info.My_Coding_History_Size);
end Coding_History_Size;
function Coding_History
(Info : in Broadcast_Info)
return String is
begin
return Interfaces.C.To_Ada
(Info.My_Coding_History,
Interfaces.C.Is_Nul_Terminated (Info.My_Coding_History));
end Coding_History;
---------------------
-- API Interface --
---------------------
function Get_Library_String
(Buffer : out String)
return Natural is
begin
return Natural (sf_command
(System.Null_Address,
sfc_get_lib_version,
Buffer'Address,
Buffer'Length));
end Get_Library_String;
function Get_Log_Info
(File : in Sound_File;
Buffer : out String)
return Natural is
begin
return Natural (sf_command
(File.Ptr,
sfc_get_log_info,
Buffer'Address,
Buffer'Length));
end Get_Log_Info;
function Get_Current_File_Info
(File : in Sound_File)
return File_Info
is
Result : File_Info;
Code : Interfaces.C.int;
begin
Code := asfc_get_current_sf_info (File.Ptr, Result);
if Code /= 0 then
Raise_Error (Code);
raise Program_Error;
else
return Result;
end if;
end Get_Current_File_Info;
function Calculate_Signal_Maximum
(File : in Sound_File)
return Long_Float
is
Result : Interfaces.C.double;
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_calc_signal_max,
Result'Address,
Interfaces.C.double'Size / Interfaces.C.CHAR_BIT);
if Code /= 0 then
Raise_Error (Code);
raise Program_Error;
else
return Long_Float (Result);
end if;
end Calculate_Signal_Maximum;
function Calculate_Normed_Signal_Maximum
(File : in Sound_File)
return Long_Float
is
Result : Interfaces.C.double;
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_calc_norm_signal_max,
Result'Address,
Interfaces.C.double'Size / Interfaces.C.CHAR_BIT);
if Code /= 0 then
Raise_Error (Code);
raise Program_Error;
else
return Long_Float (Result);
end if;
end Calculate_Normed_Signal_Maximum;
function Calculate_Maximum_All_Channels
(File : in Sound_File)
return Long_Float_Array
is
Result : Long_Float_Array (1 .. Natural (File.Chans));
Code : Interfaces.C.int;
begin
Ada.Assertions.Assert (Long_Float'Size = Interfaces.C.double'Size);
Code := sf_command
(File.Ptr,
sfc_calc_max_all_channels,
Result'Address,
Interfaces.C.double'Size / Interfaces.C.CHAR_BIT * File.Chans);
if Code /= 0 then
Raise_Error (Code);
raise Program_Error;
else
return Result;
end if;
end Calculate_Maximum_All_Channels;
function Calculate_Normed_Maximum_All_Channels
(File : in Sound_File)
return Long_Float_Array
is
Result : Long_Float_Array (1 .. Natural (File.Chans));
Code : Interfaces.C.int;
begin
Ada.Assertions.Assert (Long_Float'Size = Interfaces.C.double'Size);
Code := sf_command
(File.Ptr,
sfc_calc_norm_max_all_channels,
Result'Address,
Interfaces.C.double'Size / Interfaces.C.CHAR_BIT * File.Chans);
if Code /= 0 then
Raise_Error (Code);
raise Program_Error;
else
return Result;
end if;
end Calculate_Normed_Maximum_All_Channels;
function Get_Signal_Maximum
(File : in Sound_File)
return Long_Float
is
Result : Interfaces.C.double;
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_get_signal_max,
Result'Address,
Interfaces.C.double'Size / Interfaces.C.CHAR_BIT);
if Code = sf_false then
raise Command_Error;
elsif Code = sf_true then
return Long_Float (Result);
else
raise Program_Error;
end if;
end Get_Signal_Maximum;
function Get_Maximum_All_Channels
(File : in Sound_File)
return Long_Float_Array
is
Result : Long_Float_Array (1 .. Natural (File.Chans));
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_get_max_all_channels,
Result'Address,
Interfaces.C.double'Size / Interfaces.C.CHAR_BIT * File.Chans);
if Code = sf_false then
raise Command_Error;
elsif Code = sf_true then
return Result;
else
raise Program_Error;
end if;
end Get_Maximum_All_Channels;
procedure Set_Normed_Float
(File : in Sound_File;
Value : in Boolean)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_set_norm_float,
System.Null_Address,
(if Value then sf_true else sf_false));
end Set_Normed_Float;
procedure Set_Normed_Double
(File : in Sound_File;
Value : in Boolean)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_set_norm_double,
System.Null_Address,
(if Value then sf_true else sf_false));
end Set_Normed_Double;
function Get_Normed_Float
(File : in Sound_File)
return Boolean
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_get_norm_float,
System.Null_Address,
0);
if Code = sf_true then
return True;
elsif Code = sf_false then
return False;
else
raise Program_Error;
end if;
end Get_Normed_Float;
function Get_Normed_Double
(File : in Sound_File)
return Boolean
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_get_norm_double,
System.Null_Address,
0);
if Code = sf_true then
return True;
elsif Code = sf_false then
return False;
else
raise Program_Error;
end if;
end Get_Normed_Double;
procedure Set_Scale_Float_Integer_Read
(File : in Sound_File;
Value : in Boolean)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_set_scale_float_int_read,
System.Null_Address,
(if Value then sf_true else sf_false));
end Set_Scale_Float_Integer_Read;
procedure Set_Scale_Integer_Float_Write
(File : in Sound_File;
Value : in Boolean)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_set_scale_int_float_write,
System.Null_Address,
(if Value then sf_true else sf_false));
end Set_Scale_Integer_Float_Write;
function Get_Simple_Format_Count
return Natural
is
Result, Code : Interfaces.C.int;
begin
Code := sf_command
(System.Null_Address,
sfc_get_simple_format_count,
Result'Address,
Interfaces.C.int'Size / Interfaces.C.CHAR_BIT);
if Result < 0 then
raise Program_Error;
else
return Natural (Result);
end if;
end Get_Simple_Format_Count;
function Get_Simple_Format
(Index : in Positive)
return Format_Info
is
Result : Format_Info :=
(My_Format => Interfaces.C.int (Index) - 1,
My_Name => Interfaces.C.Strings.Null_Ptr,
My_Extension => Interfaces.C.Strings.Null_Ptr);
Code : Interfaces.C.int;
begin
Code := sf_command
(System.Null_Address,
sfc_get_simple_format,
Result'Address,
Format_Info'Size / Interfaces.C.CHAR_BIT);
if Code /= 0 then
raise Command_Error;
else
return Result;
end if;
end Get_Simple_Format;
function Do_Get_Format_Info
(Format : in Interfaces.C.int)
return Format_Info
is
Result : Format_Info :=
(My_Format => Format,
My_Name => Interfaces.C.Strings.Null_Ptr,
My_Extension => Interfaces.C.Strings.Null_Ptr);
Code : Interfaces.C.int;
begin
Code := sf_command
(System.Null_Address,
sfc_get_format_info,
Result'Address,
Format_Info'Size / Interfaces.C.CHAR_BIT);
if Code /= 0 then
raise Command_Error;
else
return Result;
end if;
end Do_Get_Format_Info;
function Get_Format_Info
(Format : in Major_Format)
return Format_Info is
begin
return Do_Get_Format_Info (To_Cint (Format));
end Get_Format_Info;
function Get_Format_Info
(Format : in Minor_Format)
return Format_Info is
begin
return Do_Get_Format_Info (To_Cint (Format));
end Get_Format_Info;
function Get_Format_Major_Count
return Natural
is
Result, Code : Interfaces.C.int;
begin
Code := sf_command
(System.Null_Address,
sfc_get_format_major_count,
Result'Address,
Interfaces.C.int'Size / Interfaces.C.CHAR_BIT);
return Natural (Result);
end Get_Format_Major_Count;
function Get_Format_Major
(Index : in Positive)
return Format_Info
is
Result : Format_Info :=
(My_Format => Interfaces.C.int (Index) - 1,
My_Name => Interfaces.C.Strings.Null_Ptr,
My_Extension => Interfaces.C.Strings.Null_Ptr);
Code : Interfaces.C.int;
begin
Code := sf_command
(System.Null_Address,
sfc_get_format_major,
Result'Address,
Format_Info'Size / Interfaces.C.CHAR_BIT);
if Code /= 0 then
raise Command_Error;
else
return Result;
end if;
end Get_Format_Major;
function Get_Format_Subtype_Count
return Natural
is
Result, Code : Interfaces.C.int;
begin
Code := sf_command
(System.Null_Address,
sfc_get_format_subtype_count,
Result'Address,
Interfaces.C.int'Size / Interfaces.C.CHAR_BIT);
return Natural (Result);
end Get_Format_Subtype_Count;
function Get_Format_Subtype
(Index : in Positive)
return Format_Info
is
Result : Format_Info :=
(My_Format => Interfaces.C.int (Index) - 1,
My_Name => Interfaces.C.Strings.Null_Ptr,
My_Extension => Interfaces.C.Strings.Null_Ptr);
Code : Interfaces.C.int;
begin
Code := sf_command
(System.Null_Address,
sfc_get_format_subtype,
Result'Address,
Format_Info'Size / Interfaces.C.CHAR_BIT);
if Code /= 0 then
raise Command_Error;
else
return Result;
end if;
end Get_Format_Subtype;
procedure Set_Add_Peak_Chunk
(File : in Sound_File;
Value : in Boolean)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_set_add_peak_chunk,
System.Null_Address,
(if Value then sf_true else sf_false));
end Set_Add_Peak_Chunk;
procedure Update_Header_Now
(File : in Sound_File)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_update_header_now,
System.Null_Address,
0);
end Update_Header_Now;
procedure Set_Update_Header_Auto
(File : in Sound_File;
Value : in Boolean)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_set_update_header_auto,
System.Null_Address,
(if Value then sf_true else sf_false));
end Set_Update_Header_Auto;
procedure File_Truncate
(File : in Sound_File;
Position : in Count_Type)
is
Code : Interfaces.C.int;
begin
Code := asfc_file_truncate (File.Ptr, Interfaces.Integer_64 (Position));
if Code /= 0 then
raise Command_Error;
end if;
end File_Truncate;
procedure Set_Raw_Start_Offset
(File : in Sound_File;
Position : in Count_Type)
is
Code : Interfaces.C.int;
begin
Code := asfc_set_raw_start_offset (File.Ptr, Interfaces.Integer_64 (Position));
if Code /= 0 then
raise Command_Error;
end if;
end Set_Raw_Start_Offset;
procedure Set_Clipping
(File : in Sound_File;
Value : in Boolean)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_set_clipping,
System.Null_Address,
(if Value then sf_true else sf_false));
end Set_Clipping;
function Get_Clipping
(File : in Sound_File)
return Boolean
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_get_clipping,
System.Null_Address,
0);
if Code = sf_true then
return True;
elsif Code = sf_false then
return False;
else
raise Program_Error;
end if;
end Get_Clipping;
function Get_Embedded_File_Info
(File : in Sound_File)
return Embedded_Info
is
Info : Embedded_Info;
Code : Interfaces.C.int;
begin
Code := asfc_get_embed_file_info (File.Ptr, Info);
if Code /= 0 then
raise Command_Error;
else
return Info;
end if;
end Get_Embedded_File_Info;
function Wavex_Get_Ambisonic
(File : in Sound_File)
return Ambisonic
is
Result : Interfaces.C.int;
begin
Result := sf_command
(File.Ptr,
sfc_wavex_get_ambisonic,
System.Null_Address,
0);
if Result = 0 then
return Ambisonic_Unsupported;
elsif Result = sf_ambisonic_none then
return Ambisonic_Off;
elsif Result = sf_ambisonic_b_format then
return Ambisonic_B_Format;
else
raise Program_Error;
end if;
end Wavex_Get_Ambisonic;
procedure Wavex_Set_Ambisonic
(File : in Sound_File;
Value : in Ambisonic)
is
My_Value, Code : Interfaces.C.int;
begin
case Value is
when Ambisonic_Unsupported =>
return;
when Ambisonic_Off =>
My_Value := sf_ambisonic_none;
when Ambisonic_B_Format =>
My_Value := sf_ambisonic_b_format;
end case;
Code := sf_command
(File.Ptr,
sfc_wavex_set_ambisonic,
System.Null_Address,
My_Value);
if Code = 0 then
raise Command_Error;
elsif Code /= sf_ambisonic_none and Code /= sf_ambisonic_b_format then
raise Program_Error;
end if;
end Wavex_Set_Ambisonic;
procedure Set_Variable_Bitrate_Encoding_Quality
(File : in Sound_File;
Value : in Long_Long_Float)
is
Code : Interfaces.C.int;
My_Value : Interfaces.C.double;
begin
My_Value := Interfaces.C.double (Value);
Code := sf_command
(File.Ptr,
sfc_set_vbr_encoding_quality,
My_Value'Address,
Interfaces.C.double'Size / Interfaces.C.CHAR_BIT);
if Code = sf_false then
raise Command_Error;
elsif Code /= sf_true then
raise Program_Error;
end if;
end Set_Variable_Bitrate_Encoding_Quality;
procedure Set_Ogg_Page_Latency_Milliseconds
(File : in Sound_File;
Value : in Long_Long_Float)
is
Code : Interfaces.C.int;
My_Value : Interfaces.C.double;
begin
My_Value := Interfaces.C.double (Value);
Code := sf_command
(File.Ptr,
sfc_set_ogg_page_latency_ms,
My_Value'Address,
Interfaces.C.double'Size / Interfaces.C.CHAR_BIT);
if Code /= 0 then
raise Command_Error;
end if;
end Set_Ogg_Page_Latency_Milliseconds;
function Get_Ogg_Stream_Serial
(File : in Sound_File)
return Integer
is
Code : Interfaces.C.int;
Result : Interfaces.Integer_32;
begin
Code := sf_command
(File.Ptr,
sfc_get_ogg_stream_serialno,
Result'Address,
Interfaces.Integer_32'Size / Interfaces.C.CHAR_BIT);
if Code = 0 then
return Integer (Result);
else
raise Command_Error;
end if;
end Get_Ogg_Stream_Serial;
procedure Set_Compression_Level
(File : in Sound_File;
Value : in Compression)
is
Code : Interfaces.C.int;
My_Value : Interfaces.C.double;
begin
My_Value := Interfaces.C.double (Value);
Code := sf_command
(File.Ptr,
sfc_set_compression_level,
My_Value'Address,
Interfaces.C.double'Size / Interfaces.C.CHAR_BIT);
if Code = sf_false then
raise Command_Error;
elsif Code /= sf_true then
raise Program_Error;
end if;
end Set_Compression_Level;
function Raw_Data_Needs_Endswap
(File : in Sound_File)
return Boolean
is
Result : Interfaces.C.int;
begin
Result := sf_command
(File.Ptr,
sfc_raw_data_needs_endswap,
System.Null_Address,
0);
if Result = sf_true then
return True;
elsif Result = sf_false then
return False;
else
raise Program_Error;
end if;
end Raw_Data_Needs_Endswap;
function Get_Broadcast_Info
(File : in Sound_File)
return Broadcast_Info
is
Result : Broadcast_Info;
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_get_broadcast_info,
Result'Address,
Broadcast_Info'Size / Interfaces.C.CHAR_BIT);
if Code = sf_true then
return Result;
elsif Code = sf_false then
raise Command_Error;
else
raise Program_Error;
end if;
end Get_Broadcast_Info;
procedure Set_Broadcast_Info
(File : in Sound_File;
Value : in Broadcast_Info)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_set_broadcast_info,
Value'Address,
Broadcast_Info'Size / Interfaces.C.CHAR_BIT);
if Code = sf_false then
raise Command_Error;
elsif Code /= sf_true then
raise Program_Error;
end if;
end Set_Broadcast_Info;
function Get_Channel_Map_Info
(File : in Sound_File)
return Channel_Map_Array
is
Raw : array (Positive range 1 .. Natural (File.Chans)) of Interfaces.C.int;
Result : Channel_Map_Array (1 .. Natural (File.Chans));
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_get_channel_map_info,
Raw'Address,
Interfaces.C.int'Size / Interfaces.C.CHAR_BIT * File.Chans);
if Code = sf_false then
raise Command_Error;
elsif Code /= sf_true then
raise Program_Error;
else
for Index in Raw'Range loop
Result (Index) := Channel_Map'Val (Raw (Index));
end loop;
return Result;
end if;
end Get_Channel_Map_Info;
procedure Set_Channel_Map_Info
(File : in Sound_File;
Value : in Channel_Map_Array)
is
My_Value : array (Positive range 1 .. Natural (File.Chans)) of Interfaces.C.int;
Code : Interfaces.C.int;
begin
if Value'Length /= File.Chans then
raise Command_Error;
end if;
for Index in Value'Range loop
My_Value (Index) := Channel_Map'Pos (Value (Index));
end loop;
Code := sf_command
(File.Ptr,
sfc_set_channel_map_info,
My_Value'Address,
Interfaces.C.int'Size / Interfaces.C.CHAR_BIT * File.Chans);
if Code = sf_false then
raise Command_Error;
elsif Code /= sf_true then
raise Program_Error;
end if;
end Set_Channel_Map_Info;
function Get_Cue_Count
(File : in Sound_File)
return Interfaces.Unsigned_32
is
Result : Interfaces.Unsigned_32;
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_get_cue_count,
Result'Address,
Interfaces.Unsigned_32'Size / Interfaces.C.CHAR_BIT);
if Code = sf_false then
raise Command_Error;
elsif Code = sf_true then
return Result;
else
raise Program_Error;
end if;
end Get_Cue_Count;
procedure RF64_Auto_Downgrade
(File : in Sound_File;
Value : in Boolean)
is
Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_rf64_auto_downgrade,
System.Null_Address,
(if Value then sf_true else sf_false));
end RF64_Auto_Downgrade;
function Get_Original_Samplerate
(File : in Sound_File)
return Natural
is
Result, Code : Interfaces.C.int;
begin
Code := sf_command
(File.Ptr,
sfc_get_original_samplerate,
Result'Address,
Interfaces.C.int'Size / Interfaces.C.CHAR_BIT);
if Code = sf_true then
return Natural (Result);
else
raise Command_Error;
end if;
end Get_Original_Samplerate;
procedure Set_Original_Samplerate
(File : in Sound_File;
Value : in Natural)
is
My_Value, Code : Interfaces.C.int;
begin
My_Value := Interfaces.C.int (Value);
Code := sf_command
(File.Ptr,
sfc_set_original_samplerate,
My_Value'Address,
Interfaces.C.int'Size / Interfaces.C.CHAR_BIT);
if Code = sf_false then
raise Command_Error;
elsif Code /= sf_true then
raise Program_Error;
end if;
end Set_Original_Samplerate;
function Get_Bitrate_Mode
(File : in Sound_File)
return Bitrate_Mode
is
Result : Interfaces.C.int;
begin
Result := sf_command
(File.Ptr,
sfc_get_bitrate_mode,
System.Null_Address,
0);
if Result = sf_bitrate_mode_constant then
return Constant_Mode;
elsif Result = sf_bitrate_mode_average then
return Average_Mode;
elsif Result = sf_bitrate_mode_variable then
return Variable_Mode;
elsif Result = -1 then
raise Command_Error;
else
raise Program_Error;
end if;
end Get_Bitrate_Mode;
procedure Set_Bitrate_Mode
(File : in Sound_File;
Value : in Bitrate_Mode)
is
Code : Interfaces.C.int;
My_Value : Interfaces.C.int := (case Value is
when Constant_Mode => sf_bitrate_mode_constant,
when Average_Mode => sf_bitrate_mode_average,
when Variable_Mode => sf_bitrate_mode_variable);
begin
Code := sf_command
(File.Ptr,
sfc_set_bitrate_mode,
My_Value'Address,
Interfaces.C.int'Size / Interfaces.C.CHAR_BIT);
if Code = sf_false then
raise Command_Error;
elsif Code /= sf_true then
raise Program_Error;
end if;
end Set_Bitrate_Mode;
end Libsndfile.Commands;
|