Skip to content

Commit

Permalink
Add support for audio queries: fix permissions on SoundRaw* + add ata…
Browse files Browse the repository at this point in the history
…ri_env test
  • Loading branch information
gkennickell committed Nov 28, 2024
1 parent 9caf22c commit 7a28271
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
12 changes: 12 additions & 0 deletions docs/cpp-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ ale::Action a = legal_actions[rand() % legal_actions.size()];
float reward = ale.act(a);
```

An optional sound observation is provided. To enable, set the associated environment parameter:

```cpp
ale.setBool("sound_obs", True);
```

Once enabled, the sound observation may be obtained by calling:

```cpp
ale.getAudio()
```

Finally, one can check whether the episode has terminated using the function `ale.game_over()`. With these functions one can already implement a very simple agent that plays randomly for one episode:

```cpp
Expand Down
4 changes: 2 additions & 2 deletions src/ale/common/SoundRaw.cxx
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ void SoundRaw::set(uint16_t addr, uint8_t value, int cycle)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundRaw::process(uint8_t* buffer, uint32_t samples)
{
// Process all the audio register updates up to this frame
// Process all the audio register updates up to this frame
// Set audio registers
uint32_t regSize = myRegWriteQueue.size();
for(uint32_t i = 0; i < regSize; ++i) {
TIARegister& info = myRegWriteQueue.front();
myTIASound.set(info.addr, info.value);
myRegWriteQueue.pop_front();
}

// Process audio registers
myTIASound.process(buffer, samples);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ale/common/SoundRaw.hxx
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private:
// Indicates the cycle when a sound register was last set
int myLastRegisterSetCycle;

// Queue of TIA register writes
// Queue of TIA register writes
std::deque<TIARegister> myRegWriteQueue;
};

Expand Down
2 changes: 1 addition & 1 deletion src/ale/python/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(
game sounds. This will lock emulation to the ROMs specified FPS
If `rgb_array` we'll return the `rgb` key in step metadata with
the current environment RGB frame.
sound_obs: bool => Add teh sound from the frame to the observation.
sound_obs: bool => Add the sound from the frame to the observation.
Note:
- The game must be installed, see ale-import-roms, or ale-py-roms.
Expand Down
9 changes: 9 additions & 0 deletions tests/python/test_atari_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,12 @@ def test_gym_compliance(tetris_env):
check_env(tetris_env.unwrapped, skip_render_check=True)

assert len(caught_warnings) == 0, [w.message for w in caught_warnings]


def test_sound_obs():
env = gymnasium.make("ALE/MsPacman-v5", sound_obs=True)

with warnings.catch_warnings(record=True) as caught_warnings:
check_env(env.unwrapped, skip_render_check=True)

assert caught_warnings == [], [caught.message.args[0] for caught in caught_warnings]

0 comments on commit 7a28271

Please sign in to comment.