comp.lang.ada
 help / color / mirror / Atom feed
From: anon@anon.org (anon)
Subject: Re: newbie problem
Date: Thu, 14 May 2009 02:59:56 GMT
Date: 2009-05-14T02:59:56+00:00	[thread overview]
Message-ID: <MOLOl.226656$4m1.181585@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: 4a0ad646$0$2854$ba620e4c@news.skynet.be

In order to create a hidden structures, the easies is to insert the IO into the 
body, but you may have to create your own "File_Type" in the spec file.  But 
another version is to use extra files and packages to hide the IO. There are a 
few others ways but the more you try to hide a package or the operations of 
that package the more complex the Ada packages and structures can become.  

--
-- sound.ads  -- Type used in Sound.IO
--
package Sound is

  pragma Pure ( Sound ) ;

  type Amplitude_Type is new Float ;
  type Frequency_Type is new Float ;
  type Time_Type      is new Float ;

  type Stereo_Amplitude_Type is record
                               Left : Amplitude_Type ;
                               Right: Amplitude_Type ;
                             end record ;
end Sound ;
--
-- Sound-io.ads
--
with Ada.Sequential_IO ;

package Sound.IO is new Ada.Sequential_IO ( Stereo_Amplitude_Type ) ;

--------------------------------------
-- adasound.ads
--------------------------------------
with Sound ;
with Sound.IO ;

package AdaSound is

     procedure Als_Create ( Als_File  : in out Sound.IO.File_Type ; 
                            File_Name : String ) ;

     procedure Als_Write ( Als_File : in out Sound.IO.File_Type ; 
                           Value    : Sound.Stereo_Amplitude_Type ) ;

     procedure Als_Close  ( Als_File : in out Sound.IO.File_Type ) ;

end AdaSound ;
--------------------------------------
-- adasound.adb
--------------------------------------
with Sound ;
with Sound.IO ;

package body adasound is

  procedure Als_Create ( Als_File : in out Sound.IO.File_Type ; 
                         File_Name: String     ) is
      File : Sound.IO.File_Type ;
    begin
      Sound.IO.Create ( Als_File, Sound.IO.Out_File, File_Name ) ;
    end Als_Create ;

  procedure Als_Write ( Als_File : in out Sound.IO.File_Type ; 
                        Value    : Sound.Stereo_Amplitude_Type ) is
    begin
      Sound.IO.Write ( Als_File, Value ) ;
    end Als_Write ;

  procedure Als_Close ( Als_File: in out Sound.IO.File_Type ) is
    begin
      Sound.IO.Close ( Als_File ) ;
    end Als_Close ;
end adasound ;
--------------------------------------
-- driver.adb
--------------------------------------

with Sound ;
with Sound.IO ;

with AdaSound ;

procedure driver is
     Sample_Rate : constant Integer := 44_100 ;
     Nb_Seconds  : constant Integer :=  3_600 ;

     Als_File    : Sound.IO.File_Type ;
     Stereo      : Sound.Stereo_Amplitude_Type ;

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;


In <4a0ad646$0$2854$ba620e4c@news.skynet.be>, Olivier Scalbert <olivier.scalbert@algosyn.com> writes:
>Hello,
>
>I am doing a little package and I have problems just for writing the 
>specification ...
>
>In short, this package should offer services to create sequential files 
>that store stereo sound samples.
>
>Here is the code:
>
>with Sequential_Io; -- Problem 2  not nice should be hidden but how ?
>
>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 private;
>
>     function  Als_Create(File_Name: String) return Als_File_T;
>     procedure Als_Write(Als_File: Als_File_T; Stereo_Amplitude: 
>Stereo_Amplitude_T);
>     procedure Als_Close(Als_File: Als_File_T);
>
>private
>     package Stereo_Amplitude_Io is new Sequential_Io (Stereo_Amplitude_T);
>
>     type Als_File_T is record
>         File_Type: Stereo_Amplitude_Io.File_Type; -- Problem 1 !!
>         -- perhaps more stuff later
>     end record;
>
>end adasound;
>
>Problem 1: it does not compile !
>adasound.ads:23:10: completion of nonlimited type cannot be limited
>adasound.ads:23:10: component "File_Type" of type "Als_File_T" has 
>limited type
>
>Problem 2: how to avoid the first "with Sequential_Io;" ?
>
>Thanks to help me !
>
>Olivier.




  parent reply	other threads:[~2009-05-14  2:59 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
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 [this message]
  -- strict thread matches above, loose matches on Subject: below --
1998-12-05  0:00 Graeme Wallace
1998-12-04  0:00 ` Mats Weber
1998-12-05  0:00   ` Matthew Heaney
1998-12-04  0:00 ` David Botton
1998-12-04  0:00 ` Gautier.DeMontmollin
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