2 * A simple example showing how to load and play a sound.
14 int main(int argc
, char *argv
[])
16 alure::DeviceManager devMgr
= alure::DeviceManager::get();
20 if(argc
> 3 && strcmp(argv
[1], "-device") == 0)
23 dev
= devMgr
.openPlayback(argv
[2], std::nothrow
);
25 std::cerr
<< "Failed to open \""<<argv
[2]<<"\" - trying default" <<std::endl
;
28 dev
= devMgr
.openPlayback();
29 std::cout
<< "Opened \""<<dev
.getName()<<"\"" <<std::endl
;
31 alure::Context ctx
= dev
.createContext();
32 alure::Context::MakeCurrent(ctx
);
34 for(int i
= fileidx
;i
< argc
;i
++)
36 alure::Buffer buffer
= ctx
.getBuffer(argv
[i
]);
37 alure::Source source
= ctx
.createSource();
39 std::cout
<< "Playing "<<argv
[i
]<<" ("<<alure::GetSampleTypeName(buffer
.getSampleType())<<", "
40 <<alure::GetChannelConfigName(buffer
.getChannelConfig())<<", "
41 <<buffer
.getFrequency()<<"hz)" <<std::endl
;
43 float invfreq
= 1.0f
/ buffer
.getFrequency();
44 while(source
.isPlaying())
46 std::cout
<< "\r "<<std::setiosflags(std::ios::fixed
)<<std::setprecision(2)<<
47 source
.getSecOffset().count()<<" / "<<(buffer
.getLength()*invfreq
);
49 std::this_thread::sleep_for(std::chrono::milliseconds(25));
55 ctx
.removeBuffer(buffer
);
58 alure::Context::MakeCurrent(nullptr);