0

when i start the code i get warning: incorrect audio format

i figured out its related to the mp3 file.

whats the problem and how can i fix it?

i already tried to convert the mp3 to a wav file but that also didnt work.

is it possible that 3mb of mp3 is to big? shouldnt be?

Edit: when i let it run without of mp3 the wav files will run just fine with mp3 the programm will start but no sound at all

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>

static const int width = 800;
static const int height = 600;

int main(int argc, char **argv)
{
    // Initialize SDL video and audio systems
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);

    // Initialize SDL mixer
    Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 3, 2048);

    // Load audio files
    Mix_Music *backgroundSound = Mix_LoadMUS("portfolio.mp3");
    Mix_Chunk *jumpEffect = Mix_LoadWAV("JumpEffect.wav");
    Mix_Chunk *laserEffect = Mix_LoadWAV("LaserEffect.wav");
    //Mix_Chunk *musicEffect = Mix_LoadWAV("portfolio2.wav");

    // Create a SDL window
    SDL_Window *window = SDL_CreateWindow("Hello, SDL2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);

    // Create a renderer (accelerated and in sync with the display refresh rate)
    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);

    // Start the background music
    Mix_PlayMusic(backgroundSound, -1);

    bool running = true;
    SDL_Event event;
    while(running)
    {
        // Process events
        while(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                running = false;
            }
            else if(event.type == SDL_KEYDOWN)
            {
                // Press "1" and play jump effect
                if(event.key.keysym.sym == SDLK_1)
                {
                    Mix_PlayChannel(-1, jumpEffect, 0);
                }
                // Press "2" and play laser effect
                else if(event.key.keysym.sym == SDLK_2)
                {
                    Mix_PlayChannel(-1, laserEffect, 0);
                }
            }
        }

        // Clear screen
        SDL_RenderClear(renderer);

        // Draw

        // Show what was drawn
        SDL_RenderPresent(renderer);
    }

    // Release resources

    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    Mix_FreeMusic(backgroundSound);
    Mix_FreeChunk(jumpEffect);
    Mix_FreeChunk(laserEffect);
    //Mix_FreeChunk(music);
    Mix_CloseAudio();
    SDL_Quit();

    return 0;
}

enter image description here

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – user16217248 Oct 18 '22 at 01:47
  • SDL version? SDL_mixer version? Using SDL/SDL_mixer binaries from github or are they self-built? – genpfault Oct 19 '22 at 16:05
  • Also, try testing with a public, freely-licensed file from Mediawiki; edit the question to add a link to it so others can attempt repro. – genpfault Oct 19 '22 at 16:06
  • What's emitting the "incorrect audio format" warning? There's no logging in your code. Is it a pop-up window? Something on stdout/stderr? – genpfault Oct 19 '22 at 16:07

0 Answers0