Skip to content

Commit

Permalink
Minor fixes in Audio plugin. Fixed test scripts. (#91)
Browse files Browse the repository at this point in the history
* Minor fixes in Audio plugin. Fixed test scripts.

* fixup! Minor fixes in Audio plugin. Fixed test scripts.
  • Loading branch information
MiranDMC authored Mar 4, 2024
1 parent 27cb5dc commit a77505c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 26 deletions.
18 changes: 13 additions & 5 deletions cleo_plugins/Audio/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class Audio
public:
static CSoundSystem soundSystem;

enum eStreamAction
{
Stop,
Play,
Pause,
Resume,
};

Audio()
{
auto cleoVer = CLEO_GetVersion();
Expand Down Expand Up @@ -113,12 +121,12 @@ class Audio
{
switch (action)
{
case 0: stream->Stop(); break;
case 1: stream->Play(); break;
case 2: stream->Pause(); break;
case 3: stream->Resume(); break;
case eStreamAction::Stop: stream->Stop(); break;
case eStreamAction::Play: stream->Play(); break;
case eStreamAction::Pause: stream->Pause(); break;
case eStreamAction::Resume: stream->Resume(); break;
default:
LOG_WARNING(thread, "Unknown audiostream's action (%d) in script %s", action, ScriptInfoStr(thread).c_str());
LOG_WARNING(thread, "Unknown AudioStreamAction (%d) in script %s", action, ScriptInfoStr(thread).c_str());
}
}

Expand Down
6 changes: 4 additions & 2 deletions cleo_plugins/Audio/CAudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ void CAudioStream::SetProgress(float value)

float CAudioStream::GetProgress() const
{
auto total = BASS_ChannelGetLength(streamInternal, BASS_POS_BYTE);
auto bytePos = BASS_ChannelGetPosition(streamInternal, BASS_POS_BYTE);
auto total = BASS_ChannelGetLength(streamInternal, BASS_POS_BYTE); // returns -1 on error
auto bytePos = BASS_ChannelGetPosition(streamInternal, BASS_POS_BYTE); // returns -1 on error

if (bytePos == -1) bytePos = 0; // error or not available yet

float progress = (float)bytePos / total;
progress = std::clamp(progress, 0.0f, 1.0f);
Expand Down
25 changes: 13 additions & 12 deletions tests/cleo_tests/Audio/0AB9.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{$CLEO .s}
{$USE debug}
{$USE memory}
{$USE audio}
var 0@ : Integer
var 1@ : Integer
var 2@ : Integer
Expand All @@ -23,7 +24,7 @@ trace "0AB9 (get_audio_stream_state)"
// load the file
wait 0
if
load_audio_stream ".\Ding.mp3" store_to 0@
load_audio_stream ".\Ding.mp3" {store_to} 0@
then
trace "~g~~h~~h~0AB9 (get_audio_stream_state), #0 PASSED"
else
Expand All @@ -33,27 +34,27 @@ end

// get state
wait 0
0AB9: get_audio_stream_state 0@ store_to 1@ // tested opcode
0AB9: get_audio_stream_state 0@ {store_to} 1@ // tested opcode
if
1@ == 2 // paused by default
1@ == 2 // AudioStreamState.Paused
then
trace "~g~~h~~h~0AB9 (get_audio_stream_state), #1 PASSED"
else
breakpoint "~r~~h~~h~~h~0AB9 (get_audio_stream_state), #1 FAILED!~n~%d Expected~n~%d Occured" -1 1@
breakpoint "~r~~h~~h~~h~0AB9 (get_audio_stream_state), #1 FAILED!~n~%d Expected~n~%d Occured" 2 1@
end


// set new state
wait 0
set_audio_stream_state 0@ state AudioStreamState.Play
set_audio_stream_state 0@ {state} AudioStreamAction.Play
trace "~g~~h~~h~0AAD (set_audio_stream_state), #2 PASSED"


// get updated state
wait 0
0AB9: get_audio_stream_state 0@ store_to 1@ // tested opcode
0AB9: get_audio_stream_state 0@ {store_to} 1@ // tested opcode
if
1@ == 1 // play
1@ == 1 // AudioStreamState.Playing
then
trace "~g~~h~~h~0AB9 (get_audio_stream_state), #3 PASSED"
else
Expand All @@ -62,14 +63,14 @@ end


// check if state updated after playback end
wait 300 // Ding.mp3 is 0.25s long
0AB9: get_audio_stream_state 0@ store_to 1@ // tested opcode
wait 400 // Ding.mp3 is 0.25s long
0AB9: get_audio_stream_state 0@ {store_to} 1@ // tested opcode
if
1@ == -1 // AudioStreamState.Stop
1@ == -1 // AudioStreamState.Stopped
then
trace "~g~~h~~h~0AB9 (get_audio_stream_state), #3 PASSED"
trace "~g~~h~~h~0AB9 (get_audio_stream_state), #4 PASSED"
else
breakpoint "~r~~h~~h~~h~0AB9 (get_audio_stream_state), #3 FAILED!~n~%d Expected~n~%d Occured" -1 1@
breakpoint "~r~~h~~h~~h~0AB9 (get_audio_stream_state), #4 FAILED!~n~%d Expected~n~%d Occured" -1 1@
end


Expand Down
9 changes: 5 additions & 4 deletions tests/cleo_tests/Audio/0AC0.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{$CLEO .s}
{$USE debug}
{$USE memory}
{$USE audio}
var 0@ : Integer
var 1@ : Integer
var 2@ : Integer
Expand Down Expand Up @@ -39,15 +40,15 @@ trace "~g~~h~~h~0AC0 (set_audio_stream_looped), #1 PASSED"

// start playback
wait 0
set_audio_stream_state 0@ state AudioStreamState.Play
set_audio_stream_state 0@ state AudioStreamAction.Play
trace "~g~~h~~h~0AC0 (set_audio_stream_looped), #2 PASSED"


// get updated state
wait 0
get_audio_stream_state 0@ store_to 1@
if
1@ == 1 // play
1@ == 1 // AudioStreamState.Playing
then
trace "~g~~h~~h~0AC0 (set_audio_stream_looped), #3 PASSED"
else
Expand All @@ -59,7 +60,7 @@ end
wait 400 // Ding.mp3 is 0.25s long
get_audio_stream_state 0@ store_to 1@
if
1@ == 1 // play
1@ == 1 // AudioStreamState.Playing
then
trace "~g~~h~~h~0AC0 (set_audio_stream_looped), #4 PASSED"
else
Expand All @@ -69,7 +70,7 @@ end

// stop playback
wait 0
set_audio_stream_state 0@ state AudioStreamState.Stop
set_audio_stream_state 0@ state AudioStreamAction.Stop
trace "~g~~h~~h~0AC0 (set_audio_stream_looped), #5 PASSED"


Expand Down
5 changes: 3 additions & 2 deletions tests/cleo_tests/Audio/0AC2.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{$CLEO .s}
{$USE debug}
{$USE memory}
{$USE audio}
var 0@ : Integer
var 1@ : Integer
var 2@ : Integer
Expand Down Expand Up @@ -57,7 +58,7 @@ trace "~g~~h~~h~0AC2 (set_play_3d_audio_stream_at_coords), #3 PASSED"
wait 0
print_big_formatted "LEFT________________________" {time} 300 {style} TextStyle.MiddleSmaller
set_audio_stream_volume 0@ volume 10.0
set_audio_stream_state 0@ state AudioStreamState.Play
set_audio_stream_state 0@ state AudioStreamAction.Play
wait 250
trace "~g~~h~~h~0AC2 (set_play_3d_audio_stream_at_coords), #4 PASSED"

Expand All @@ -78,7 +79,7 @@ trace "~g~~h~~h~0AC2 (set_play_3d_audio_stream_at_coords), #3 PASSED"
wait 0
print_big_formatted "________________________RIGHT" {time} 300 {style} TextStyle.MiddleSmaller
set_audio_stream_volume 0@ volume 10.0
set_audio_stream_state 0@ state AudioStreamState.Play
set_audio_stream_state 0@ state AudioStreamAction.Play
wait 250
trace "~g~~h~~h~0AC2 (set_play_3d_audio_stream_at_coords), #4 PASSED"

Expand Down
3 changes: 2 additions & 1 deletion tests/cleo_tests/Audio/0AC4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ nop
{$CLEO .s}
{$USE debug}
{$USE memory}
{$USE audio}
var 0@ : Integer
var 1@ : Integer
var 2@ : Integer
Expand Down Expand Up @@ -53,7 +54,7 @@ trace "~g~~h~~h~0AC4 (set_play_3d_audio_stream_at_char), #2 PASSED"
// play the sound
wait 0
print_big_formatted "AT PLAYER CHAR" {time} 300 {style} TextStyle.MiddleSmaller
set_audio_stream_state 0@ state AudioStreamState.Play
set_audio_stream_state 0@ state AudioStreamAction.Play
wait 250
trace "~g~~h~~h~0AC4 (set_play_3d_audio_stream_at_char), #3 PASSED"

Expand Down

0 comments on commit a77505c

Please sign in to comment.