mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-06 22:29:17 -05:00
Compare commits
10 Commits
e00c5eb8b1
...
78a06990c7
| Author | SHA1 | Date | |
|---|---|---|---|
| 78a06990c7 | |||
| 82b80a6998 | |||
| 71b302846a | |||
| 8823aba9df | |||
| 6b9a685bae | |||
| 14582a9f06 | |||
| 0405de794a | |||
| d03ac97eff | |||
| 34af70866c | |||
| 9e908e4a76 |
@ -61,7 +61,9 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
|
#ifndef PLATFORM_WEB // NOTE: On non web platforms the PollInputEvents just works before the inputs checks
|
||||||
|
PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
|
||||||
|
#endif
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
|
if (IsKeyPressed(KEY_SPACE)) pause = !pause;
|
||||||
|
|
||||||
@ -76,6 +78,10 @@ int main(void)
|
|||||||
if (position >= GetScreenWidth()) position = 0;
|
if (position >= GetScreenWidth()) position = 0;
|
||||||
timeCounter += deltaTime; // We count time (seconds)
|
timeCounter += deltaTime; // We count time (seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PLATFORM_WEB // NOTE: On web platform for some reason the PollInputEvents only works after the inputs check, so just call it after check all your inputs (on web)
|
||||||
|
PollInputEvents(); // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
|
||||||
|
#endif
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|||||||
40
src/raudio.c
40
src/raudio.c
@ -1891,14 +1891,28 @@ void UpdateMusicStream(Music music)
|
|||||||
// Check both sub-buffers to check if they require refilling
|
// Check both sub-buffers to check if they require refilling
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
if (!music.stream.buffer->isSubBufferProcessed[i]) continue; // No refilling required, move to next sub-buffer
|
|
||||||
|
|
||||||
unsigned int framesLeft = music.frameCount - music.stream.buffer->framesProcessed; // Frames left to be processed
|
unsigned int framesLeft = music.frameCount - music.stream.buffer->framesProcessed; // Frames left to be processed
|
||||||
unsigned int framesToStream = 0; // Total frames to be streamed
|
unsigned int framesToStream = 0; // Total frames to be streamed
|
||||||
|
|
||||||
if ((framesLeft >= subBufferSizeInFrames) || music.looping) framesToStream = subBufferSizeInFrames;
|
if ((framesLeft >= subBufferSizeInFrames) || music.looping) framesToStream = subBufferSizeInFrames;
|
||||||
else framesToStream = framesLeft;
|
else framesToStream = framesLeft;
|
||||||
|
|
||||||
|
if (framesToStream == 0)
|
||||||
|
{
|
||||||
|
// Check if both buffers have been processed
|
||||||
|
if (music.stream.buffer->isSubBufferProcessed[0] && music.stream.buffer->isSubBufferProcessed[1])
|
||||||
|
{
|
||||||
|
ma_mutex_unlock(&AUDIO.System.lock);
|
||||||
|
StopMusicStream(music);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ma_mutex_unlock(&AUDIO.System.lock);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!music.stream.buffer->isSubBufferProcessed[i]) continue; // No refilling required, move to next sub-buffer
|
||||||
|
|
||||||
int frameCountStillNeeded = framesToStream;
|
int frameCountStillNeeded = framesToStream;
|
||||||
int frameCountReadTotal = 0;
|
int frameCountReadTotal = 0;
|
||||||
|
|
||||||
@ -2011,19 +2025,6 @@ void UpdateMusicStream(Music music)
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateAudioStreamInLockedState(music.stream, AUDIO.System.pcmBuffer, framesToStream);
|
UpdateAudioStreamInLockedState(music.stream, AUDIO.System.pcmBuffer, framesToStream);
|
||||||
|
|
||||||
music.stream.buffer->framesProcessed = music.stream.buffer->framesProcessed%music.frameCount;
|
|
||||||
|
|
||||||
if (framesLeft <= subBufferSizeInFrames)
|
|
||||||
{
|
|
||||||
if (!music.looping)
|
|
||||||
{
|
|
||||||
ma_mutex_unlock(&AUDIO.System.lock);
|
|
||||||
// Streaming is ending, we filled latest frames from input
|
|
||||||
StopMusicStream(music);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_mutex_unlock(&AUDIO.System.lock);
|
ma_mutex_unlock(&AUDIO.System.lock);
|
||||||
@ -2086,8 +2087,12 @@ float GetMusicTimePlayed(Music music)
|
|||||||
int subBufferSize = (int)music.stream.buffer->sizeInFrames/2;
|
int subBufferSize = (int)music.stream.buffer->sizeInFrames/2;
|
||||||
int framesInFirstBuffer = music.stream.buffer->isSubBufferProcessed[0]? 0 : subBufferSize;
|
int framesInFirstBuffer = music.stream.buffer->isSubBufferProcessed[0]? 0 : subBufferSize;
|
||||||
int framesInSecondBuffer = music.stream.buffer->isSubBufferProcessed[1]? 0 : subBufferSize;
|
int framesInSecondBuffer = music.stream.buffer->isSubBufferProcessed[1]? 0 : subBufferSize;
|
||||||
|
int framesInBuffers = framesInFirstBuffer + framesInSecondBuffer;
|
||||||
|
if (framesInBuffers > music.frameCount) {
|
||||||
|
if (!music.looping) framesInBuffers = music.frameCount;
|
||||||
|
}
|
||||||
int framesSentToMix = music.stream.buffer->frameCursorPos%subBufferSize;
|
int framesSentToMix = music.stream.buffer->frameCursorPos%subBufferSize;
|
||||||
int framesPlayed = (framesProcessed - framesInFirstBuffer - framesInSecondBuffer + framesSentToMix)%(int)music.frameCount;
|
int framesPlayed = (framesProcessed - framesInBuffers + framesSentToMix)%(int)music.frameCount;
|
||||||
if (framesPlayed < 0) framesPlayed += music.frameCount;
|
if (framesPlayed < 0) framesPlayed += music.frameCount;
|
||||||
secondsPlayed = (float)framesPlayed/music.stream.sampleRate;
|
secondsPlayed = (float)framesPlayed/music.stream.sampleRate;
|
||||||
ma_mutex_unlock(&AUDIO.System.lock);
|
ma_mutex_unlock(&AUDIO.System.lock);
|
||||||
@ -2684,8 +2689,7 @@ static void UpdateAudioStreamInLockedState(AudioStream stream, const void *data,
|
|||||||
ma_uint32 subBufferSizeInFrames = stream.buffer->sizeInFrames/2;
|
ma_uint32 subBufferSizeInFrames = stream.buffer->sizeInFrames/2;
|
||||||
unsigned char *subBuffer = stream.buffer->data + ((subBufferSizeInFrames*stream.channels*(stream.sampleSize/8))*subBufferToUpdate);
|
unsigned char *subBuffer = stream.buffer->data + ((subBufferSizeInFrames*stream.channels*(stream.sampleSize/8))*subBufferToUpdate);
|
||||||
|
|
||||||
// Total frames processed in buffer is always the complete size, filled with 0 if required
|
stream.buffer->framesProcessed += frameCount;
|
||||||
stream.buffer->framesProcessed += subBufferSizeInFrames;
|
|
||||||
|
|
||||||
// Does this API expect a whole buffer to be updated in one go?
|
// Does this API expect a whole buffer to be updated in one go?
|
||||||
// Assuming so, but if not will need to change this logic
|
// Assuming so, but if not will need to change this logic
|
||||||
|
|||||||
@ -2927,7 +2927,16 @@ void ImageColorReplace(Image *image, Color color, Color replace)
|
|||||||
image->data = pixels;
|
image->data = pixels;
|
||||||
image->format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
image->format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||||
|
|
||||||
ImageFormat(image, format);
|
// Only convert back to original format if it supported alpha
|
||||||
|
if ((format == PIXELFORMAT_UNCOMPRESSED_R8G8B8) ||
|
||||||
|
(format == PIXELFORMAT_UNCOMPRESSED_R5G6B5) ||
|
||||||
|
(format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) ||
|
||||||
|
(format == PIXELFORMAT_UNCOMPRESSED_R32G32B32) ||
|
||||||
|
(format == PIXELFORMAT_UNCOMPRESSED_R16G16B16) ||
|
||||||
|
(format == PIXELFORMAT_COMPRESSED_DXT1_RGB) ||
|
||||||
|
(format == PIXELFORMAT_COMPRESSED_ETC1_RGB) ||
|
||||||
|
(format == PIXELFORMAT_COMPRESSED_ETC2_RGB) ||
|
||||||
|
(format == PIXELFORMAT_COMPRESSED_PVRT_RGB)) ImageFormat(image, format);
|
||||||
}
|
}
|
||||||
#endif // SUPPORT_IMAGE_MANIPULATION
|
#endif // SUPPORT_IMAGE_MANIPULATION
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user