TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Mime-Version:
1.0
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Subject:
From:
Jesse Farmer <[log in to unmask]>
Date:
Wed, 15 Nov 2000 00:15:31 -0500
Content-Type:
text/plain; charset="us-ascii"; format=flowed
Reply-To:
Jesse Farmer <[log in to unmask]>
Parts/Attachments:
text/plain (229 lines)
can someone spot the error in the code here?
when you compile and run this you will notice that the time for the eighth
note is way off.  Any ideas as to why this is?
We suspect some kind of decimal precision error but not positive about that.
Any help would be greatly appreciated.

**********begin code****************
-- -----------------------------------------------------
--  NAME:                               TestTime.adb
--  VERSION:                    1.00a
--  AUTHOR:                             Stephane Richard
-- -----------------------------------------------------
    with Ada.Real_Time;
    with Gnat.IO;
    procedure BPMPPQTest2 is
       -- ----------------
       --  WORK VARIABLES
       -- ----------------
       Time_Start               : Ada.Real_Time.Time;
       Time_End                 : Ada.Real_Time.Time;
       Time_Difference          : Ada.Real_Time.Time_Span;
       Time_Delta               : Ada.Real_Time.Time_Span;
       Delta_Whole_Note         : Ada.Real_Time.Time_Span;
       Delta_Half_Note          : Ada.Real_Time.Time_Span;
       Delta_Quarter_Note       : Ada.Real_Time.Time_Span;
       Delta_Eighth_Note        : Ada.Real_Time.Time_Span;
       Delta_Sixteenth_Note     : Ada.Real_Time.Time_Span;
       Delta_ThirtySecond_Note  : Ada.Real_Time.Time_Span;
       Delta_SixtyFourth_Note   : Ada.Real_Time.Time_Span;
       Delta_128th_Note         : Ada.Real_Time.Time_Span;
       Time_Duration            : Duration;
       Time_Delta_Duration      : Duration;
       Next_Time                : Ada.Real_Time.Time;
       -- -----------
       --  CONSTANTS
       -- -----------
       Ticks_Per_Minute         : constant := 17_400;
       Number_Of_Ticks          : constant := 60.0;
       Seconds_Per_Minute       : constant := 60.0;
       Pulse_Per_Quarter        : constant := 480;  -- this cna be changed
to 240 or 120 ...
       Beats_Per_Minutes        : constant := 140.0;
       -- ---------------------
       --  FORMULAIC CONSTANTS
       -- ---------------------
       Whole_Note               : constant := Pulse_Per_Quarter * 4;
       Half_Note                : constant := Pulse_Per_Quarter * 2;
       Quarter_Note             : constant := Pulse_Per_Quarter;
       Eighth_Note              : constant := Pulse_Per_Quarter / 2;
       Sixteenth_Note           : constant := Pulse_Per_Quarter / 4;  --
being realistic
       ThirtySecond_Note        : constant := Pulse_Per_Quarter / 8;  --
being optomistic
       SixtyFourth_Note         : constant := Pulse_Per_Quarter / 16; --
being crazy lol
       HundredTwentyEighth_Note : constant := Pulse_Per_Quarter / 32; --
being on Silicon Graphics lol

       Seconds_Per_Tick         : constant Ada.Real_Time.Time_Span :=
          Ada.Real_Time.To_Time_Span (Seconds_Per_Minute / Ticks_Per_Minute);

       use type Ada.Real_Time.Time;

    begin
       -- -------------------------------------------------
       --  Time Difference Calculations for note durations
       -- -------------------------------------------------
       Time_Delta              :=
Ada.Real_Time.To_Time_Span(Duration((1.0/(Beats_Per_Minutes/Number_Of_Ticks)
)/Pulse_Per_Quarter));
       Time_Delta_Duration     := Ada.Real_Time.To_Duration(Time_Delta);
       Delta_Whole_Note        :=
Ada.Real_Time.To_Time_Span(Time_Delta_Duration * Whole_Note);
       Delta_Half_Note         :=
Ada.Real_Time.To_Time_Span(Time_Delta_Duration * Half_Note);
       Delta_Quarter_Note      :=
Ada.Real_Time.To_Time_Span(Time_Delta_Duration * Quarter_Note);
       Delta_Eighth_Note       :=
Ada.Real_Time.To_Time_Span(Time_Delta_Duration * Eighth_Note);
       Delta_Sixteenth_Note    :=
Ada.Real_Time.To_Time_Span(Time_Delta_Duration * Sixteenth_Note);
       Delta_ThirtySecond_Note :=
Ada.Real_Time.To_Time_Span(Time_Delta_Duration * ThirtySecond_Note);
       Delta_SixtyFourth_Note  :=
Ada.Real_Time.To_Time_Span(Time_Delta_Duration * SixtyFourth_Note);
       Delta_128th_Note        :=
Ada.Real_Time.To_Time_Span(Time_Delta_Duration * HundredTwentyEighth_Note);

       -- ------------------------------
       --  TEST 01: Loop 20 whole notes
       -- ------------------------------
    --      for I in 1 .. 10 loop
           -- ---------------------------
           --  PRINT RELPORT HEADER INFO
           -- ---------------------------
       Gnat.IO.Put("TEST LOOP: ");
       --Gnat.IO.Put(I);
       Gnat.IO.Put_Line("---------------------------------------------------
Gnat.IO.Put_Line("---------------------------------------------------------");
       Gnat.IO.Put("note values");



    -- --------------------
      --  1 WHOLE NOTE DELAY
      -- --------------------
       Time_Start         := Ada.Real_Time.Clock;
       Next_Time       := Time_Start + Delta_Whole_Note;
       delay until Next_Time;
       Time_End        := Ada.Real_Time.Clock;
       Time_Difference := Time_End - Time_Start;
       Time_Duration   := Ada.Real_Time.To_Duration(Time_Difference);
       Gnat.IO.Put("Time Difference: ");
       Gnat.IO.Put(Duration'Image (Time_Duration));
       Gnat.IO.Put_Line("For one whole note");
      -- --------------------
      --  2 HALF NOTE DELAYS
      -- --------------------
       Time_Start         := Ada.Real_Time.Clock;
       Next_Time       := Next_Time + Delta_Half_Note;
       delay until Next_Time;
       Next_Time       := Next_Time + Delta_Half_Note;
       delay until Next_Time;
       Time_End        := Ada.Real_Time.Clock;
       Time_Difference := Time_End - Time_Start;
       Time_Duration   := Ada.Real_Time.To_Duration(Time_Difference);
       Gnat.IO.Put("Time Difference: ");
       Gnat.IO.Put(Duration'Image (Time_Duration));
       Gnat.IO.Put_Line("For 2 Half note");
      -- -----------------------
      --  4 QUARTER NOTE DELAYS
      -- -----------------------
       Time_Start         := Ada.Real_Time.Clock;
       Next_Time       := Next_Time + Delta_Quarter_Note;
       for J in 1..4 loop
          delay until Next_Time;
          Next_Time   := Next_Time + Delta_Quarter_Note;
       end loop;
       Time_End        := Ada.Real_Time.Clock;
       Time_Difference := Time_End - Time_Start;
       Time_Duration   := Ada.Real_Time.To_Duration(Time_Difference);
       Gnat.IO.Put("Time Difference: ");
       Gnat.IO.Put(Duration'Image (Time_Duration));
       Gnat.IO.Put_Line("For 4 Quarter note Delay");
      -- ----------------------
      --  8 EIGHTH NOTE DELAYS
      -- ----------------------
       Time_Start         := Ada.Real_Time.Clock;
       Next_Time       := Next_Time + Delta_Eighth_Note;
       for J in 1..8 loop
          delay until Next_Time;
          Next_Time   := Next_Time + Delta_Eighth_Note;
       end loop;
       Time_End        := Ada.Real_Time.Clock;
       Time_Difference := Time_End - Time_Start;
       Time_Duration   := Ada.Real_Time.To_Duration(Time_Difference);
       Gnat.IO.Put("Time Difference: ");
       Gnat.IO.Put(Duration'Image (Time_Duration));
       Gnat.IO.Put_Line("For 8 8th note Delay");
      -- --------------------------
      --  16 SIXTEENTH NOTE DELAYS
      -- --------------------------
       Time_Start         := Ada.Real_Time.Clock;
       Next_Time       := Next_Time + Delta_Sixteenth_Note;
       for J in 1..16 loop
          delay until Next_Time;
          Next_Time   := Next_Time + Delta_Sixteenth_Note;
       end loop;
       Time_End        := Ada.Real_Time.Clock;
       Time_Difference := Time_End - Time_Start;
       Time_Duration   := Ada.Real_Time.To_Duration(Time_Difference);
       Gnat.IO.Put("Time Difference: ");
       Gnat.IO.Put(Duration'Image (Time_Duration));
       Gnat.IO.Put_Line("For 16 16th note Delay");
      -- ------------------------------
      --  32 THIRTY SECOND NOTE DELAYS
      -- ------------------------------
       Time_Start         := Ada.Real_Time.Clock;
       Next_Time       := Next_Time + Delta_ThirtySecond_Note;
       for J in 1..32 loop
          delay until Next_Time;
          Next_Time   := Next_Time + Delta_ThirtySecond_Note;
       end loop;
       Time_End        := Ada.Real_Time.Clock;
       Time_Difference := Time_End - Time_Start;
       Time_Duration   := Ada.Real_Time.To_Duration(Time_Difference);
       Gnat.IO.Put("Time Difference: ");
       Gnat.IO.Put(Duration'Image (Time_Duration));
       Gnat.IO.Put_Line("For 32 32th note Delay");
      -- -----------------------------
      --  64 SIXTY FOURTH NOTE DELAYS
      -- -----------------------------
       Time_Start         := Ada.Real_Time.Clock;
       Next_Time       := Next_Time + Delta_SixtyFourth_Note;
       for J in 1..64 loop
          delay until Next_Time;
          Next_Time   := Next_Time + Delta_SixtyFourth_Note;
       end loop;
       Time_End        := Ada.Real_Time.Clock;
       Time_Difference := Time_End - Time_Start;
       Time_Duration   := Ada.Real_Time.To_Duration(Time_Difference);
       Gnat.IO.Put("Time Difference: ");
       Gnat.IO.Put(Duration'Image (Time_Duration));
       Gnat.IO.Put_Line("For 64 64th note Delay");

        --my mod 128th
       Time_Start         := Ada.Real_Time.Clock;
       Next_Time       := Next_Time + Delta_128th_Note;
       for J in 1..128 loop
          delay until Next_Time;
          Next_Time   := Next_Time + Delta_128th_Note;
       end loop;
       Time_End        := Ada.Real_Time.Clock;
       Time_Difference := Time_End - Time_Start;
       Time_Duration   := Ada.Real_Time.To_Duration(Time_Difference);
       Gnat.IO.Put("Time Difference: ");
       Gnat.IO.Put(Duration'Image (Time_Duration));
       Gnat.IO.Put_Line("For 128 128th note Delay");



    --      end loop;

       delay 30.0;

    end BPMPPQTest2;

***********end code *************

ATOM RSS1 RSS2