From: Olivier Scalbert <olivier.scalbert@algosyn.com>
Subject: Re: newbie problem
Date: Wed, 13 May 2009 20:00:04 +0200
Date: 2009-05-13T20:00:04+02:00 [thread overview]
Message-ID: <4a0b0aa2$0$2846$ba620e4c@news.skynet.be> (raw)
In-Reply-To: <4a0ad646$0$2854$ba620e4c@news.skynet.be>
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.
next prev parent reply other threads:[~2009-05-13 18:00 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 [this message]
2009-05-13 18:51 ` Martin
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 ` David Botton
1998-12-04 0:00 ` Gautier.DeMontmollin
1998-12-04 0:00 ` Mats Weber
1998-12-05 0:00 ` Matthew Heaney
1998-12-04 0:00 ` Simon Bracken
1998-12-04 0:00 ` Marin David Condic
1998-12-04 0:00 ` Marin David Condic
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