From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,4cad17e8664256c9 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!s20g2000vbp.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Allocation questions Date: Thu, 28 May 2009 03:02:49 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <4a1e5d9e$0$2868$ba620e4c@news.skynet.be> NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1243504969 16004 127.0.0.1 (28 May 2009 10:02:49 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 28 May 2009 10:02:49 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s20g2000vbp.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6060 Date: 2009-05-28T03:02:49-07:00 List-Id: On May 28, 10:46=A0am, Olivier Scalbert wrote: > 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 > > =A0 =A0 =A0type Sample is new Float; > =A0 =A0 =A0type Time =A0 is new Float; > > =A0 =A0 =A0type Samples_Array is array (Positive range <>) of Sample; > > =A0 =A0 =A0type Delay_T is tagged record > =A0 =A0 =A0 =A0 =A0Delay_Time: Time; > =A0 =A0 =A0 =A0 =A0Output =A0 =A0: Sample; > =A0 =A0 =A0 =A0 =A0Samples =A0 : access Samples_Array; > =A0 =A0 =A0end record; > > =A0 =A0 =A0function Create_Delay (Time_Value: Time) return Delay_T; > > =A0 =A0 =A0procedure Input (D: Delay_T; Input: Sample); > =A0 =A0 =A0function Output (D: Delay_T) return Sample; > =A0 =A0 =A0procedure =A0Next (D: Delay_T); -- compute next output > > end audio.effect; > > package body audio.effect is > > =A0 =A0 =A0function Create_Delay(Time_Value: Time) return Delay_T is > =A0 =A0 =A0 =A0 =A0Result: =A0 =A0 =A0Delay_T; > =A0 =A0 =A0 =A0 =A0Nb_Samples: =A0Integer; > =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0Result.Delay_Time :=3D Time_Value; > =A0 =A0 =A0 =A0 =A0Nb_Samples :=3D Integer(Time_Value * 44_100.0); > =A0 =A0 =A0 =A0 =A0Result.Samples :=3D new Samples_Array(1..Nb_Samples); > =A0 =A0 =A0 =A0 =A0Result.Output =A0:=3D 0.0; > =A0 =A0 =A0 =A0 =A0return Result; > =A0 =A0 =A0end Create_Delay; > > =A0 =A0 =A0procedure Input (D: Delay_T; Input: Sample) is > =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0null; --TBD > =A0 =A0 =A0end Input; > > =A0 =A0 =A0function Output(D: Delay_T) return Sample is > =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0return D.Output; > =A0 =A0 =A0end Output; > > =A0 =A0 =A0procedure Next(D: Delay_T) is > =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0null; --TBD > =A0 =A0 =A0end 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 ? You could look at Ada.Container.Vectors and the Reserve_Capacity subprogram. The container libraries should offer perfectly acceptable performance, esp if you only need to reserve once. Or you could use a discriminant: type Samples (No_Of_Samples : Natural :=3D 0) is record S : array (1 .. No_Of_Samples) of Sample; end record; > 2) Is it possible to release the array automatically when the Delay > object died ? Checkout package Ada.Finalization. > 3) I have read that there is a program call gnatmem to detect memory > leaks. Is there somewhere a package for Linux (Debian) ? Sorry, no idea. Cheers -- Martin