Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
d9d9901e
Commit
d9d9901e
authored
Apr 25, 2018
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for Emscripten.
parent
3301b179
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
1 deletion
+62
-1
tests/README.md
tests/README.md
+13
-1
tests/mal_test_0.c
tests/mal_test_0.c
+48
-0
tests/mal_test_0_build_emscripten.bat
tests/mal_test_0_build_emscripten.bat
+1
-0
No files found.
tests/README.md
View file @
d9d9901e
Building
========
Build and run these test from this folder. Example:
Build and run these test from this folder. Example:
clear && ./mal_test_0_build && ./bin/mal_test_0
clear && ./mal_test_0_build && ./bin/mal_test_0
These tests load resources from hard coded paths which point to the "res" folder. These
These tests load resources from hard coded paths which point to the "res" folder. These
paths are based on the assumption that the current directory is where the build files
paths are based on the assumption that the current directory is where the build files
are located.
are located.
\ No newline at end of file
Emscripten
----------
On Windows, you need to move into this directory and run emsdk_env.bat from a command
prompt using an absolute path like "C:
\e
msdk
\e
msdk_env.bat". Note that PowerShell doesn't
work for me for some reason. Then, run the relevant batch file:
mal_test_0_build_emscripten.bat
The output will be placed in the bin folder.
\ No newline at end of file
tests/mal_test_0.c
View file @
d9d9901e
...
@@ -13,6 +13,14 @@
...
@@ -13,6 +13,14 @@
#define MAL_IMPLEMENTATION
#define MAL_IMPLEMENTATION
#include "../mini_al.h"
#include "../mini_al.h"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
void
main_loop__em
()
{
}
#endif
mal_backend
g_Backends
[]
=
{
mal_backend
g_Backends
[]
=
{
mal_backend_wasapi
,
mal_backend_wasapi
,
mal_backend_dsound
,
mal_backend_dsound
,
...
@@ -2209,6 +2217,7 @@ int do_backend_tests()
...
@@ -2209,6 +2217,7 @@ int do_backend_tests()
typedef
struct
typedef
struct
{
{
mal_decoder
*
pDecoder
;
mal_decoder
*
pDecoder
;
mal_sine_wave
*
pSineWave
;
mal_event
endOfPlaybackEvent
;
mal_event
endOfPlaybackEvent
;
}
playback_test_callback_data
;
}
playback_test_callback_data
;
...
@@ -2217,12 +2226,29 @@ mal_uint32 on_send__playback_test(mal_device* pDevice, mal_uint32 frameCount, vo
...
@@ -2217,12 +2226,29 @@ mal_uint32 on_send__playback_test(mal_device* pDevice, mal_uint32 frameCount, vo
playback_test_callback_data
*
pData
=
(
playback_test_callback_data
*
)
pDevice
->
pUserData
;
playback_test_callback_data
*
pData
=
(
playback_test_callback_data
*
)
pDevice
->
pUserData
;
mal_assert
(
pData
!=
NULL
);
mal_assert
(
pData
!=
NULL
);
#if !defined(__EMSCRIPTEN__)
mal_uint64
framesRead
=
mal_decoder_read
(
pData
->
pDecoder
,
frameCount
,
pFrames
);
mal_uint64
framesRead
=
mal_decoder_read
(
pData
->
pDecoder
,
frameCount
,
pFrames
);
if
(
framesRead
==
0
)
{
if
(
framesRead
==
0
)
{
mal_event_signal
(
&
pData
->
endOfPlaybackEvent
);
mal_event_signal
(
&
pData
->
endOfPlaybackEvent
);
}
}
return
(
mal_uint32
)
framesRead
;
return
(
mal_uint32
)
framesRead
;
#else
if
(
pDevice
->
format
==
mal_format_f32
)
{
for
(
mal_uint32
iFrame
=
0
;
iFrame
<
frameCount
;
++
iFrame
)
{
float
sample
;
mal_sine_wave_read
(
pData
->
pSineWave
,
1
,
&
sample
);
for
(
mal_uint32
iChannel
=
0
;
iChannel
<
pDevice
->
channels
;
++
iChannel
)
{
((
float
*
)
pFrames
)[
iFrame
*
pDevice
->
channels
+
iChannel
]
=
sample
;
}
}
return
frameCount
;
}
else
{
return
0
;
}
#endif
}
}
int
do_playback_test
(
mal_backend
backend
)
int
do_playback_test
(
mal_backend
backend
)
...
@@ -2230,11 +2256,13 @@ int do_playback_test(mal_backend backend)
...
@@ -2230,11 +2256,13 @@ int do_playback_test(mal_backend backend)
mal_result
result
=
MAL_SUCCESS
;
mal_result
result
=
MAL_SUCCESS
;
mal_device
device
;
mal_device
device
;
mal_decoder
decoder
;
mal_decoder
decoder
;
mal_sine_wave
sineWave
;
mal_bool32
haveDevice
=
MAL_FALSE
;
mal_bool32
haveDevice
=
MAL_FALSE
;
mal_bool32
haveDecoder
=
MAL_FALSE
;
mal_bool32
haveDecoder
=
MAL_FALSE
;
playback_test_callback_data
callbackData
;
playback_test_callback_data
callbackData
;
callbackData
.
pDecoder
=
&
decoder
;
callbackData
.
pDecoder
=
&
decoder
;
callbackData
.
pSineWave
=
&
sineWave
;
printf
(
"--- %s ---
\n
"
,
mal_get_backend_name
(
backend
));
printf
(
"--- %s ---
\n
"
,
mal_get_backend_name
(
backend
));
...
@@ -2244,6 +2272,10 @@ int do_playback_test(mal_backend backend)
...
@@ -2244,6 +2272,10 @@ int do_playback_test(mal_backend backend)
mal_context_config
contextConfig
=
mal_context_config_init
(
on_log
);
mal_context_config
contextConfig
=
mal_context_config_init
(
on_log
);
mal_device_config
deviceConfig
=
mal_device_config_init_default_playback
(
on_send__playback_test
);
mal_device_config
deviceConfig
=
mal_device_config_init_default_playback
(
on_send__playback_test
);
#if defined(__EMSCRIPTEN__)
deviceConfig
.
format
=
mal_format_f32
;
#endif
result
=
mal_device_init_ex
(
&
backend
,
1
,
&
contextConfig
,
mal_device_type_playback
,
NULL
,
&
deviceConfig
,
&
callbackData
,
&
device
);
result
=
mal_device_init_ex
(
&
backend
,
1
,
&
contextConfig
,
mal_device_type_playback
,
NULL
,
&
deviceConfig
,
&
callbackData
,
&
device
);
if
(
result
==
MAL_SUCCESS
)
{
if
(
result
==
MAL_SUCCESS
)
{
printf
(
"Done
\n
"
);
printf
(
"Done
\n
"
);
...
@@ -2271,6 +2303,7 @@ int do_playback_test(mal_backend backend)
...
@@ -2271,6 +2303,7 @@ int do_playback_test(mal_backend backend)
goto
done
;
goto
done
;
}
}
#if !defined(__EMSCRIPTEN__)
mal_decoder_config
decoderConfig
=
mal_decoder_config_init
(
device
.
format
,
device
.
channels
,
device
.
sampleRate
);
mal_decoder_config
decoderConfig
=
mal_decoder_config_init
(
device
.
format
,
device
.
channels
,
device
.
sampleRate
);
result
=
mal_decoder_init_file
(
"res/sine_s16_mono_48000.wav"
,
&
decoderConfig
,
&
decoder
);
result
=
mal_decoder_init_file
(
"res/sine_s16_mono_48000.wav"
,
&
decoderConfig
,
&
decoder
);
if
(
result
==
MAL_SUCCESS
)
{
if
(
result
==
MAL_SUCCESS
)
{
...
@@ -2280,6 +2313,17 @@ int do_playback_test(mal_backend backend)
...
@@ -2280,6 +2313,17 @@ int do_playback_test(mal_backend backend)
goto
done
;
goto
done
;
}
}
haveDecoder
=
MAL_TRUE
;
haveDecoder
=
MAL_TRUE
;
#else
result
=
mal_sine_wave_init
(
0
.
5
f
,
400
,
device
.
sampleRate
,
&
sineWave
);
if
(
result
==
MAL_SUCCESS
)
{
printf
(
"Done
\n
"
);
}
else
{
printf
(
"Failed to init sine wave.
\n
"
);
goto
done
;
}
#endif
}
}
printf
(
" Press Enter to start playback... "
);
printf
(
" Press Enter to start playback... "
);
...
@@ -2291,6 +2335,10 @@ int do_playback_test(mal_backend backend)
...
@@ -2291,6 +2335,10 @@ int do_playback_test(mal_backend backend)
goto
done
;
goto
done
;
}
}
#if defined(__EMSCRIPTEN__)
emscripten_set_main_loop
(
main_loop__em
,
0
,
1
);
#endif
mal_event_wait
(
&
callbackData
.
endOfPlaybackEvent
);
// Wait for the sound to finish.
mal_event_wait
(
&
callbackData
.
endOfPlaybackEvent
);
// Wait for the sound to finish.
printf
(
"Done
\n
"
);
printf
(
"Done
\n
"
);
}
}
...
...
tests/mal_test_0_build_emscripten.bat
0 → 100644
View file @
d9d9901e
emcc
./mal_test_0.c
-o
./bin/mal_test_0_emscripten.html
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment