home *** CD-ROM | disk | FTP | other *** search
- /* BASS Simple Console Test (rev.4), copyright (c) 1999 Ian Luck.
- =================================================================
- Imports: bass.lib, kernel32.lib, user32.lib, winmm.lib
- */
-
- #include <windows.h>
- #include <mmsystem.h>
- #include <conio.h>
- #include "bass.h"
-
- /* display error messages */
- void Error(char *text)
- {
- printf("Error(%d): %s\n",BASS_ErrorGetCode(),text);
- BASS_Free();
- ExitProcess(0);
- }
-
- static DWORD starttime;
-
- /* Looping synchronizer, resets the clock */
- void CALLBACK LoopSync(HSYNC handle, DWORD channel, DWORD data)
- {
- starttime=timeGetTime(); // reset the clock
- }
-
- void main(int argc, char **argv)
- {
- HMUSIC mod;
- HSTREAM str;
- DWORD time,pos,level;
- int a,freq;
- BOOL mono=FALSE;
-
- printf("Simple console mode BASS example : MOD/MP3/WAV player\n"
- "-----------------------------------------------------\n");
-
- /* Check that BASS 0.6 was loaded */
- if (BASS_GetVersion()!=MAKELONG(0,6)) {
- printf("BASS version 0.6 was not loaded\n");
- return;
- }
-
- if (argc<2 || argc>3) {
- printf("\tusage: contest <file> [low]\n\tlow = lower quality, uses less CPU.\n");
- return;
- }
-
- /* setup output - default device, 44100hz (22050 if "low" quality), stereo, 16 bits */
- freq=(argv[2] && !stricmp(argv[2],"low"))?22050:44100;
- if (!BASS_Init(-1,freq,0,GetForegroundWindow()))
- Error("Can't initialize device");
- /* Try streaming the file */
- if (str=BASS_StreamCreateFile(FALSE,argv[1],0,0,0)) {
- /* Check if the stream is mono (for the level indicator) */
- mono=BASS_ChannelGetFlags(str)&BASS_SAMPLE_MONO;
- BASS_ChannelSetSync(str,BASS_SYNC_END,0,&LoopSync);
- } else {
- /* load the MOD (with looping and normal ramping) */
- if (!(mod=BASS_MusicLoad(FALSE,argv[1],0,0,BASS_MUSIC_LOOP|BASS_MUSIC_RAMP)))
- /* not a MOD either */
- Error("Can't play the file");
- BASS_ChannelSetSync(mod,BASS_SYNC_END,0,&LoopSync);
- }
-
- BASS_Start();
- if (str)
- BASS_StreamPlay(str,FALSE,BASS_SAMPLE_LOOP);
- else
- BASS_MusicPlay(mod);
- starttime=timeGetTime();
- printf("now playing... press any key to stop\n");
-
- /* NOTE: some compilers don't support _kbhit */
- while (!_kbhit() && BASS_ChannelIsActive(str?str:mod)) {
- /* display some stuff and wait a bit */
- time=timeGetTime()-starttime;
- level=BASS_ChannelGetLevel(str?str:mod);
- pos=BASS_ChannelGetPosition(str?str:mod);
- if (str)
- printf("pos %09d - time %d:%02d - L ",pos,time/60000,(time/1000)%60);
- else
- printf("pos %03d:%03d - time %d:%02d - L ",LOWORD(pos),HIWORD(pos),time/60000,(time/1000)%60);
- for (a=93;a;a=a*2/3) putchar(LOWORD(level)>=a?'*':'-');
- putchar(' ');
- if (mono)
- for (a=1;a<128;a+=a-(a>>1)) putchar(LOWORD(level)>=a?'*':'-');
- else
- for (a=1;a<128;a+=a-(a>>1)) putchar(HIWORD(level)>=a?'*':'-');
- printf(" R - cpu %d%% \r",BASS_GetCPU());
- Sleep(50);
- }
- printf(" \r");
-
- /* get the frequency... and wind it down */
- BASS_ChannelGetAttributes(str?str:mod,&freq,NULL,NULL);
- level=freq/40;
- for (;freq>2000;freq-=level) {
- BASS_ChannelSetAttributes(str?str:mod,freq,-1,-101);
- Sleep(5);
- }
-
- /* fade-out to avoid a "click" */
- BASS_SlideVolume(0,1,BASS_SLIDE_DIGITAL);
- while (BASS_IsSliding()) ;
-
- BASS_Free();
- }
-