Skip to content

Commit

Permalink
Modified audio_manager (and unit tests for same) to use DEFAULT_AUDIO…
Browse files Browse the repository at this point in the history
…_* constants instead of hard-coding default values
  • Loading branch information
Josh Glover committed Mar 19, 2010
1 parent e4ce628 commit caf91ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 14 additions & 5 deletions src/audio/audio_manager.h
Expand Up @@ -46,6 +46,15 @@ namespace audio
*/
static const u_int16 AUDIO_S16 = 16;

/**
* @name Default values for audio manager
*/
static const int DEFAULT_AUDIO_BUFFERS = 4096;
static const int DEFAULT_AUDIO_CHANNELS = 2;
static const u_int16 DEFAULT_AUDIO_FORMAT = AUDIO_S16;
static const int DEFAULT_AUDIO_MIXCHANNELS = 16;
static const int DEFAULT_AUDIO_RATE = 44100;

/** Audio access is made through this class.
* This static class manages audio system configuration.
*/
Expand Down Expand Up @@ -81,28 +90,28 @@ namespace audio
/** Sets the audio rate (in Hz)
* @param audio_rate audio rate in samples per second (Hz)
*/
static bool set_audio_rate(const int audio_rate = 44100);
static bool set_audio_rate(const int audio_rate = DEFAULT_AUDIO_RATE);

/** Sets the audio format
* @param audio_format audio format; see
* http://www.libsdl.org/cgi/docwiki.cgi/SDL_AudioSpec
*/
static bool set_audio_format(const u_int16 audio_format = AUDIO_S16);
static bool set_audio_format(const u_int16 audio_format = DEFAULT_AUDIO_FORMAT);

/** Sets the number of audio channels
* @param audio_channels number of audio channels
*/
static bool set_audio_channels(const int audio_channels = 2);
static bool set_audio_channels(const int audio_channels = DEFAULT_AUDIO_CHANNELS);

/** Sets the audio buffer size
* @param audio_buffers size of audio buffer, in bytes
*/
static bool set_audio_buffers(const int audio_buffers = 4096);
static bool set_audio_buffers(const int audio_buffers = DEFAULT_AUDIO_BUFFERS);

/** Sets the number of audio mixer channels
* @param audio_mixchannels number of audio mixer channels
*/
static bool set_audio_mixchannels(const int audio_mixchannels = 16);
static bool set_audio_mixchannels(const int audio_mixchannels = DEFAULT_AUDIO_MIXCHANNELS);

protected:
static int audio_rate_;
Expand Down
10 changes: 5 additions & 5 deletions src/audio/test_audio_manager.cc
Expand Up @@ -61,31 +61,31 @@ namespace audio
TEST_F(audio_manager_Test, set_audio_rate_Default) {
audio_manager::set_audio_rate();

EXPECT_EQ(44100, audio_manager::get_audio_rate());
EXPECT_EQ(DEFAULT_AUDIO_RATE, audio_manager::get_audio_rate());
}

TEST_F(audio_manager_Test, set_audio_format_Default) {
audio_manager::set_audio_format();

EXPECT_EQ(AUDIO_S16, audio_manager::get_audio_format());
EXPECT_EQ(DEFAULT_AUDIO_FORMAT, audio_manager::get_audio_format());
}

TEST_F(audio_manager_Test, set_audio_channels_Default) {
audio_manager::set_audio_channels();

EXPECT_EQ(2, audio_manager::get_audio_channels());
EXPECT_EQ(DEFAULT_AUDIO_CHANNELS, audio_manager::get_audio_channels());
}

TEST_F(audio_manager_Test, set_audio_buffers_Default) {
audio_manager::set_audio_buffers();

EXPECT_EQ(4096, audio_manager::get_audio_buffers());
EXPECT_EQ(DEFAULT_AUDIO_BUFFERS, audio_manager::get_audio_buffers());
}

TEST_F(audio_manager_Test, set_audio_mixchannels_Default) {
audio_manager::set_audio_mixchannels();

EXPECT_EQ(16, audio_manager::get_audio_mixchannels());
EXPECT_EQ(DEFAULT_AUDIO_MIXCHANNELS, audio_manager::get_audio_mixchannels());
}

TEST_F(audio_manager_Test, set_audio_rate) {
Expand Down

0 comments on commit caf91ea

Please sign in to comment.