summaryrefslogtreecommitdiff
path: root/src/libsndfile-commands.ads
blob: 45e509871ce738b1825b67c5ed8e061d96e69f5d (plain)
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


--  Programmed by Jedidiah Barber
--  Released into the public domain


with

    Interfaces;

private with

    Interfaces.C.Strings;


package Libsndfile.Commands is


    ---------------------------------
    --  Data Types and Structures  --
    ---------------------------------

    type Long_Float_Array is array (Positive range <>) of Long_Float;


    type Format_Info is tagged private;

    function Major
           (Info : in Format_Info)
        return Major_Format;

    function Minor
           (Info : in Format_Info)
        return Minor_Format;

    function Endian
           (Info : in Format_Info)
        return Endianness;

    function Name
           (Info : in Format_Info)
        return String;

    function Extension
           (Info : in Format_Info)
        return String;


    type Embedded_Info is record
        Offset : Count_Type;
        Length : Count_Type;
    end record;

    type Ambisonic is
       (Ambisonic_Unsupported,
        Ambisonic_Off,
        Ambisonic_B_Format);

    subtype Compression is Long_Float range 0.0 .. 1.0;

    type Broadcast_Info is record
        Description          : String (1 .. 256);
        Originator           : String (1 .. 32);
        Originator_Reference : String (1 .. 32);
        Origination_Date     : String (1 .. 10);
        Origination_Time     : String (1 .. 8);
        Time_Reference_Low   : Interfaces.Unsigned_32;
        Time_Reference_High  : Interfaces.Unsigned_32;
        Version              : Short_Integer;
        Umid                 : String (1 .. 64);
        Reserved             : String (1 .. 190);
        Coding_History_Size  : Interfaces.Unsigned_32;
        Coding_History       : String (1 .. 256);
    end record;

    type Channel_Map is
       (Map_Invalid,
        Map_Mono,
        Map_Left,
        Map_Right,
        Map_Center,
        Map_Front_Left,
        Map_Front_Right,
        Map_Front_Center,
        Map_Rear_Center,
        Map_Rear_Left,
        Map_Rear_Right,
        Map_LFE,
        Map_Front_Left_Of_Center,
        Map_Front_Right_Of_Center,
        Map_Side_Left,
        Map_Side_Right,
        Map_Top_Center,
        Map_Top_Front_Left,
        Map_Top_Front_Right,
        Map_Top_Front_Center,
        Map_Top_Rear_Left,
        Map_Top_Rear_Right,
        Map_Top_Rear_Center,
        Map_Ambisonic_B_W,
        Map_Ambisonic_B_X,
        Map_Ambisonic_B_Y,
        Map_Ambisonic_B_Z,
        Map_Max);

    type Channel_Map_Array is array (Positive range <>) of Channel_Map;


    type Cart_Timer is record
        Usage : String (1 .. 4);
        Value : Interfaces.Integer_32;
    end record;

    type Cart_Timer_Array is array (Positive range <>) of Cart_Timer;

    --  Is 1024 enough? Who knows! I hate this API
    Max_Cart_Tag_Size : constant Natural := 1024;

    type Cart_Info (Tag_Size : Natural) is record
        Version              : String (1 .. 4);
        Title                : String (1 .. 64);
        Artist               : String (1 .. 64);
        Cut_ID               : String (1 .. 64);
        Client_ID            : String (1 .. 64);
        Category             : String (1 .. 64);
        Classification       : String (1 .. 64);
        Out_Cue              : String (1 .. 64);
        Start_Date           : String (1 .. 10);
        Start_Time           : String (1 .. 8);
        End_Date             : String (1 .. 10);
        End_Time             : String (1 .. 8);
        Producer_App_ID      : String (1 .. 64);
        Producer_App_Version : String (1 .. 64);
        User_Defined         : String (1 .. 64);
        Level_Reference      : Long_Integer;
        Post_Timers          : Cart_Timer_Array (1 .. 8);
        Reserved             : String (1 .. 276);
        URL                  : String (1 .. 1024);
        Tag_Text             : String (1 .. Tag_Size);
    end record;


    type Loop_Mode is
       (No_Loop,
        Loop_Forward,
        Loop_Backward,
        Loop_Alternating);

    type Beats_Per_Minute is delta 10.0**(-2) digits 5 range 0.0 .. 655.0;

    subtype MIDI_Note is Integer range -1 .. 127;
    No_Note : constant MIDI_Note := -1;

    type Integer_Array is array (Positive range <>) of Integer;

    type Loop_Info is record
        Time_Sig_Num : Short_Integer;
        Time_Sig_Den : Short_Integer;
        Mode         : Loop_Mode;
        Beats        : Positive;
        BPM          : Beats_Per_Minute;
        Root_Key     : MIDI_Note;
        Future       : Integer_Array (1 .. 6);
    end record;


    --  Many of these fields should likely be something more specific
    --  However it is hard to tell exactly what would be best
    type Instrument_Data is record
        Gain          : Integer;
        Basenote      : Character;
        Detune        : Character;
        Velocity_Low  : Character;
        Velocity_High : Character;
        Key_Low       : Character;
        Key_High      : Character;
    end record;

    type Loop_Data is record
        Mode   : Loop_Mode;
        Start  : Interfaces.Unsigned_32;
        Finish : Interfaces.Unsigned_32;
        Count  : Interfaces.Unsigned_32;
    end record;

    type Loop_Data_Array is array (Positive range <>) of Loop_Data;

    type Instrument_Info is tagged private;

    function Create
           (Base    : in Instrument_Data;
            Repeats : in Loop_Data_Array)
        return Instrument_Info
    with Pre => Repeats'Length <= 16;

    function Base
           (Info : in Instrument_Info)
        return Instrument_Data;

    function Repeats
           (Info : in Instrument_Info)
        return Loop_Data_Array
    with Post => Repeats'Result'Length <= 16;


    type Cue_Marker is record
        Index         : Integer;
        Position      : Interfaces.Unsigned_32;
        FCC_Chunk     : Integer;
        Chunk_Start   : Integer;
        Block_Start   : Integer;
        Sample_Offset : Interfaces.Unsigned_32;
        Name          : String (1 .. 256);
    end record;

    type Cue_Marker_Array is array (Positive range <>) of Cue_Marker;


    type Bitrate_Mode is
       (Constant_Mode,
        Average_Mode,
        Variable_Mode);




    ------------------
    --  Exceptions  --
    ------------------

    Command_Error : exception;




    ---------------------
    --  API Interface  --
    ---------------------

    function Get_Library_String
           (Buffer : out String)
        return Natural;

    function Get_Log_Info
           (File   : in  Sound_File;
            Buffer : out String)
        return Natural;

    function Get_Current_File_Info
           (File : in Sound_File)
        return File_Info;

    function Calculate_Signal_Maximum
           (File : in Sound_File)
        return Long_Float;

    function Calculate_Normed_Signal_Maximum
           (File : in Sound_File)
        return Long_Float;

    function Calculate_Maximum_All_Channels
           (File : in Sound_File)
        return Long_Float_Array;

    function Calculate_Normed_Maximum_All_Channels
           (File : in Sound_File)
        return Long_Float_Array;

    function Get_Signal_Maximum
           (File : in Sound_File)
        return Long_Float;

    function Get_Maximum_All_Channels
           (File : in Sound_File)
        return Long_Float_Array;

    procedure Set_Normed_Float
           (File  : in Sound_File;
            Value : in Boolean);

    procedure Set_Normed_Double
           (File  : in Sound_File;
            Value : in Boolean);

    function Get_Normed_Float
           (File : in Sound_File)
        return Boolean;

    function Get_Normed_Double
           (File : in Sound_File)
        return Boolean;

    procedure Set_Scale_Float_Integer_Read
           (File  : in Sound_File;
            Value : in Boolean);

    procedure Set_Scale_Integer_Float_Write
           (File  : in Sound_File;
            Value : in Boolean);

    function Get_Simple_Format_Count
        return Natural;

    function Get_Simple_Format
           (Index : in Positive)
        return Format_Info;

    function Get_Format_Info
           (Format : in Major_Format)
        return Format_Info;

    function Get_Format_Info
           (Format : in Minor_Format)
        return Format_Info;

    function Get_Format_Major_Count
        return Natural;

    function Get_Format_Major
           (Index : in Positive)
        return Format_Info;

    function Get_Format_Subtype_Count
        return Natural;

    function Get_Format_Subtype
           (Index : in Positive)
        return Format_Info;

    procedure Set_Add_Peak_Chunk
           (File  : in Sound_File;
            Value : in Boolean);

    procedure Update_Header_Now
           (File : in Sound_File);

    procedure Set_Update_Header_Auto
           (File  : in Sound_File;
            Value : in Boolean);

    procedure File_Truncate
           (File     : in Sound_File;
            Position : in Count_Type);

    procedure Set_Raw_Start_Offset
           (File     : in Sound_File;
            Position : in Count_Type);

    procedure Set_Clipping
           (File  : in Sound_File;
            Value : in Boolean);

    function Get_Clipping
           (File : in Sound_File)
        return Boolean;

    function Get_Embedded_File_Info
           (File : in Sound_File)
        return Embedded_Info;

    function Wavex_Get_Ambisonic
           (File : in Sound_File)
        return Ambisonic;

    procedure Wavex_Set_Ambisonic
           (File  : in Sound_File;
            Value : in Ambisonic);

    procedure Set_Variable_Bitrate_Encoding_Quality
           (File  : in Sound_File;
            Value : in Long_Long_Float);

    procedure Set_Ogg_Page_Latency_Milliseconds
           (File  : in Sound_File;
            Value : in Long_Long_Float);

    function Get_Ogg_Stream_Serial
           (File : in Sound_File)
        return Integer;

    procedure Set_Compression_Level
           (File  : in Sound_File;
            Value : in Compression);

    function Raw_Data_Needs_Endswap
           (File : in Sound_File)
        return Boolean;

    function Get_Broadcast_Info
           (File : in Sound_File)
        return Broadcast_Info;

    procedure Set_Broadcast_Info
           (File  : in Sound_File;
            Value : in Broadcast_Info);

    function Get_Channel_Map_Info
           (File : in Sound_File)
        return Channel_Map_Array;

    procedure Set_Channel_Map_Info
           (File  : in Sound_File;
            Value : in Channel_Map_Array);

    function Get_Cart_Info
           (File : in Sound_File)
        return Cart_Info
    with Post => Get_Cart_Info'Result.Tag_Size <= Max_Cart_Tag_Size;

    procedure Set_Cart_Info
           (File : in Sound_File;
            Info : in Cart_Info)
    with Pre => Info.Tag_Size <= Max_Cart_Tag_Size;

    function Get_Loop_Info
           (File : in Sound_File)
        return Loop_Info;

    function Get_Instrument
           (File : in Sound_File)
        return Instrument_Info;

    procedure Set_Instrument
           (File : in Sound_File;
            Info : in Instrument_Info);

    function Get_Cue_Count
           (File : in Sound_File)
        return Interfaces.Unsigned_32;

    function Get_Cue
           (File : in Sound_File)
        return Cue_Marker_Array
    with Post => Get_Cue'Result'Length <= 100;

    procedure Set_Cue
           (File : in Sound_File;
            Info : in Cue_Marker_Array)
    with Pre => Info'Length <= 100;

    --  Why the hell would you design this command in this way?
    --  You shouldn't have to intentionally try to set the thing after writing
    --  in order to find the value of it.
    procedure RF64_Auto_Downgrade
           (File  : in Sound_File;
            Value : in Boolean);

    function Get_Original_Samplerate
           (File : in Sound_File)
        return Natural;

    procedure Set_Original_Samplerate
           (File  : in Sound_File;
            Value : in Natural);

    function Get_Bitrate_Mode
           (File : in Sound_File)
        return Bitrate_Mode;

    procedure Set_Bitrate_Mode
           (File  : in Sound_File;
            Value : in Bitrate_Mode);


private


    --  This corresponds to the C-side SF_FORMAT_INFO
    type C_Format_Info is record
        My_Format    : Interfaces.C.int;
        My_Name      : Interfaces.C.Strings.chars_ptr;
        My_Extension : Interfaces.C.Strings.chars_ptr;
    end record with Convention => C;

    type Format_Info is tagged record
        C_Data : C_Format_Info;
    end record;


    --  This cannot correspond to the C-side SF_EMBED_FILE_INFO struct since
    --  sf_count_t can vary
    type C_Embedded_Info is record
        My_Offset : Interfaces.Integer_64;
        My_Length : Interfaces.Integer_64;
    end record with Convention => C;


    --  This corresponds to the C-side SF_BROADCAST_INFO
    type C_Broadcast_Info is record
        My_Description          : Interfaces.C.char_array (1 .. 256);
        My_Originator           : Interfaces.C.char_array (1 .. 32);
        My_Originator_Reference : Interfaces.C.char_array (1 .. 32);
        My_Origination_Date     : Interfaces.C.char_array (1 .. 10);
        My_Origination_Time     : Interfaces.C.char_array (1 .. 8);
        My_Time_Reference_Low   : Interfaces.C.unsigned;
        My_Time_Reference_High  : Interfaces.C.unsigned;
        My_Version              : Interfaces.C.short;
        My_Umid                 : Interfaces.C.char_array (1 .. 64);
        My_Reserved             : Interfaces.C.char_array (1 .. 190);
        My_Coding_History_Size  : Interfaces.C.unsigned;
        My_Coding_History       : Interfaces.C.char_array (1 .. 256);
    end record with Convention => C;


    --  This corresponds to the C-side SF_CART_TIMER
    type C_Cart_Timer is record
        My_Usage : Interfaces.C.char_array (1 .. 4);
        My_Value : Interfaces.Integer_32;
    end record with Convention => C;

    type C_Cart_Timer_Array is array (Positive range <>) of C_Cart_Timer;

    --  This corresponds to the C-side SF_CART_INFO
    type C_Cart_Info is record
        My_Version              : Interfaces.C.char_array (1 .. 4);
        My_Title                : Interfaces.C.char_array (1 .. 64);
        My_Artist               : Interfaces.C.char_array (1 .. 64);
        My_Cut_ID               : Interfaces.C.char_array (1 .. 64);
        My_Client_ID            : Interfaces.C.char_array (1 .. 64);
        My_Category             : Interfaces.C.char_array (1 .. 64);
        My_Classification       : Interfaces.C.char_array (1 .. 64);
        My_Out_Cue              : Interfaces.C.char_array (1 .. 64);
        My_Start_Date           : Interfaces.C.char_array (1 .. 10);
        My_Start_Time           : Interfaces.C.char_array (1 .. 8);
        My_End_Date             : Interfaces.C.char_array (1 .. 10);
        My_End_Time             : Interfaces.C.char_array (1 .. 8);
        My_Producer_App_ID      : Interfaces.C.char_array (1 .. 64);
        My_Producer_App_Version : Interfaces.C.char_array (1 .. 64);
        My_User_Def             : Interfaces.C.char_array (1 .. 64);
        My_Level_Reference      : Interfaces.C.long;
        My_Post_Timers          : C_Cart_Timer_Array (1 .. 8);
        My_Reserved             : Interfaces.C.char_array (1 .. 276);
        My_URL                  : Interfaces.C.char_array (1 .. 1024);
        My_Tag_Text_Size        : Interfaces.C.unsigned;
        My_Tag_Text             : Interfaces.C.char_array
            (1 .. Interfaces.C.size_t (Max_Cart_Tag_Size));
    end record with Convention => C;


    type C_Int_Array is array (Positive range <>) of Interfaces.C.int;

    --  This corresponds to the C-side SF_LOOP_INFO struct
    type C_Loop_Info is record
        My_Time_Sig_Num : Interfaces.C.short;
        My_Time_Sig_Den : Interfaces.C.short;
        My_Loop_Mode    : Interfaces.C.int;
        My_Num_Beats    : Interfaces.C.int;
        My_BPM          : Interfaces.C.C_float;
        My_Root_Key     : Interfaces.C.int;
        My_Future       : C_Int_Array (1 .. 6);
    end record with Convention => C;


    type C_Loop_Data is record
        My_Mode  : Interfaces.C.int;
        My_Start : Interfaces.C.unsigned;
        My_End   : Interfaces.C.unsigned;
        My_Count : Interfaces.C.unsigned;
    end record with Convention => C;

    type C_Loop_Data_Array is array (Positive range <>) of C_Loop_Data;

    --  This corresponds to the C-side SF_INSTRUMENT struct
    type C_Instrument_Info is record
        My_Gain        : Interfaces.C.int;
        My_Basenote    : Interfaces.C.char;
        My_Detune      : Interfaces.C.char;
        My_Velocity_Lo : Interfaces.C.char;
        My_Velocity_Hi : Interfaces.C.char;
        My_Key_Lo      : Interfaces.C.char;
        My_Key_Hi      : Interfaces.C.char;
        My_Loop_Count  : Interfaces.C.int;
        My_Loops       : C_Loop_Data_Array (1 .. 16);
    end record with Convention => C;

    type Instrument_Info is tagged record
        C_Data : C_Instrument_Info;
    end record;


    type C_Cue is record
        My_Indx          : Interfaces.Integer_32;
        My_Position      : Interfaces.Unsigned_32;
        My_FCC_Chunk     : Interfaces.Integer_32;
        My_Chunk_Start   : Interfaces.Integer_32;
        My_Block_Start   : Interfaces.Integer_32;
        My_Sample_Offset : Interfaces.Unsigned_32;
        My_Name          : Interfaces.C.char_array (1 .. 256);
    end record with Convention => C;

    type C_Cue_Array is array (Positive range <>) of C_Cue;

    --  This corresponds to the C-side SF_CUES struct
    type C_Cue_Info is record
        My_Cue_Count  : Interfaces.C.int;
        My_Cue_Points : C_Cue_Array (1 .. 100);
    end record with Convention => C;


    function To_Ada
           (Num : in Interfaces.C.int)
        return Loop_Mode;

    function To_C
           (Enum : in Loop_Mode)
        return Interfaces.C.int;


end Libsndfile.Commands;