2 #define WIN32_LEAN_AND_MEAN
8 inline void Sleep(uint32_t ms
)
10 struct timespec ts
, rem
;
11 ts
.tv_sec
= ms
/ 1000;
12 ts
.tv_nsec
= (ms
% 1000) * 1000000;
13 while(nanosleep(&ts
, &rem
) == -1 && errno
== EINTR
)
27 int main(int argc
, char *argv
[])
29 alure::DeviceManager
*devMgr
= alure::DeviceManager::get();
31 alure::Device
*dev
= devMgr
->openPlayback();
32 std::cout
<< "Opened \""<<dev
->getName(alure::PlaybackDevType_Basic
)<<"\"" <<std::endl
;
34 if(!dev
->queryExtension("ALC_SOFT_HRTF"))
36 std::cerr
<< "ALC_SOFT_HRTF not supported!" <<std::endl
;
40 // Enumerate (and display) the available HRTFs
41 std::cout
<< "Available HRTFs:" <<std::endl
;
42 std::vector
<std::string
> hrtf_names
= dev
->enumerateHRTFNames();
43 for(const std::string
&name
: hrtf_names
)
44 std::cout
<< " "<<name
<<std::endl
;
47 std::vector
<ALCint
> attrs
;
48 attrs
.push_back(ALC_HRTF_SOFT
);
49 attrs
.push_back(ALC_TRUE
);
50 if(argc
-i
> 1 && strcasecmp(argv
[i
], "-hrtf") == 0)
52 // Find the given HRTF and add it to the attributes list
53 auto iter
= std::find_if(hrtf_names
.begin(), hrtf_names
.end(),
54 [argv
, i
](const std::string
&name
) -> bool
55 { return name
== argv
[i
+1]; }
57 if(iter
== hrtf_names
.end())
58 std::cerr
<< "HRTF \""<<argv
[i
+1]<<"\" not found" <<std::endl
;
61 attrs
.push_back(ALC_HRTF_ID_SOFT
);
62 attrs
.push_back(std::distance(hrtf_names
.begin(), iter
));
67 alure::Context
*ctx
= dev
->createContext(attrs
.data());
68 alure::Context::MakeCurrent(ctx
);
70 std::cout
<< "Using HRTF \""<<dev
->getCurrentHRTF()<<"\"" <<std::endl
;
74 if(argc
-i
> 1 && strcasecmp(argv
[i
], "-hrtf") == 0)
76 // Find the given HRTF and reset the device using it
77 auto iter
= std::find_if(hrtf_names
.begin(), hrtf_names
.end(),
78 [argv
, i
](const std::string
&name
) -> bool
79 { return name
== argv
[i
+1]; }
81 if(iter
== hrtf_names
.end())
82 std::cerr
<< "HRTF \""<<argv
[i
+1]<<"\" not found" <<std::endl
;
86 attrs
.push_back(ALC_HRTF_SOFT
);
87 attrs
.push_back(ALC_TRUE
);
88 attrs
.push_back(ALC_HRTF_ID_SOFT
);
89 attrs
.push_back(std::distance(hrtf_names
.begin(), iter
));
90 dev
->reset(attrs
.data());
92 std::cout
<< "Using HRTF \""<<dev
->getCurrentHRTF()<<"\"" <<std::endl
;
99 alure::SharedPtr
<alure::Decoder
> decoder(ctx
->createDecoder(argv
[i
]));
100 alure::Source
*source
= ctx
->getSource();
102 source
->play(decoder
, 32768, 4);
103 std::cout
<< "Playing "<<argv
[i
]<<" ("<<alure::GetSampleTypeName(decoder
->getSampleType())<<", "
104 <<alure::GetChannelConfigName(decoder
->getChannelConfig())<<", "
105 <<decoder
->getFrequency()<<"hz)" <<std::endl
;
107 float invfreq
= 1.0f
/ decoder
->getFrequency();
108 while(source
->isPlaying())
110 std::cout
<< "\r "<<std::setiosflags(std::ios::fixed
)<<std::setprecision(2)<<
111 (source
->getOffset()*invfreq
)<<" / "<<(decoder
->getLength()*invfreq
);
116 std::cout
<<std::endl
;
122 alure::Context::MakeCurrent(0);