sdlada_2.5.20_cd53c280/src/mixer/sdl-mixer-chunks.adb

  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
--------------------------------------------------------------------------------------------------------------------
--  This source code is subject to the Zlib license, see the LICENCE file in the root of this directory.
--------------------------------------------------------------------------------------------------------------------

with SDL.Error;

with Interfaces.C.Strings;

package body SDL.Mixer.Chunks is

   -----------------
   -- Load_WAV_RW --
   -----------------

   procedure Load_WAV_RW (Source      : in out SDL.RWops.RWops;
                          Free_Source : in     Boolean;
                          Chunk       :    out Chunk_Type)
   is
      function Mix_Load_WAV_RW (Source   : in SDL.RWops.RWops;
                                Free_Src : in C.int) return Chunk_Type
        with
        Import        => True,
        Convention    => C,
        External_Name => "Mix_LoadWAV_RW";
      Free_C  : constant C.int      := Boolean'Pos (Free_Source);
      Chunk_C : constant Chunk_Type := Mix_Load_WAV_RW (Source, Free_C);
   begin
      if Chunk_C = null then
         raise Mixer_Error with SDL.Error.Get;
      end if;
      Chunk := Chunk_C;
   end Load_WAV_RW;

   --------------
   -- Load_WAV --
   --------------

   procedure Load_WAV (Filename : in     String;
                       Chunk    :    out Chunk_Type)
   is
      use SDL.RWops;
      Ops : RWops.RWops := From_File (Filename, Read_Binary);
   begin
      Load_WAV_RW (Ops, True, Chunk);
   end Load_WAV;

   --------------------
   -- Quick_Load_WAV --
   --------------------

   procedure Quick_Load_WAV (Mem   : in     System.Address;
                             Chunk :    out Chunk_Type)
   is
      function Mix_Quick_Load_WAV (Mem : in System.Address) return Chunk_Type
        with
        Import => True,
        Convention => C,
        External_Name => "Mix_QuickLoad_WAV";
      Result : constant Chunk_Type := Mix_Quick_Load_WAV (Mem);
   begin
      if Result = null then
         raise Mixer_Error with SDL.Error.Get;
      end if;
      Chunk := Result;
   end Quick_Load_WAV;

   --------------------
   -- Quick_Load_RAW --
   --------------------

   procedure Quick_Load_RAW (Mem   : in     System.Address;
                             Len   : in     Byte_Count;
                             Chunk :    out Chunk_Type)
   is
      use Interfaces;
      function Mix_Quick_Load_RAW (Mem : in System.Address;
                                   Len : in Unsigned_32) return Chunk_Type
        with
        Import => True,
        Convention => C,
        External_Name => "Mix_QuickLoad_RAW";
      Result : constant Chunk_Type := Mix_Quick_Load_RAW (Mem, Unsigned_32 (Len));
   begin
      if Result = null then
         raise Mixer_Error with SDL.Error.Get;
      end if;
      Chunk := Result;
   end Quick_Load_RAW;

   ----------
   -- Free --
   ----------

   procedure Free (Chunk : in out Chunk_Type)
   is
      procedure Mix_Free_Chunk (Chunk : in Chunk_Type)
        with
        Import        => True,
        Convention    => C,
        External_Name => "Mix_FreeChunk";
   begin
      Mix_Free_Chunk (Chunk);
   end Free;

   ------------------------
   -- Number_Of_Decoders --
   ------------------------

   function Number_Of_Decoders return Natural
   is
      function Mix_Get_Num_Chunk_Decoders return C.int
        with
        Import        => True,
        Convention    => C,
        External_Name => "Mix_GetNumChunkDecoders";
   begin
      return Natural (Mix_Get_Num_Chunk_Decoders);
   end Number_Of_Decoders;

   ------------------
   -- Decoder_Name --
   ------------------

   function Decoder_Name (Index : in Positive) return String
   is
      use Interfaces.C.Strings;
      function Mix_Get_Chunk_Decoder_Name (Index : in C.int)
                                          return chars_ptr with
        Import        => True,
        Convention    => C,
        External_Name => "Mix_GetChunkDecoder";
      Index_C : constant C.int := C.int (Index - 1);
   begin
      return Value (Mix_Get_Chunk_Decoder_Name (Index_C));
   end Decoder_Name;

   -----------------
   -- Has_Decoder --
   -----------------

   function Has_Decoder (Name : in String) return Boolean
   is
      use Interfaces.C.Strings;
      function Mix_Has_Chunk_Decoder (Name : in chars_ptr) return C.int
        with
        Import        => True,
        Convention    => C,
        External_Name => "Mix_HasChunkDecoder";
      Result : constant C.int := Mix_Has_Chunk_Decoder (New_String (Name));
   begin
      return Result /= 0;
   end Has_Decoder;


end SDL.Mixer.Chunks;