Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
hatari
Commits
56d093d7
Unverified
Commit
56d093d7
authored
Oct 15, 2020
by
Libretro-Admin
Committed by
GitHub
Oct 15, 2020
Browse files
Merge pull request #56 from bbbradsmith/patch-1
sound.c type mismatch, possible out of bound read?
parents
05c7f4e9
0bb427d3
Pipeline
#1479
passed with stages
in 2 minutes and 33 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/sound.c
View file @
56d093d7
...
@@ -1441,67 +1441,71 @@ void Sound_Update(bool FillFrame)
...
@@ -1441,67 +1441,71 @@ void Sound_Update(bool FillFrame)
extern
short
signed
int
SNDBUF
[
1024
*
2
];
extern
short
signed
int
SNDBUF
[
1024
*
2
];
static
void
Retro_Audio_CallBack
(
int
len
)
static
void
Retro_Audio_CallBack
(
int
len
)
{
{
Sint16
*
pBuffer
;
Sint16
*
pBuffer
;
int
i
,
window
,
nSamplesPerFrame
;
int
i
,
window
,
nSamplesPerFrame
;
pBuffer
=
(
Sint16
*
)
&
SNDBUF
[
0
];
len
=
len
/
4
;
// Use length in samples (16 bit stereo), not in bytes
pBuffer
=
(
Sint16
*
)
&
SNDBUF
[
0
];
/* Adjust emulation rate within +/- 0.58% (10 cents) occasionally,
len
=
len
/
4
;
// Use length in samples (16 bit stereo), not in bytes
* to synchronize sound. Note that an octave (frequency doubling)
* has 12 semitones (12th root of two for a semitone), and that
/* Adjust emulation rate within +/- 0.58% (10 cents) occasionally,
* one semitone has 100 cents (1200th root of two for one cent).
* to synchronize sound. Note that an octave (frequency doubling)
* Ten cents are desired, thus, the 120th root of two minus one is
* has 12 semitones (12th root of two for a semitone), and that
* multiplied by 1,000,000 to convert to microseconds, and divided
* one semitone has 100 cents (1200th root of two for one cent).
* by nScreenRefreshRate=60 to get a 96 microseconds swallow size.
* Ten cents are desired, thus, the 120th root of two minus one is
* (2^(10cents/(12semitones*100cents)) - 1) * 10^6 / nScreenRefreshRate
* multiplied by 1,000,000 to convert to microseconds, and divided
* See: main.c - Main_WaitOnVbl()
* by nScreenRefreshRate=60 to get a 96 microseconds swallow size.
*/
* (2^(10cents/(12semitones*100cents)) - 1) * 10^6 / nScreenRefreshRate
pulse_swallowing_count
=
0
;
/* 0 = Unaltered emulation rate */
* See: main.c - Main_WaitOnVbl()
if
(
ConfigureParams
.
Sound
.
bEnableSoundSync
)
*/
{
/* Sound synchronized emulation */
pulse_swallowing_count
=
0
;
/* 0 = Unaltered emulation rate */
nSamplesPerFrame
=
nAudioFrequency
/
nScreenRefreshRate
;
window
=
(
nSamplesPerFrame
>
SoundBufferSize
)
?
nSamplesPerFrame
:
SoundBufferSize
;
if
(
ConfigureParams
.
Sound
.
bEnableSoundSync
)
/* Window Comparator for SoundBufferSize */
{
if
(
nGeneratedSamples
<
window
+
(
window
>>
1
))
/* Sound synchronized emulation */
/* Increase emulation rate to maintain sound synchronization */
nSamplesPerFrame
=
nAudioFrequency
/
nScreenRefreshRate
;
pulse_swallowing_count
=
-
5793
/
nScreenRefreshRate
;
window
=
(
nSamplesPerFrame
>
SoundBufferSize
)
?
nSamplesPerFrame
:
SoundBufferSize
;
else
if
(
nGeneratedSamples
>
(
window
<<
1
)
+
(
window
>>
2
))
/* Window Comparator for SoundBufferSize */
/* Decrease emulation rate to maintain sound synchronization */
if
(
nGeneratedSamples
<
window
+
(
window
>>
1
))
pulse_swallowing_count
=
5793
/
nScreenRefreshRate
;
/* Increase emulation rate to maintain sound synchronization */
/* Otherwise emulation rate is unaltered. */
pulse_swallowing_count
=
-
5793
/
nScreenRefreshRate
;
}
else
if
(
nGeneratedSamples
>=
len
)
if
(
nGeneratedSamples
>
(
window
<<
1
)
+
(
window
>>
2
))
{
/* Decrease emulation rate to maintain sound synchronization */
/* Enough samples available: Pass completed buffer to audio system
pulse_swallowing_count
=
5793
/
nScreenRefreshRate
;
* by write samples into sound buffer and by converting them from
* 'signed' to 'unsigned' */
/* Otherwise emulation rate is unaltered. */
for
(
i
=
0
;
i
<
len
;
i
++
)
}
{
if
(
nGeneratedSamples
>=
len
)
*
pBuffer
++
=
MixBuffer
[(
CompleteSndBufIdx
+
i
)
%
MIXBUFFER_SIZE
][
0
];
{
*
pBuffer
++
=
MixBuffer
[(
CompleteSndBufIdx
+
i
)
%
MIXBUFFER_SIZE
][
1
];
/* Enough samples available: Pass completed buffer to audio system
}
* by write samples into sound buffer and by converting them from
CompleteSndBufIdx
+=
len
;
* 'signed' to 'unsigned' */
nGeneratedSamples
-=
len
;
for
(
i
=
0
;
i
<
len
;
i
++
)
}
{
else
/* Not enough samples available: */
*
pBuffer
++
=
MixBuffer
[(
CompleteSndBufIdx
+
i
)
%
MIXBUFFER_SIZE
][
0
];
{
*
pBuffer
++
=
MixBuffer
[(
CompleteSndBufIdx
+
i
)
%
MIXBUFFER_SIZE
][
1
];
for
(
i
=
0
;
i
<
nGeneratedSamples
;
i
++
)
}
{
CompleteSndBufIdx
+=
len
;
*
pBuffer
++
=
MixBuffer
[(
CompleteSndBufIdx
+
i
)
%
MIXBUFFER_SIZE
][
0
];
nGeneratedSamples
-=
len
;
*
pBuffer
++
=
MixBuffer
[(
CompleteSndBufIdx
+
i
)
%
MIXBUFFER_SIZE
][
1
];
}
}
else
/* Not enough samples available: */
/* If the buffer is filled more than 50%, mirror sample buffer to fake the
{
* missing samples */
for
(
i
=
0
;
i
<
nGeneratedSamples
;
i
++
)
if
(
nGeneratedSamples
>=
len
/
2
)
{
{
*
pBuffer
++
=
MixBuffer
[(
CompleteSndBufIdx
+
i
)
%
MIXBUFFER_SIZE
][
0
];
int
remaining
=
len
-
nGeneratedSamples
;
*
pBuffer
++
=
MixBuffer
[(
CompleteSndBufIdx
+
i
)
%
MIXBUFFER_SIZE
][
1
];
memcpy
(
pBuffer
,
SNDBUF
+
(
nGeneratedSamples
-
remaining
)
*
4
,
remaining
*
4
);
}
}
/* Clear rest of the buffer to ensure we don't play random bytes instead */
CompleteSndBufIdx
+=
nGeneratedSamples
;
/* of missing samples */
nGeneratedSamples
=
0
;
memset
(
pBuffer
,
0
,
(
len
-
nGeneratedSamples
)
*
4
);
}
CompleteSndBufIdx
=
CompleteSndBufIdx
%
MIXBUFFER_SIZE
;
CompleteSndBufIdx
+=
nGeneratedSamples
;
nGeneratedSamples
=
0
;
}
CompleteSndBufIdx
=
CompleteSndBufIdx
%
MIXBUFFER_SIZE
;
}
}
#endif
#endif
...
...
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