comp.lang.ada
 help / color / mirror / Atom feed
* Allocation questions
@ 2009-05-28  9:46 Olivier Scalbert
  2009-05-28 10:02 ` Martin
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Olivier Scalbert @ 2009-05-28  9:46 UTC (permalink / raw)


Hello,

In the context of my small audio project, I need to create an object to 
introduce a delay in a signal. With some of these objects and other 
stuff it is possible to simulate nice reverberation.

Here is the code (As delay is a reserved word in Ada, I use Delay_T as I 
found nothing better !):

package audio.effect is

     type Sample is new Float;
     type Time   is new Float;

     type Samples_Array is array (Positive range <>) of Sample;

     type Delay_T is tagged record
         Delay_Time: Time;
         Output    : Sample;
         Samples   : access Samples_Array;
     end record;

     function Create_Delay (Time_Value: Time) return Delay_T;

     procedure Input (D: Delay_T; Input: Sample);
     function Output (D: Delay_T) return Sample;
     procedure  Next (D: Delay_T); -- compute next output

end audio.effect;

package body audio.effect is

     function Create_Delay(Time_Value: Time) return Delay_T is
         Result:      Delay_T;
         Nb_Samples:  Integer;
     begin
         Result.Delay_Time := Time_Value;
         Nb_Samples := Integer(Time_Value * 44_100.0);
         Result.Samples := new Samples_Array(1..Nb_Samples);
         Result.Output  := 0.0;
         return Result;
     end Create_Delay;

     procedure Input (D: Delay_T; Input: Sample) is
     begin
         null; --TBD
     end Input;

     function Output(D: Delay_T) return Sample is
     begin
         return D.Output;
     end Output;

     procedure Next(D: Delay_T) is
     begin
         null; --TBD
     end Next;

end audio.effect;
-- --------------------------------
Here are my questions:

1) Is there a way to avoid the dynamic array allocation, as I do not 
know the Time_Value at compile time ?

2) Is it possible to release the array automatically when the Delay 
object died ?

3) I have read that there is a program call gnatmem to detect memory 
leaks. Is there somewhere a package for Linux (Debian) ?

Thanks for the help,

Olivier



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2009-05-28 23:13 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-28  9:46 Allocation questions Olivier Scalbert
2009-05-28 10:02 ` Martin
2009-05-28 11:55   ` xavier grave
2009-05-28 12:19     ` Ludovic Brenta
2009-05-28 13:00       ` Georg Bauhaus
2009-05-28 23:13       ` Robert A Duff
2009-05-28 10:05 ` Dmitry A. Kazakov
2009-05-28 10:40   ` Martin
2009-05-28 12:32     ` Olivier Scalbert
2009-05-28 13:39       ` Martin
2009-05-28 13:57         ` Olivier Scalbert
2009-05-28 14:51         ` Adam Beneschan
2009-05-28 17:58           ` Randy Brukardt
2009-05-28 14:04       ` Dmitry A. Kazakov
2009-05-28 16:59 ` Jeffrey R. Carter
2009-05-28 17:26   ` Olivier Scalbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox