Help with SDL and Sounds

This is a discussion on Help with SDL and Sounds within the C++ Programming forums, part of the General Programming Boards category; Yes I meant that. But its wrong because if no event is queued no sound will be played. There are ...

  1. #16
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    Yes I meant that. But its wrong because if no event is queued no sound will be played. There are alternatives...
    But I feel so sleepy and can't think... I better go to bed. Good night!
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #17
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    Why it fills time_str with one unicode char 11 times?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #18
    Registered User
    Join Date
    May 2010
    Posts
    84
    that is not important for this question, pls just help me get the timing right...

    the last code didnt worked either, the timing still has some delay :\

    Help pls

  4. #19
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    Sorry but I should understand your code before doing anything to it.

    One way is to make a provider and a consumer thread. Provider provides the sequence to be played by consumer thread.

    I thought it would be hard for you. To find an easier way, I need a very clean code that I fully understand.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  5. #20
    Registered User
    Join Date
    May 2010
    Posts
    84
    hmm can u explain that "provider" metod pls??

    oh and btw if u really need to know, it fills time_str in every position (except [12]) with space, so it needs to loop 11 times.

  6. #21
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    I mean why time_str has 11 chars?

    Provider thread is a thread you write to set the time_str.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  7. #22
    Registered User
    Join Date
    May 2010
    Posts
    84
    the time_str has 11 chars because it is a string, that will then turn into an integer, this means that the max number of that integer is 99999999.

  8. #23
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    As you are filling that string yourself, there is no need to have a string at all. You can put it directly to an int.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  9. #24
    Registered User
    Join Date
    May 2010
    Posts
    84
    Its for saving the string into a surface, so the user can keep track of the value

  10. #25
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    I didn't tested it. Just a proposal.

    Code:
        while (quit==0)
        {
            apply_surface(bg, screen,0,0);
    
            y=atoi(time_str);
            if (y<=0) y=1;
    
            if ((SDL_GetTicks()-timing) == (60000/y))
            {
            if (SDL_PollEvent(&event))
            {
    
                //Quit Metronome
                if (event.type==SDL_QUIT)
                {
                    quit=1;
                }
                //--------------------------------
    
                if (event.type==SDL_KEYDOWN)
                {
                    SDL_EnableUNICODE(SDL_ENABLE);
    
                    if (event.key.keysym.unicode>=(Uint16)'0' && event.key.keysym.unicode <=(Uint16)'9')
                    {
                        if (x<11)
                        {
                        time_str[x]=(char)event.key.keysym.unicode;
                        x++;
                        text=NULL;
                        }
                    }
    
                    if (event.key.keysym.sym==SDLK_RETURN)
                    {
                        x=0;
                        while (x<11)
                        {
                        time_str[x]=' ';
                        x++;
                        }
                        x=0;
                        text=NULL;
                    }
    
    
                }
                text=TTF_RenderText_Solid(font, time_str, textcolor);
    
            }
                Mix_PlayChannel(-1,clap,0);
                timing=SDL_GetTicks();
            }
    
            apply_surface(text, screen,0,0);
    
            SDL_Flip(screen);
        }
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  11. #26
    Registered User
    Join Date
    May 2010
    Posts
    84
    nop that doesnt work, it doesnt let me input nothing and the program enters in an infinite loop cause the events only happen when ((SDL_GetTicks()-timing) == (60000/y)) and when i input something AT THE SAME EXACT TIME, wich is impossible. and besides it still delays a little bit.

    the delay has to do with lots of things (cpu speed... etc...) and what i want to know is how to round that and i want to know how to get THE PERFECT TIMING.

  12. #27
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    If SDL has an event queue maybe you need to call PumpEvents() just before if block in my last post.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  13. #28
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    I recommend using OpenAL or some other better third party sound API. FMOD is also one I would recommend. I'm assuming SDL is trying to offer a very basic sound system so it is easy to get simple sounds playing but probably was not designed to be a fully featured sound API.

  14. #29
    Registered User
    Join Date
    Jun 2010
    Posts
    1
    I also have problems like that!Thanks for answer and help!^^



    -------------------------------------------------------------------------------


    Learn more about our Fashion Games website.Fashion Games

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL sound.
    By antex in forum Game Programming
    Replies: 6
    Last Post: 11-08-2005, 04:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21