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-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!o20g2000vbh.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: newbie problem Date: Wed, 13 May 2009 11:51:05 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5e500136-c9a5-4fca-8e7c-63d5bd09cb71@o20g2000vbh.googlegroups.com> References: <4a0ad646$0$2854$ba620e4c@news.skynet.be> <4a0b0aa2$0$2846$ba620e4c@news.skynet.be> NNTP-Posting-Host: 81.156.240.174 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1242240667 26844 127.0.0.1 (13 May 2009 18:51:07 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 13 May 2009 18:51:07 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o20g2000vbh.googlegroups.com; posting-host=81.156.240.174; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.10) Gecko/2009042315 Firefox/3.0.10,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5824 Date: 2009-05-13T11:51:05-07:00 List-Id: On May 13, 7:00=A0pm, Olivier Scalbert 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 > > =A0 =A0 =A0type Amplitude_T is new Float; > =A0 =A0 =A0type Frequency_T is new Float; > =A0 =A0 =A0type Time_T =A0 =A0 =A0is new Float; > > =A0 =A0 =A0type Stereo_Amplitude_T is record > =A0 =A0 =A0 =A0 =A0Left : Amplitude_T; > =A0 =A0 =A0 =A0 =A0Right: Amplitude_T; > =A0 =A0 =A0end record; > > =A0 =A0 =A0type Als_File_T is limited private; > > =A0 =A0 =A0procedure Als_Create(Als_File: out Als_File_T; File_Name: Stri= ng); > =A0 =A0 =A0procedure Als_Write(Als_File: Als_File_T; Stereo_Amplitude: > Stereo_Amplitude_T); > =A0 =A0 =A0procedure Als_Close(Als_File: out Als_File_T); > > private > =A0 =A0 =A0package Stereo_Amplitude_Io is new Ada.Sequential_Io > (Stereo_Amplitude_T); > > =A0 =A0 =A0type Als_File_T is record > =A0 =A0 =A0 =A0 =A0File_Type: Stereo_Amplitude_Io.File_Type; > =A0 =A0 =A0 =A0 =A0-- perhaps more stuff later > =A0 =A0 =A0end record; > > end adasound; > > -------------------------------------- > -- adasound.adb > -------------------------------------- > package body adasound is > > procedure Als_Create(Als_File: out Als_File_T; File_Name: String) is > =A0 =A0 =A0File: Stereo_Amplitude_Io.File_Type; > begin > =A0 =A0 =A0Stereo_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 > =A0 =A0 =A0Stereo_Amplitude_Io.Write(Als_File.File_Type, Stereo_Amplitude= ); > end Als_Write; > > procedure Als_Close(Als_File: out Als_File_T) is > begin > =A0 =A0 =A0Stereo_Amplitude_Io.Close(Als_File.File_Type); > end Als_Close; > > end adasound; > > -------------------------------------- > -- driver.adb > -------------------------------------- > with adasound; > use adasound; > > procedure driver is > =A0 =A0 =A0Als_File : Als_File_T; > =A0 =A0 =A0Stereo : Stereo_Amplitude_T; > =A0 =A0 =A0Sample_Rate : constant Integer :=3D 44_100; > =A0 =A0 =A0Nb_Seconds =A0: constant Integer :=3D =A03_600; > begin > =A0 =A0 =A0Stereo.Left =A0:=3D 0.0; > =A0 =A0 =A0Stereo.Right :=3D 0.0; > =A0 =A0 =A0Als_Create(Als_File, "test.als"); > =A0 =A0 =A0for i in 1..Sample_Rate * Nb_Seconds loop > =A0 =A0 =A0 =A0 =A0Als_Write(Als_File, Stereo); > =A0 =A0 =A0end loop; > =A0 =A0 =A0Als_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 =A0 =A00m15.648s > user =A0 =A00m10.305s > sys =A0 =A0 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