Skip to content

Commit 4451a49

Browse files
committed
Add setVolume method to Sound
1 parent 929a805 commit 4451a49

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

include/scratchcpp/sound.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class LIBSCRATCHCPP_EXPORT Sound : public Asset
2525
int sampleCount() const;
2626
void setSampleCount(int newSampleCount);
2727

28+
virtual void setVolume(double volume);
29+
2830
virtual void start();
2931
virtual void stop();
3032

src/scratch/sound.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ void Sound::setSampleCount(int newSampleCount)
3939
impl->sampleCount = newSampleCount;
4040
}
4141

42+
/*! Sets the volume percentage of the sound. */
43+
void Sound::setVolume(double volume)
44+
{
45+
impl->player->setVolume(volume / 100);
46+
}
47+
4248
/*! Starts the playback of the sound. */
4349
void Sound::start()
4450
{

test/assets/sound_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ TEST_F(SoundTest, ProcessData)
6464
sound.setData(3, dataPtr);
6565
}
6666

67+
TEST_F(SoundTest, SetVolume)
68+
{
69+
Sound sound("sound1", "a", "wav");
70+
71+
EXPECT_CALL(*m_player, setVolume(0.5604));
72+
sound.setVolume(56.04);
73+
}
74+
6775
TEST_F(SoundTest, Start)
6876
{
6977
Sound sound("sound1", "a", "wav");

0 commit comments

Comments
 (0)