-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaymod.cpp
More file actions
84 lines (75 loc) · 2.21 KB
/
playmod.cpp
File metadata and controls
84 lines (75 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
Modified from "BASS simple console player" distributed in BASSMOD library.
Copyright (c) 1999-2012 Un4seen Developments Ltd.
*/
#include "Main.h"
#include "bass.h"
#pragma comment (lib, "bass.lib")
// display error messages
void Error(const char *text)
{
printf("Error(%d): %s\n",BASS_ErrorGetCode(),text);
BASS_Free();
exit(0);
}
DWORD WINAPI PlayMod(void* argv)
{
DWORD chan,act,time,level;
BOOL ismod;
QWORD pos;
int a;
// check the correct BASS was loaded
if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
printf("An incorrect version of BASS was loaded");
return 0;
}
// setup output - default device
if (!BASS_Init(-1,44100,0,0,NULL))return 0;
//Error("Can't initialize device");
// try streaming the file
if ((chan=BASS_StreamCreateFile(FALSE,argv,0,0,BASS_SAMPLE_LOOP))) {
pos=BASS_ChannelGetLength(chan,BASS_POS_BYTE);
ismod=FALSE;
} else {
// try loading the MOD (with looping, sensitive ramping, and calculate the duration)
if (!(chan=BASS_MusicLoad(FALSE,argv,0,0,BASS_SAMPLE_LOOP|BASS_MUSIC_RAMPS|BASS_MUSIC_PRESCAN,1)))
// not a MOD either
//Error("Can't play the file");
return 0;
else { // count channels
float dummy;
for (a=0;BASS_ChannelGetAttribute(chan,BASS_ATTRIB_MUSIC_VOL_CHAN+a,&dummy);a++);
}
pos=BASS_ChannelGetLength(chan,BASS_POS_BYTE);
ismod=TRUE;
}
BASS_ChannelPlay(chan,FALSE);
while (act=BASS_ChannelIsActive(chan)){
WaitForSingleObject(hMusicMutex, INFINITE);
if(noSound){
ReleaseMutex(hMusicMutex);
break;
}
ReleaseMutex(hMusicMutex);
Sleep(200);
}
// wind the frequency down...
//BASS_ChannelSlideAttribute(chan,BASS_ATTRIB_FREQ,1000,500);
//Sleep(300);
// ...and fade-out to avoid a "click"
BASS_ChannelSlideAttribute(chan,BASS_ATTRIB_VOL,-1,200);
// wait for slide to finish
while (BASS_ChannelIsSliding(chan,0)) Sleep(1);
BASS_Free();
while(1)
{
WaitForSingleObject(hMusicMutex, INFINITE);
if(!noSound){
ReleaseMutex(hMusicMutex);
PlayMod(argv);
return 1;
}
ReleaseMutex(hMusicMutex);
}
return 1;
}