private with Allegro.Digital_Samples;
private with Almp3;
private with Resources;
private package Audio_Players.Cache is
type Sound is abstract tagged limited private;
type A_Sound is access all Sound'Class;
function Is_Done( this : not null access Sound'Class ) return Boolean;
procedure Play( this : access Sound; looping : Boolean ) is abstract;
procedure Poll( this : access Sound ) is abstract;
procedure Stop( this : access Sound ) is abstract;
function Load_Sound( filename : String ) return A_Sound;
pragma Precondition( filename'Length > 0 );
pragma Postcondition( Load_Sound'Result /= null );
procedure Unload_Sound( snd : in out A_Sound );
private
use Allegro.Digital_Samples;
use Almp3;
use Resources;
type Audio_Resource is abstract new Object with
record
refs : Natural := 0;
resource : A_Resource_File := null;
end record;
type A_Audio_Resource is access all Audio_Resource'Class;
function Create_Audio_Resource( filename : String ) return A_Audio_Resource;
pragma Precondition( filename'Length > 0 );
pragma Postcondition( Create_Audio_Resource'Result /= null );
procedure Construct( this : access Audio_Resource; filename : String );
function Create_Sound( this : access Audio_Resource ) return A_Sound;
pragma Postcondition( Create_Sound'Result = null );
procedure Dec_Refs( this : not null access Audio_Resource'Class );
procedure Delete( this : in out Audio_Resource );
function Get_Resource_File( this : not null access Audio_Resource'Class ) return A_Resource_File;
procedure Inc_Refs( this : not null access Audio_Resource'Class );
function Ref_Count( this : not null access Audio_Resource'Class ) return Natural;
procedure Delete( this : in out A_Audio_Resource );
type Mp3_Resource is new Audio_Resource with null record;
type A_Mp3_Resource is access all Mp3_Resource'Class;
function Create_Mp3_Resource( filename : String ) return A_Audio_Resource;
pragma Precondition( filename'Length > 0 );
function Create_Sound( this : access Mp3_Resource ) return A_Sound;
pragma Postcondition( Create_Sound'Result /= null );
type Sample_Resource is new Audio_Resource with
record
sample : A_Sample := null;
end record;
type A_Sample_Resource is access all Sample_Resource'Class;
function Create_Sample_Resource( filename : String ) return A_Audio_Resource;
procedure Construct( this : access Sample_Resource; filename : String );
function Create_Sound( this : access Sample_Resource ) return A_Sound;
pragma Postcondition( Create_Sound'Result /= null );
procedure Delete( this : in out Sample_Resource );
function Get_Sample( this : not null access Sample_Resource'Class ) return A_Sample;
pragma Postcondition( Get_Sample'Result /= null );
type Sound is abstract tagged limited
record
resource : A_Audio_Resource := null;
done : Boolean := False;
end record;
procedure Delete( this : in out Sound );
function Get_Filename( this : not null access Sound'Class ) return String;
pragma Postcondition( Get_Filename'Result'Length > 0 );
procedure Delete( this : in out A_Sound );
pragma Postcondition( this = null );
type Mp3_Sound is new Sound with
record
mp3 : A_mp3 := null;
end record;
function Create_Mp3_Sound( resource : not null A_Mp3_Resource ) return A_Sound;
pragma Postcondition( Create_Mp3_Sound'Result /= null );
procedure Delete( this : in out Mp3_Sound );
procedure Play( this : access Mp3_Sound; looping : Boolean );
procedure Poll( this : access Mp3_Sound );
procedure Stop( this : access Mp3_Sound );
type Sample_Sound is new Sound with
record
voice : Integer := -1;
end record;
function Create_Sample_Sound( resource : not null A_Sample_Resource ) return A_Sound;
pragma Postcondition( Create_Sample_Sound'Result /= null );
procedure Play( this : access Sample_Sound; looping : Boolean );
procedure Poll( this : access Sample_Sound );
procedure Stop( this : access Sample_Sound );
end Audio_Players.Cache;