home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 554 / JUIN / DIGITEST.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-07  |  7KB  |  241 lines

  1. Program RAWDigitalOutput;
  2.  
  3. (*************************************************************************)
  4. (*                                                                       *)
  5. (*  Programmed by David Dahl                                             *)
  6. (*  This program and all routines are PUBLIC DOMAIN.                     *)
  7. (*                                                                       *)
  8. (*  If you use any of these routines in your own programs, I would       *)
  9. (*  appreciate an acknowledgement in the docs and/or program.            *)
  10. (*                                                                       *)
  11. (*************************************************************************)
  12.  
  13. Uses  CRT,
  14.       Digital;
  15.  
  16. Type  String4  = String[4];
  17.       String35 = String[35];
  18.  
  19. Const MaxDevices = 9;
  20.  
  21.       DeviceCommand  : Array [1..MaxDevices] of String4 =
  22.                         ('-L1',  '-L2',  '-L3',  '-L4',
  23.                          '-P' ,  '-PM',
  24.                          '-A' ,  '-SB',  '-GUS' );
  25.  
  26.       DeviceName     : Array [1..MaxDevices] of String35 =
  27.                         ('LPT DAC on LPT1',
  28.                          'LPT DAC on LPT2',
  29.                          'LPT DAC on LPT3',
  30.                          'LPT DAC on LPT4',
  31.                          'PC Speaker (Polled Mode)',
  32.                          'PC Speaker (Pulse Width Modulated)',
  33.                          'Adlib / SoundBlaster FM',
  34.                          'SoundBlaster DAC',
  35.                          'Gravis UltraSound');
  36.  
  37.       SignedUnsigned  : Array [False .. True] of String35 =
  38.                          ('Unsigned Sample',
  39.                           'Signed Sample');
  40.  
  41.  
  42. {-[ Return An All Capaitalized String ]-----------------------------------}
  43. Function UpString (StringIn : String) : String;
  44. Var TempString : String;
  45.     Counter    : Byte;
  46. Begin
  47.      TempString := '';
  48.  
  49.      For Counter := 1 to Length (StringIn) do
  50.          TempString := TempString + UpCase(StringIn[Counter]);
  51.  
  52.      UpString := TempString;
  53. End;
  54. {-[ Check If File Exists ]------------------------------------------------}
  55. Function FileExists (FileName : String) : Boolean;
  56. Var F : File;
  57. Begin
  58.      {$I-}
  59.      Assign (F, FileName);
  60.      Reset(F);
  61.      Close(F);
  62.      {$I+}
  63.      FileExists := (IOResult = 0) And (FileName <> '');
  64. End;
  65. {=[ Comand Line Parameter Decode ]========================================}
  66. Function FindOutPutDevice : DeviceType;
  67. Var Counter       : Byte;
  68.     DeviceCounter : Byte;
  69.     Found         : Boolean;
  70.     Device        : DeviceType;
  71. Begin
  72.      Counter := 1;
  73.      Found   := False;
  74.      Device  := PcSpeaker;
  75.  
  76.      While (Counter <= ParamCount) AND Not(Found) do
  77.      Begin
  78.           For DeviceCounter := 1 To MaxDevices do
  79.               If UpString(ParamStr(Counter)) =
  80.                  DeviceCommand[DeviceCounter] Then
  81.               Begin
  82.                    Device := DeviceType(DeviceCounter - 1);
  83.                    Found  := True;
  84.               End;
  85.  
  86.           Inc(Counter);
  87.      End;
  88.  
  89.      FindOutPutDevice := Device;
  90. End;
  91. Function FindRawFileName : String;
  92. Var FileNameFound : String;
  93.     TempName      : String;
  94.     Found         : Boolean;
  95.     Counter       : Byte;
  96. Begin
  97.      FileNameFound   := '';
  98.  
  99.      Counter := 1;
  100.      Found   := False;
  101.  
  102.      While (Counter <= ParamCount) AND Not(Found) do
  103.      Begin
  104.           TempName := UpString(ParamStr(Counter));
  105.  
  106.           If TempName[1] <> '-' Then
  107.           Begin
  108.                FileNameFound := TempName;
  109.                Found         := True;
  110.           End;
  111.  
  112.           Inc (Counter);
  113.      End;
  114.  
  115.      FindRawFileName := FileNameFound;
  116. End;
  117. Function FindPlayBackRate : Word;
  118. Var RateString : String;
  119.     Rate       : Word;
  120.     Found      : Boolean;
  121.     Counter    : Byte;
  122.     ErrorCode  : Integer;
  123. Begin
  124.      Rate := 22000;
  125.  
  126.      Counter := 1;
  127.      Found   := False;
  128.  
  129.      While (Counter <= ParamCount) AND Not(Found) do
  130.      Begin
  131.           RateString := UpString(ParamStr(Counter));
  132.  
  133.           If Copy(RateString,1,2) = '-F' Then
  134.           Begin
  135.                RateString := Copy(RateString,3,Length(RateString)-2);
  136.  
  137.                Val (RateString, Rate, ErrorCode);
  138.  
  139.                If ErrorCode <> 0 Then
  140.                Begin
  141.                     Rate := 22000;
  142.                     Writeln ('Error In Frequency. Using Default');
  143.                End;
  144.  
  145.                Found := True;
  146.           End;
  147.  
  148.           Inc (Counter);
  149.      End;
  150.  
  151.      If Rate < 18
  152.      Then
  153.          Rate := 18
  154.      Else
  155.          If Rate > 44100 Then
  156.             Rate := 44100;
  157.  
  158.      FindPlayBackRate := Rate;
  159. End;
  160.  
  161. Function SignedSample : Boolean;
  162. Var Found   : Boolean;
  163.     Counter : Word;
  164. Begin
  165.      SignedSample := False;
  166.  
  167.      Found   := False;
  168.      Counter := 1;
  169.  
  170.      While (Counter <= ParamCount) AND Not(Found) do
  171.      Begin
  172.           If UpString(ParamStr(Counter)) = '-S' Then
  173.           Begin
  174.                SignedSample := True;
  175.                Found        := True;
  176.           End;
  177.  
  178.           Inc(Counter);
  179.      End;
  180. End;
  181. {=[ Main Program ]========================================================}
  182. Var SampleName : String;
  183.     SampleRate : Word;
  184.     OutDevice  : DeviceType;
  185. Begin
  186.      Writeln;
  187.      Writeln ('RAW Sound File Player V0.07');
  188.      Writeln ('Programmed By David Dahl');
  189.      Writeln ('Thanks to Emil Gilliam for Adlib digital output information');
  190.      Writeln ('This Program is PUBLIC DOMAIN');
  191.  
  192.      If ParamCount <> 0 Then
  193.      Begin
  194.           SampleRate := FindPlayBackRate;
  195.           SampleName := FindRawFileName;
  196.           OutDevice  := FindOutPutDevice;
  197.  
  198.           Writeln;
  199.           
  200.           If SampleName <> '' Then
  201.           Begin
  202.                Writeln ('Raw File   : ',SampleName);
  203.                Writeln ('Format     : ',SignedUnsigned[SignedSample]);
  204.                Writeln ('Sample Rate: ',SampleRate);
  205.                Writeln ('Device     : ',DeviceName[Ord(OutDevice)+1]);
  206.  
  207.                If FileExists (SampleName) Then
  208.                Begin
  209.                     SetOutputDevice  (OutDevice, SignedSample);
  210.  
  211.                     PlayRAWSoundFile (SampleName, SampleRate);
  212.                End
  213.                Else
  214.                    Writeln ('Sound File Not Found.');
  215.           End
  216.           Else
  217.               Writeln ('Filename Not Specified.');
  218.      End
  219.      Else
  220.      Begin
  221.           Writeln;
  222.           Writeln ('USAGE:');
  223.           Writeln (ParamStr(0),' [SWITCHES] <RAW DATA FILE>');
  224.           Writeln;
  225.           Writeln ('SWITCHES:');
  226.           Writeln (' -P      PC Speaker, Polled (Default)');
  227.           Writeln (' -L1     LPT DAC on LPT 1');
  228.           Writeln (' -L2     LPT DAC on LPT 2');
  229.           Writeln (' -L3     LPT DAC on LPT 3');
  230.           Writeln (' -L4     LPT DAC on LPT 4');
  231.           Writeln (' -A      Adlib/Sound Blaster FM');
  232.           Writeln;
  233.           Writeln (' -S      Signed Sample (Unsigned Default)');
  234.           Writeln;
  235.           Writeln (' -FXXXXX Frequency Of Sample. XXXXX can be any integer ',
  236.                    'between 18 to 44100');
  237.           Writeln ('         (22000 Default)');
  238.      End;
  239.  
  240.      CleanUp;
  241. End.