Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear PCM buffer state when closing audio device #2736

Merged
merged 1 commit into from
Oct 2, 2022

Conversation

veins1
Copy link
Contributor

@veins1 veins1 commented Oct 2, 2022

Fix for #2714
Code used for testing:

#include "raylib.h"

int main(void)
{
    bool restarting = true;
    while (restarting) {
        // Initialization
        //--------------------------------------------------------------------------------------
        const int screenWidth = 800;
        const int screenHeight = 450;

        InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");

        InitAudioDevice();              // Initialize audio device

        Music music = LoadMusicStream("resources/country.mp3");

        PlayMusicStream(music);

        SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
        //--------------------------------------------------------------------------------------

        // Main game loop
        while (restarting && (!WindowShouldClose()))    // Detect window close button or ESC key
        {
            // Update
            if (IsKeyPressed(KEY_Q)) {
                restarting = false;
            }
            //----------------------------------------------------------------------------------
            UpdateMusicStream(music);   // Update music buffer with new stream data
            //----------------------------------------------------------------------------------
        
            // Draw
            //----------------------------------------------------------------------------------
            BeginDrawing();
                ClearBackground(RAYWHITE);

                DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);

                DrawText("PRESS ESC TO RESTART", 215, 250, 20, LIGHTGRAY);
                DrawText("PRESS Q TO QUIT", 208, 280, 20, LIGHTGRAY);
            EndDrawing();
            //----------------------------------------------------------------------------------
        }
        // De-Initialization
        //--------------------------------------------------------------------------------------
        UnloadMusicStream(music);   // Unload music stream buffers from RAM

        CloseAudioDevice();         // Close audio device (music streaming is automatically stopped)

        CloseWindow();              // Close window and OpenGL context
        //--------------------------------------------------------------------------------------
    }
    return 0;
}

@raysan5 raysan5 merged commit 2872b2f into raysan5:master Oct 2, 2022
@raysan5
Copy link
Owner

raysan5 commented Oct 2, 2022

@veins1 Thanks for the review.

@veins1 veins1 deleted the veins1-patch-1 branch October 3, 2022 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants