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
5effa71e
Commit
5effa71e
authored
Sep 15, 2020
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor refactor.
parent
0a732338
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
69 deletions
+76
-69
research/miniaudio_engine.h
research/miniaudio_engine.h
+76
-69
No files found.
research/miniaudio_engine.h
View file @
5effa71e
...
@@ -8324,89 +8324,96 @@ static void ma_sound_mix_wait(ma_sound* pSound)
...
@@ -8324,89 +8324,96 @@ static void ma_sound_mix_wait(ma_sound* pSound)
}
}
}
}
static
void
ma_engine_mix_sound_internal
(
ma_engine
*
pEngine
,
ma_sound_group
*
pGroup
,
ma_sound
*
pSound
,
ma_uint64
frameCount
)
static
void
ma_engine_mix_sound
(
ma_engine
*
pEngine
,
ma_sound_group
*
pGroup
,
ma_sound
*
pSound
,
ma_uint64
frameCount
)
{
{
MA_ASSERT
(
pEngine
!=
NULL
);
ma_result
result
=
MA_SUCCESS
;
MA_ASSERT
(
pGroup
!=
NULL
);
ma_uint64
framesProcessed
;
MA_ASSERT
(
pSound
!=
NULL
);
c89atomic_exchange_32
(
&
pSound
->
isMixing
,
MA_TRUE
);
/* This must be done before checking the isPlaying state. */
/* Don't do anything if we're not playing. */
{
if
(
pSound
->
isPlaying
==
MA_FALSE
)
{
if
(
pSound
->
isPlaying
)
{
return
;
ma_result
result
=
MA_SUCCESS
;
}
ma_uint64
framesProcessed
;
/* If we're marked at the end we need to stop the sound and do nothing. */
/* If we're marked at the end we need to stop the sound and do nothing. */
if
(
pSound
->
atEnd
)
{
if
(
!
pSound
->
atEnd
)
{
ma_sound_stop_internal
(
pSound
);
/* If we're seeking, do so now before reading. */
return
;
if
(
pSound
->
seekTarget
!=
MA_SEEK_TARGET_NONE
)
{
}
pSound
->
seekTarget
=
MA_SEEK_TARGET_NONE
;
ma_data_source_seek_to_pcm_frame
(
pSound
->
pDataSource
,
pSound
->
seekTarget
);
/* If we're seeking, do so now before reading. */
if
(
pSound
->
seekTarget
!=
MA_SEEK_TARGET_NONE
)
{
pSound
->
seekTarget
=
MA_SEEK_TARGET_NONE
;
ma_data_source_seek_to_pcm_frame
(
pSound
->
pDataSource
,
pSound
->
seekTarget
);
/* Any time-dependant effects need to have their times updated. */
/* Any time-dependant effects need to have their times updated. */
ma_engine_effect_set_time
(
&
pSound
->
effect
,
pSound
->
seekTarget
);
ma_engine_effect_set_time
(
&
pSound
->
effect
,
pSound
->
seekTarget
);
}
}
/* If the sound is being delayed we don't want to mix anything, nor do we want to advance time forward from the perspective of the data source. */
/* If the sound is being delayed we don't want to mix anything, nor do we want to advance time forward from the perspective of the data source. */
if
((
pSound
->
runningTimeInEngineFrames
+
frameCount
)
>
pSound
->
startDelayInEngineFrames
)
{
if
((
pSound
->
runningTimeInEngineFrames
+
frameCount
)
>
pSound
->
startDelayInEngineFrames
)
{
/* We're not delayed so we can mix or seek. In order to get frame-exact playback timing we need to start mixing from an offset. */
/* We're not delayed so we can mix or seek. In order to get frame-exact playback timing we need to start mixing from an offset. */
ma_uint64
currentTimeInFrames
;
ma_uint64
currentTimeInFrames
;
ma_uint64
offsetInFrames
;
ma_uint64
offsetInFrames
;
offsetInFrames
=
0
;
offsetInFrames
=
0
;
if
(
pSound
->
startDelayInEngineFrames
>
pSound
->
runningTimeInEngineFrames
)
{
if
(
pSound
->
startDelayInEngineFrames
>
pSound
->
runningTimeInEngineFrames
)
{
offsetInFrames
=
pSound
->
startDelayInEngineFrames
-
pSound
->
runningTimeInEngineFrames
;
offsetInFrames
=
pSound
->
startDelayInEngineFrames
-
pSound
->
runningTimeInEngineFrames
;
}
}
MA_ASSERT
(
offsetInFrames
<
frameCount
);
MA_ASSERT
(
offsetInFrames
<
frameCount
);
/*
/*
An obvious optimization is to skip mixing if the sound is not audible. The problem with this, however, is that the effect may need to update some
An obvious optimization is to skip mixing if the sound is not audible. The problem with this, however, is that the effect may need to update some
internal state such as timing information for things like fades, delays, echos, etc. We're going to always mix the sound if it's active and trust
internal state such as timing information for things like fades, delays, echos, etc. We're going to always mix the sound if it's active and trust
the mixer to optimize the volume = 0 case, and let the effect do it's own internal optimizations in non-audible cases.
the mixer to optimize the volume = 0 case, and let the effect do it's own internal optimizations in non-audible cases.
*/
*/
result
=
ma_mixer_mix_data_source
(
&
pGroup
->
mixer
,
pSound
->
pDataSource
,
offsetInFrames
,
(
frameCount
-
offsetInFrames
),
&
framesProcessed
,
pSound
->
volume
,
&
pSound
->
effect
,
pSound
->
isLooping
);
result
=
ma_mixer_mix_data_source
(
&
pGroup
->
mixer
,
pSound
->
pDataSource
,
offsetInFrames
,
(
frameCount
-
offsetInFrames
),
&
framesProcessed
,
pSound
->
volume
,
&
pSound
->
effect
,
pSound
->
isLooping
);
/* If we reached the end of the sound we'll want to mark it as at the end and stop it. This should never be returned for looping sounds. */
/* If we reached the end of the sound we'll want to mark it as at the end and stop it. This should never be returned for looping sounds. */
if
(
result
==
MA_AT_END
)
{
if
(
result
==
MA_AT_END
)
{
c89atomic_exchange_32
(
&
pSound
->
atEnd
,
MA_TRUE
);
/* This will be set to false in ma_sound_start(). */
c89atomic_exchange_32
(
&
pSound
->
atEnd
,
MA_TRUE
);
/* This will be set to false in ma_sound_start(). */
}
}
/*
/*
For the benefit of the main effect we need to ensure the local time is updated explicitly. This is required for allowing time-based effects to
For the benefit of the main effect we need to ensure the local time is updated explicitly. This is required for allowing time-based effects to
support loop transitions properly.
support loop transitions properly.
*/
*/
result
=
ma_sound_get_cursor_in_pcm_frames
(
pSound
,
&
currentTimeInFrames
);
result
=
ma_sound_get_cursor_in_pcm_frames
(
pSound
,
&
currentTimeInFrames
);
if
(
result
==
MA_SUCCESS
)
{
if
(
result
==
MA_SUCCESS
)
{
ma_engine_effect_set_time
(
&
pSound
->
effect
,
currentTimeInFrames
);
ma_engine_effect_set_time
(
&
pSound
->
effect
,
currentTimeInFrames
);
}
}
pSound
->
runningTimeInEngineFrames
+=
offsetInFrames
+
framesProcessed
;
pSound
->
runningTimeInEngineFrames
+=
offsetInFrames
+
framesProcessed
;
}
else
{
}
else
{
/* The sound hasn't started yet. Just keep advancing time forward, but leave the data source alone. */
/* The sound hasn't started yet. Just keep advancing time forward, but leave the data source alone. */
pSound
->
runningTimeInEngineFrames
+=
frameCount
;
pSound
->
runningTimeInEngineFrames
+=
frameCount
;
}
}
/* If we're stopping after a delay we need to check if the delay has expired and if so, stop for real. */
/* If we're stopping after a delay we need to check if the delay has expired and if so, stop for real. */
if
(
pSound
->
stopDelayInEngineFramesRemaining
>
0
)
{
if
(
pSound
->
stopDelayInEngineFramesRemaining
>
0
)
{
if
(
pSound
->
stopDelayInEngineFramesRemaining
>=
frameCount
)
{
if
(
pSound
->
stopDelayInEngineFramesRemaining
>=
frameCount
)
{
pSound
->
stopDelayInEngineFramesRemaining
-=
frameCount
;
pSound
->
stopDelayInEngineFramesRemaining
-=
frameCount
;
}
else
{
}
else
{
pSound
->
stopDelayInEngineFramesRemaining
=
0
;
pSound
->
stopDelayInEngineFramesRemaining
=
0
;
}
}
/* Stop the sound if the delay has been reached. */
/* Stop the sound if the delay has been reached. */
if
(
pSound
->
stopDelayInEngineFramesRemaining
==
0
)
{
if
(
pSound
->
stopDelayInEngineFramesRemaining
==
0
)
{
ma_sound_stop_internal
(
pSound
);
ma_sound_stop_internal
(
pSound
);
}
}
}
else
{
/* The sound is at the end. Make sure it's marked as stopped. */
ma_sound_stop_internal
(
pSound
);
}
}
}
}
}
}
static
void
ma_engine_mix_sound
(
ma_engine
*
pEngine
,
ma_sound_group
*
pGroup
,
ma_sound
*
pSound
,
ma_uint64
frameCount
)
{
MA_ASSERT
(
pEngine
!=
NULL
);
MA_ASSERT
(
pGroup
!=
NULL
);
MA_ASSERT
(
pSound
!=
NULL
);
c89atomic_exchange_32
(
&
pSound
->
isMixing
,
MA_TRUE
);
/* This must be done before checking the isPlaying state. */
{
ma_engine_mix_sound_internal
(
pEngine
,
pGroup
,
pSound
,
frameCount
);
}
c89atomic_exchange_32
(
&
pSound
->
isMixing
,
MA_FALSE
);
c89atomic_exchange_32
(
&
pSound
->
isMixing
,
MA_FALSE
);
}
}
...
...
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