home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 November / CDVD1105.ISO / Software / Freeware / programare / bass / Delphi / ConTest / ConTest.dpr < prev   
Encoding:
Text File  |  2005-09-14  |  4.4 KB  |  161 lines

  1. program ConTest;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   Windows,
  7.   SysUtils,
  8.   MMSystem,
  9.   Bass in '..\Bass.pas';
  10.  
  11. function IntToFixed(val, digits: Integer): string;
  12. var
  13.   s: string;
  14. begin
  15.   s := IntToStr(val);
  16.   while Length(s) < digits do s := '0' + s;
  17.   Result := s;
  18. end;
  19.  
  20. // display error messages
  21. procedure Error(text: string);
  22. begin
  23.   WriteLn('Error(' + IntToStr(BASS_ErrorGetCode) + '): ' + text);
  24.   BASS_Free;
  25.   Halt(0);
  26. end;
  27.  
  28. var
  29.   chn: DWORD;
  30.   ismod: Boolean;
  31.   time, pos, level, act: DWORD;
  32.   a: Integer;
  33.  
  34. begin
  35.   WriteLn('Simple console mode BASS example : MOD/MPx/OGG/WAV player');
  36.   Writeln('---------------------------------------------------------');
  37.  
  38.   // check that BASS 2.2 was loaded
  39.   if (BASS_GetVersion <> DWORD(MAKELONG(2,2))) then
  40.   begin
  41.     Writeln('BASS version 2.2 was not loaded');
  42.     Exit;
  43.   end;
  44.   if (ParamCount <> 1) then
  45.   begin
  46.     WriteLn(#9 + 'usage: contest <file>');
  47.     Exit;
  48.   end;
  49.  
  50.   // setup output - default device, 44100hz, stereo, 16 bits
  51.   if not BASS_Init(-1, 44100, 0, 0, nil) then
  52.     Error('Can''t initialize device');
  53.  
  54.   // try streaming the file
  55.   chn := BASS_StreamCreateFile(FALSE, PChar(ParamStr(1)), 0, 0, BASS_SAMPLE_LOOP);
  56.   if (chn = 0) then
  57.     chn := BASS_StreamCreateURL(PChar(ParamStr(1)), 0, BASS_SAMPLE_LOOP or BASS_STREAM_META, nil, 0);
  58.   if (chn <> 0) then
  59.   begin
  60.     pos := BASS_ChannelGetLength(chn);
  61.     if (BASS_StreamGetFilePosition(chn, BASS_FILEPOS_DOWNLOAD) <> DWORD(-1)) then
  62.     begin
  63.       // streaming from the internet
  64.       if (pos <> 0) then
  65.         Write('streaming internet file [' + IntToStr(pos) + ' bytes]')
  66.       else
  67.         Write('streaming internet file');
  68.     end
  69.     else
  70.       Write('streaming file [' + IntToStr(pos) + ' bytes]');
  71.     ismod := False;
  72.   end
  73.   else
  74.   begin
  75.     // load the MOD (with looping and sensitive ramping)
  76.     chn := BASS_MusicLoad(FALSE, PChar(ParamStr(1)), 0, 0, BASS_MUSIC_LOOP or BASS_MUSIC_RAMPS or BASS_MUSIC_PRESCAN or BASS_MUSIC_SURROUND, 0);
  77.     if (chn = 0) then
  78.       // not a MOD either
  79.       Error('Can''t play the file');
  80.     // count channels
  81.     a := 0;
  82.     while (BASS_MusicGetAttribute(chn, BASS_MUSIC_ATTRIB_VOL_CHAN + a) <> DWORD(-1)) do
  83.       a := a + 1;
  84.     Write('playing MOD music "' + BASS_MusicGetName(chn) + '" [' + IntToStr(a) + ' chans, ' + IntToStr(BASS_MusicGetOrders(chn)) + ' orders]');
  85.     pos := BASS_ChannelGetLength(chn);
  86.     ismod := True;
  87.   end;
  88.  
  89.     // display the time length
  90.     if (pos > 0) then
  91.   begin
  92.         time := Trunc(BASS_ChannelBytes2Seconds(chn,pos));
  93.         WriteLn(Format(' %d:%.2d', [time div 60, time mod 60]));
  94.   end
  95.   else // no time length available
  96.         WriteLn('');
  97.  
  98.   BASS_ChannelPlay(chn, False);
  99.  
  100.   act := BASS_ChannelIsActive(chn);
  101.   while (*not KeyPressed and*) (act > 0) do
  102.   begin
  103.     // display some stuff and wait a bit
  104.         level := BASS_ChannelGetLevel(chn);
  105.         pos := BASS_ChannelGetPosition(chn);
  106.         time := Trunc(BASS_ChannelBytes2Seconds(chn,pos));
  107.         Write(Format('pos %.9d', [pos]));
  108.         if (ismod) then
  109.     begin
  110.             pos := BASS_MusicGetOrderPosition(chn);
  111.             Write(Format(' (%.3d:%.3d)',[LOWORD(pos),HIWORD(pos)]));
  112.         end;
  113.         Write(Format(' - %d:%.2d - L ', [time div 60,time mod 60]));
  114.  
  115.         if (act=BASS_ACTIVE_STALLED) then // playback has stalled
  116.     begin
  117.             Write(Format('-- buffering : %.5d --',
  118.                 [BASS_StreamGetFilePosition(chn,BASS_FILEPOS_DOWNLOAD)-BASS_StreamGetFilePosition(chn,BASS_FILEPOS_DECODE)]));
  119.         end
  120.     else
  121.     begin
  122.       a := 27204;
  123.       while (a > 200) do
  124.       begin
  125.         if (LOWORD(level) >= a) then
  126.           Write('*')
  127.         else
  128.           Write('-');
  129.         a := a * 2 div 3;
  130.       end;
  131.       Write(' ');
  132.       a := 210;
  133.       while (a < 32768) do
  134.       begin
  135.         if (HIWORD(level) >= a) then
  136.           Write('*')
  137.         else
  138.           Write('-');
  139.         a := a * 3 div 2;
  140.       end;
  141.         end;
  142.         Write(Format(' R - cpu %.2f%%' + #13, [BASS_GetCPU]));
  143.         Sleep(50);
  144.  
  145.     // Needs to update act to the current Active
  146.     // status for the look to react accordingly
  147.     act := BASS_ChannelIsActive(chn);
  148.   end;
  149.   WriteLn('                                                                   ');
  150.  
  151.   // wind the frequency down...
  152.   BASS_ChannelSlideAttributes(chn,1000,-1,-101,500);
  153.   Sleep(300);
  154.   // ...and fade-out to avoid a "click"
  155.   BASS_ChannelSlideAttributes(chn,-1,-2,-101,200);
  156.   while (BASS_ChannelIsSliding(chn) <> 0) do
  157.     Sleep(1);
  158.  
  159.   BASS_Free();
  160. end.
  161.