2
votes

I want to write a simple console music player, which supports both .mp3 and .wav audio formats. Playing .wav files with SDL_mixer lowers the quality of the sound, but with mp3 files it does not. When the .wav file starts playing there is a continuous "cracking" sound, the rest is fine tho.

I already checked if it is the wav file itself or a similar problem, but it doesn't matter which file I use, it ends up always the same. I also tried changing values in the Mix_OpenAudio function, the frequency and chunksize for example.

I've tried too to play the sound without SDL_mixer, but with SDL_OpenAudio etc... result is the same, MP3 is fine WAVE not.

It's not my computer, with vlc or rythmbox (audio player) .wav files play with no problem.

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

using namespace std;

    int main()
    {
        // Music which will be played
        Mix_Music* Music = NULL;

        // Init
        //
        // Init SDL Audio
        SDL_Init(SDL_INIT_AUDIO);

        // Init SDL_mixer
        Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 512);

        // Load the files
        //
        // Load the music
        Music = Mix_LoadMUS("Star Trek - Deep Space Nine.mp3");

        // Play the music
        Mix_PlayMusic(Music, 1);

        while (Mix_PlayingMusic() == 1)
        {

        }

        // clean up
        //
        // free the music
        Mix_FreeMusic(Music);

        // Quit Mixer
        Mix_CloseAudio();

        // Quit SDL
        SDL_Quit();

        return 0;
    }

I'm getting no error message or anything.

Here is the file.

2
Please provide a minimal reproducible example (a piece of code that we can actually compile), and the .wav file you have problems with.HolyBlackCat
@HolyBlackCat It's my first post ever, I hope that'll be forgiven :D. I edited the code now, so you can compile it.Anton Büttner

2 Answers

0
votes

So I tried the same with Windows now, it worked there without problems, so this might be an compiler issue or I don't know. Very strange. I'll leave it like it is and do .mp3 only.

0
votes

Many people seems to be having this kind of problem. This problem is actually related to the format which the Audio is played. You need to have your decoder toss that information on you or need to work with only one kind of audio format.