comp.lang.ada
 help / color / mirror / Atom feed
From: Martin <martin.dowie@btopenworld.com>
Subject: Re: newbie problem
Date: Wed, 13 May 2009 11:51:05 -0700 (PDT)
Date: 2009-05-13T11:51:05-07:00	[thread overview]
Message-ID: <5e500136-c9a5-4fca-8e7c-63d5bd09cb71@o20g2000vbh.googlegroups.com> (raw)
In-Reply-To: 4a0b0aa2$0$2846$ba620e4c@news.skynet.be

On May 13, 7:00 pm, Olivier Scalbert <olivier.scalb...@algosyn.com>
wrote:
> Finally I have done some changes. Als_Create is now a procedure.
>
> Here is the code:
>
> --------------------------------------
> -- adasound.ads
> --------------------------------------
> private with Ada.Sequential_Io;
>
> package adasound is
>
>      type Amplitude_T is new Float;
>      type Frequency_T is new Float;
>      type Time_T      is new Float;
>
>      type Stereo_Amplitude_T is record
>          Left : Amplitude_T;
>          Right: Amplitude_T;
>      end record;
>
>      type Als_File_T is limited private;
>
>      procedure Als_Create(Als_File: out Als_File_T; File_Name: String);
>      procedure Als_Write(Als_File: Als_File_T; Stereo_Amplitude:
> Stereo_Amplitude_T);
>      procedure Als_Close(Als_File: out Als_File_T);
>
> private
>      package Stereo_Amplitude_Io is new Ada.Sequential_Io
> (Stereo_Amplitude_T);
>
>      type Als_File_T is record
>          File_Type: Stereo_Amplitude_Io.File_Type;
>          -- perhaps more stuff later
>      end record;
>
> end adasound;
>
> --------------------------------------
> -- adasound.adb
> --------------------------------------
> package body adasound is
>
> procedure Als_Create(Als_File: out Als_File_T; File_Name: String) is
>      File: Stereo_Amplitude_Io.File_Type;
> begin
>      Stereo_Amplitude_Io.Create(Als_File.File_Type,
> Stereo_Amplitude_Io.Out_File, File_Name);
> end Als_Create;
>
> procedure Als_Write(Als_File: Als_File_T; Stereo_Amplitude:
> Stereo_Amplitude_T) is
> begin
>      Stereo_Amplitude_Io.Write(Als_File.File_Type, Stereo_Amplitude);
> end Als_Write;
>
> procedure Als_Close(Als_File: out Als_File_T) is
> begin
>      Stereo_Amplitude_Io.Close(Als_File.File_Type);
> end Als_Close;
>
> end adasound;
>
> --------------------------------------
> -- driver.adb
> --------------------------------------
> with adasound;
> use adasound;
>
> procedure driver is
>      Als_File : Als_File_T;
>      Stereo : Stereo_Amplitude_T;
>      Sample_Rate : constant Integer := 44_100;
>      Nb_Seconds  : constant Integer :=  3_600;
> begin
>      Stereo.Left  := 0.0;
>      Stereo.Right := 0.0;
>      Als_Create(Als_File, "test.als");
>      for i in 1..Sample_Rate * Nb_Seconds loop
>          Als_Write(Als_File, Stereo);
>      end loop;
>      Als_Close(Als_File);
> end driver;
>
> I do not know if the design is better or not but at least it works.
>
> I am also very pleased with the performance. Of course, it is nearly
> only IO but ...
>
> time ./driver
> real    0m15.648s
> user    0m10.305s
> sys     0m3.364s
>
> ls -l test.als
> -rw-r--r-- 1 ols ols 1270080000 2009-05-13 18:41 test.als
>
> Olivier.

Nice one.

Stylistically, why isn't the package called 'ALS' and then you could
remove the tautological 'Als_' everywhere? Perhaps a root package of
'Audio' and a child package of 'Audio.ALS' - that way you could expand
to support other audio file formats 'Audio.mp3', 'Audio.Wav', etc.

Again a style thing, but '_T' looks rather ugly and isn't common usage
- see the RM, esp the Ada.Container.* hierarchy for naming ideas.

Cheers
-- Martin



  reply	other threads:[~2009-05-13 18:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-13 14:16 newbie problem Olivier Scalbert
2009-05-13 14:54 ` Martin
2009-05-13 15:20   ` Olivier Scalbert
2009-05-13 15:14 ` Adam Beneschan
2009-05-13 15:54   ` Olivier Scalbert
2009-05-13 15:44 ` Ludovic Brenta
2009-05-13 16:03   ` Olivier Scalbert
2009-05-13 18:00 ` Olivier Scalbert
2009-05-13 18:51   ` Martin [this message]
2009-05-13 19:45     ` sjw
2009-05-13 19:48     ` Olivier Scalbert
2009-05-14 19:41       ` sjw
2009-05-15  5:02         ` Olivier Scalbert
2009-05-15  8:05         ` Jean-Pierre Rosen
2009-05-18 10:23         ` Olivier Scalbert
2009-05-18 10:48           ` Martin
2009-05-18 10:54             ` Olivier Scalbert
2009-05-18 10:52           ` Ludovic Brenta
2009-05-18 11:09             ` Olivier Scalbert
2009-05-14 22:39       ` Jeffrey R. Carter
2009-05-14  2:59 ` anon
  -- strict thread matches above, loose matches on Subject: below --
1998-12-05  0:00 Graeme Wallace
1998-12-04  0:00 ` Marin David Condic
1998-12-04  0:00 ` Simon Bracken
1998-12-04  0:00   ` Marin David Condic
1998-12-04  0:00 ` Gautier.DeMontmollin
1998-12-04  0:00 ` David Botton
1998-12-04  0:00 ` Mats Weber
1998-12-05  0:00   ` Matthew Heaney
1998-12-05  0:00 ` Matthew Heaney
1998-12-07  0:00 ` Jeff Carter
replies disabled

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