Skip to content

Commit

Permalink
Simplify automating closing devices in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Sep 20, 2024
1 parent 5435317 commit 72e6db0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
15 changes: 5 additions & 10 deletions examples/allafplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,16 +877,11 @@ auto main(al::span<std::string_view> args) -> int
}
args = args.subspan(1);

/* A simple RAII container for OpenAL startup and shutdown. */
struct AudioManager {
AudioManager(al::span<std::string_view> &args_)
{
if(InitAL(args_) != 0)
throw std::runtime_error{"Failed to initialize OpenAL"};
}
~AudioManager() { CloseAL(); }
};
AudioManager almgr{args};
if(InitAL(args) != 0)
throw std::runtime_error{"Failed to initialize OpenAL"};
/* A simple RAII container for automating OpenAL shutdown. */
struct AudioManager { ~AudioManager() { CloseAL(); } };
AudioManager almgr;

std::for_each(args.begin(), args.end(), PlayLAF);

Expand Down
18 changes: 6 additions & 12 deletions examples/alstreamcb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,26 +486,20 @@ struct StreamPlayer {

int main(al::span<std::string_view> args)
{
/* A simple RAII container for OpenAL startup and shutdown. */
struct AudioManager {
AudioManager(al::span<std::string_view> &args_)
{
if(InitAL(args_) != 0)
throw std::runtime_error{"Failed to initialize OpenAL"};
}
~AudioManager() { CloseAL(); }
};

/* Print out usage if no arguments were specified */
if(args.size() < 2)
{
fprintf(stderr, "Usage: %.*s [-device <name>] <filenames...>\n", al::sizei(args[0]),
args[0].data());
return 1;
}

args = args.subspan(1);
AudioManager almgr{args};

if(InitAL(args) != 0)
throw std::runtime_error{"Failed to initialize OpenAL"};
/* A simple RAII container for automating OpenAL shutdown. */
struct AudioManager { ~AudioManager() { CloseAL(); } };
AudioManager almgr;

if(!alIsExtensionPresent("AL_SOFT_callback_buffer"))
{
Expand Down

0 comments on commit 72e6db0

Please sign in to comment.