sound in c++

I am trying to make sound in c++ trhough SDL.

My source is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_mixer.h>


SDL_Surface *screen=NULL;


SDL_Event event;
bool run=true;


int main(int argc, char** argv)
{

SDL_Init(SDL_INIT_EVERYTHING);

SDL_WM_SetCaption("My SDL sprogram",NULL);

screen=SDL_SetVideoMode(1000,1000,32,SDL_SWSURFACE);

Mix_Chunk *effect1;
Mix_Chunk *effect2;

Mix_Music *music;

Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);

music=Mix_LoadMUS("sample.wav");



Mix_PlayMusic(music,-1);



while(run)
{
    if(SDL_PollEvent(&event))
    {
        switch(event.type)
        {
            case SDL_QUIT:
            run=false;
            break;

            }
          


        }


    }


Mix_FreeMusic(music);
Mix_CloseAudio();

SDL_Quit();
return 0;
}


I have put a .wav named <sample> but nothing happens when run the program.
is the source wrong?
Make sure that Mix_LoadMUS doesn't return a null pointer.
hey im a beginner i havn't braved the apis yet, would you recomend it? is it like learning c++ let me know how you get on if you could, i will be on sdl soon, maybe can compare practice codes ?
hepic.hepic is my skype.
Add me there if you want.

So peter,the source is correct?
How can fix it?
Hello. I just ran your code with one of my music files and everything works just fine. The problem might be your samlple.wav isn't being recognized by the compiler. In which case, you can put the wav file in the same directory as your .exe.

@ devonrevenge

I'm a beginner also with SDL. From my experience, I can say it is a lot easier than learning c++. It just takes time getting familiar with the syntax. I guess i'd recommend it based on the fact that there are plenty of tuts out there on learning the basics and it's not really hard.
Last edited on
man add me in skype to make a game together for fun etc...
@ skarla

That would be a good idea except I don't have a cam for it
no problem just add me here in skype:
hepic.hepic
Topic archived. No new replies allowed.