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
361983f7
Commit
361983f7
authored
Jan 17, 2021
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the resource manager example to work with Emscripten.
parent
30b55db6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
4 deletions
+31
-4
research/_examples/resource_manager.c
research/_examples/resource_manager.c
+31
-4
No files found.
research/_examples/resource_manager.c
View file @
361983f7
...
...
@@ -28,6 +28,22 @@ set, each sound will have their own formats and you'll need to do the necessary
#include "../../miniaudio.h"
#include "../miniaudio_engine.h"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
void
main_loop__em
(
void
*
pUserData
)
{
ma_resource_manager
*
pResourceManager
=
(
ma_resource_manager
*
)
pUserData
;
MA_ASSERT
(
pResourceManager
!=
NULL
);
/*
The Emscripten build does not support threading which means we need to process jobs manually. If
there are no jobs needing to be processed this will return immediately with MA_NO_DATA_AVAILABLE.
*/
ma_resource_manager_process_next_job
(
pResourceManager
);
}
#endif
void
data_callback
(
ma_device
*
pDevice
,
void
*
pOutput
,
const
void
*
pInput
,
ma_uint32
frameCount
)
{
ma_data_source_read_pcm_frames
((
ma_data_source
*
)
pDevice
->
pUserData
,
pOutput
,
frameCount
,
NULL
,
MA_TRUE
);
...
...
@@ -71,6 +87,15 @@ int main(int argc, char** argv)
resourceManagerConfig
.
decodedChannels
=
device
.
playback
.
channels
;
resourceManagerConfig
.
decodedSampleRate
=
device
.
sampleRate
;
/*
We're not supporting threading with Emscripten so go ahead and disable threading. It's important
that we set the appropriate flag and also the job thread count to 0.
*/
#ifdef __EMSCRIPTEN__
resourceManagerConfig
.
flags
|=
MA_RESOURCE_MANAGER_FLAG_NO_THREADING
;
resourceManagerConfig
.
jobThreadCount
=
0
;
#endif
result
=
ma_resource_manager_init
(
&
resourceManagerConfig
,
&
resourceManager
);
if
(
result
!=
MA_SUCCESS
)
{
ma_device_uninit
(
&
device
);
...
...
@@ -82,10 +107,9 @@ int main(int argc, char** argv)
result
=
ma_resource_manager_data_source_init
(
&
resourceManager
,
argv
[
1
],
MA_DATA_SOURCE_FLAG_DECODE
|
MA_DATA_SOURCE_FLAG_ASYNC
/*| MA_DATA_SOURCE_FLAG_STREAM*/
,
MA_DATA_SOURCE_FLAG_DECODE
|
MA_DATA_SOURCE_FLAG_ASYNC
|
MA_DATA_SOURCE_FLAG_STREAM
,
NULL
,
/* Async notification. */
&
dataSource
);
if
(
result
!=
MA_SUCCESS
)
{
printf
(
"Failed to load sound
\"
%s
\"
."
,
argv
[
1
]);
return
-
1
;
...
...
@@ -100,9 +124,12 @@ int main(int argc, char** argv)
return
-
1
;
}
printf
(
"Press Enter to quit..."
);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop_arg
(
main_loop__em
,
&
resourceManager
,
0
,
1
);
#else
printf
(
"Press Enter to quit...
\n
"
);
getchar
();
#endif
/* Teardown. */
...
...
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