home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 April / Chip CMCD0400.iso / SOFTWARE / Freeware / Programare / Bass / CONTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-26  |  3.2 KB  |  109 lines

  1. /* BASS Simple Console Test (rev.4), copyright (c) 1999 Ian Luck.
  2. =================================================================
  3. Imports: bass.lib, kernel32.lib, user32.lib, winmm.lib
  4. */
  5.  
  6. #include <windows.h>
  7. #include <mmsystem.h>
  8. #include <conio.h>
  9. #include "bass.h"
  10.  
  11. /* display error messages */
  12. void Error(char *text) 
  13. {
  14.     printf("Error(%d): %s\n",BASS_ErrorGetCode(),text);
  15.     BASS_Free();
  16.     ExitProcess(0);
  17. }
  18.  
  19. static DWORD starttime;
  20.  
  21. /* Looping synchronizer, resets the clock */
  22. void CALLBACK LoopSync(HSYNC handle, DWORD channel, DWORD data)
  23. {
  24.     starttime=timeGetTime();    // reset the clock
  25. }
  26.  
  27. void main(int argc, char **argv)
  28. {
  29.     HMUSIC mod;
  30.     HSTREAM str;
  31.     DWORD time,pos,level;
  32.     int a,freq;
  33.     BOOL mono=FALSE;
  34.  
  35.     printf("Simple console mode BASS example : MOD/MP3/WAV player\n"
  36.             "-----------------------------------------------------\n");
  37.  
  38.     /* Check that BASS 0.6 was loaded */
  39.     if (BASS_GetVersion()!=MAKELONG(0,6)) {
  40.         printf("BASS version 0.6 was not loaded\n");
  41.         return;
  42.     }
  43.  
  44.     if (argc<2 || argc>3) {
  45.         printf("\tusage: contest <file> [low]\n\tlow = lower quality, uses less CPU.\n");
  46.         return;
  47.     }
  48.  
  49.     /* setup output - default device, 44100hz (22050 if "low" quality), stereo, 16 bits */
  50.     freq=(argv[2] && !stricmp(argv[2],"low"))?22050:44100;
  51.     if (!BASS_Init(-1,freq,0,GetForegroundWindow()))
  52.         Error("Can't initialize device");
  53.     /* Try streaming the file */
  54.     if (str=BASS_StreamCreateFile(FALSE,argv[1],0,0,0)) {
  55.         /* Check if the stream is mono (for the level indicator) */
  56.         mono=BASS_ChannelGetFlags(str)&BASS_SAMPLE_MONO;
  57.         BASS_ChannelSetSync(str,BASS_SYNC_END,0,&LoopSync);
  58.     } else {
  59.         /* load the MOD (with looping and normal ramping) */
  60.         if (!(mod=BASS_MusicLoad(FALSE,argv[1],0,0,BASS_MUSIC_LOOP|BASS_MUSIC_RAMP)))
  61.             /* not a MOD either */
  62.             Error("Can't play the file");
  63.         BASS_ChannelSetSync(mod,BASS_SYNC_END,0,&LoopSync);
  64.     }
  65.  
  66.     BASS_Start();
  67.     if (str)
  68.         BASS_StreamPlay(str,FALSE,BASS_SAMPLE_LOOP);
  69.     else
  70.         BASS_MusicPlay(mod);
  71.     starttime=timeGetTime();
  72.     printf("now playing... press any key to stop\n");
  73.  
  74.     /* NOTE: some compilers don't support _kbhit */
  75.     while (!_kbhit() && BASS_ChannelIsActive(str?str:mod)) {
  76.         /* display some stuff and wait a bit */
  77.         time=timeGetTime()-starttime;
  78.         level=BASS_ChannelGetLevel(str?str:mod);
  79.         pos=BASS_ChannelGetPosition(str?str:mod);
  80.         if (str)
  81.             printf("pos %09d - time %d:%02d - L ",pos,time/60000,(time/1000)%60);
  82.         else
  83.             printf("pos %03d:%03d - time %d:%02d - L ",LOWORD(pos),HIWORD(pos),time/60000,(time/1000)%60);
  84.         for (a=93;a;a=a*2/3) putchar(LOWORD(level)>=a?'*':'-');
  85.         putchar(' ');
  86.         if (mono)
  87.             for (a=1;a<128;a+=a-(a>>1)) putchar(LOWORD(level)>=a?'*':'-');
  88.         else
  89.             for (a=1;a<128;a+=a-(a>>1)) putchar(HIWORD(level)>=a?'*':'-');
  90.         printf(" R - cpu %d%%  \r",BASS_GetCPU());
  91.         Sleep(50);
  92.     }
  93.     printf("                                                                 \r");
  94.  
  95.     /* get the frequency... and wind it down */
  96.     BASS_ChannelGetAttributes(str?str:mod,&freq,NULL,NULL);
  97.     level=freq/40;
  98.     for (;freq>2000;freq-=level) {
  99.         BASS_ChannelSetAttributes(str?str:mod,freq,-1,-101);
  100.         Sleep(5);
  101.     }
  102.  
  103.     /* fade-out to avoid a "click" */
  104.     BASS_SlideVolume(0,1,BASS_SLIDE_DIGITAL);
  105.     while (BASS_IsSliding()) ;
  106.  
  107.     BASS_Free();
  108. }
  109.