Skip to content

Commit

Permalink
Add snd_pcm_pause hook
Browse files Browse the repository at this point in the history
  • Loading branch information
clementgallet committed May 1, 2020
1 parent ca12341 commit d6cbdcd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Add a Dockerfile and instructions to build the container
* Add sync setting for Hollow Knight
* Add epoll_wait hook (#321)
* Add snd_pcm_pause hook (#321)

### Changed

Expand Down
32 changes: 32 additions & 0 deletions src/library/audio/alsa/pcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ DEFINE_ORIG_POINTER(snd_pcm_mmap_commit);
DEFINE_ORIG_POINTER(snd_pcm_start);
DEFINE_ORIG_POINTER(snd_pcm_drop);
DEFINE_ORIG_POINTER(snd_pcm_state);
DEFINE_ORIG_POINTER(snd_pcm_hw_params_can_pause);
DEFINE_ORIG_POINTER(snd_pcm_pause);
DEFINE_ORIG_POINTER(snd_pcm_resume);
DEFINE_ORIG_POINTER(snd_pcm_wait);
DEFINE_ORIG_POINTER(snd_pcm_delay);
Expand Down Expand Up @@ -255,6 +257,36 @@ int snd_pcm_drop(snd_pcm_t *pcm)
return 0;
}

int snd_pcm_hw_params_can_pause(const snd_pcm_hw_params_t *params)
{
if (GlobalState::isNative()) {
LINK_NAMESPACE_GLOBAL(snd_pcm_hw_params_can_pause);
return orig::snd_pcm_hw_params_can_pause(params);
}

DEBUGLOGCALL(LCF_SOUND);
return 1;
}

int snd_pcm_pause(snd_pcm_t *pcm, int enable)
{
if (GlobalState::isNative()) {
LINK_NAMESPACE_GLOBAL(snd_pcm_state);
return orig::snd_pcm_state(pcm);
}

DEBUGLOGCALL(LCF_SOUND);

int sourceId = reinterpret_cast<intptr_t>(pcm);
auto source = audiocontext.getSource(sourceId);
if (enable)
source->state = AudioSource::SOURCE_PAUSED;
else
source->state = AudioSource::SOURCE_PLAYING;

return 0;
}

snd_pcm_state_t snd_pcm_state(snd_pcm_t *pcm)
{
if (GlobalState::isNative()) {
Expand Down
3 changes: 2 additions & 1 deletion src/library/audio/alsa/pcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ OVERRIDE int snd_pcm_reset(snd_pcm_t *pcm);
OVERRIDE int snd_pcm_start(snd_pcm_t *pcm);
OVERRIDE int snd_pcm_drop(snd_pcm_t *pcm);
// int snd_pcm_drain(snd_pcm_t *pcm);
// int snd_pcm_pause(snd_pcm_t *pcm, int enable);
OVERRIDE int snd_pcm_hw_params_can_pause(const snd_pcm_hw_params_t *params);
OVERRIDE int snd_pcm_pause(snd_pcm_t *pcm, int enable);
OVERRIDE snd_pcm_state_t snd_pcm_state(snd_pcm_t *pcm);
// int snd_pcm_hwsync(snd_pcm_t *pcm);
OVERRIDE int snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp);
Expand Down

0 comments on commit d6cbdcd

Please sign in to comment.