Thread: SDL sound.

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    80

    SDL sound.

    Code:
    void AudioCallback(void *userdata, Uint8 *buffer, int len)
    {
    	for(int index = 0; index < len; index++)
    		buffer[index] = rand()%256;
    }
    That function fills the soundbuffer with random noise but what I do not understand is why
    nothing can be heard at all if I change rand()%256 to always be, 205 for example, any suggestions?
    In other words I can't hear any sounds if the whole buffer contains the same value.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Same value means that the speaker will be at that deflection for the entire time. You will hear one pop when the speaker moves and then nothing. Sound is created by the speaker mimicing the crests and valleys of the wave. In your case you don't have one.

    No vibrations=no sound.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well if you are using SDL simply because it is easier and allows you to skip the low-level DirectX stuff that you don't understand or care to take the time to then you are using it for the wrong reason.

    If you are using it because you understand the low-level stuff
    but want to focus more on your game, then you are using it as a tool instead of a scapegoat

    If you use SDL for the wrong reason know that it will catch up to you and you will code yourself into a corner. Learn the APIs then decide on your tool of choice. Anything else is flying blind.

    Instead of SDL for Direct3D I would use the Microsoft provided Direct3D framework. It will help you with the nitty gritty and will help you understand how it all works. Eventually you will probably code your own DirectX wrapper classes. As always if you code it, you know what you need and you can tailor it to your needs. If you are using someone else's code, it may not be exactly tailored to your specific needs.
    Last edited by VirtualAce; 11-08-2005 at 12:34 AM.

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    How do you know he is using SDL to set up D3D? BTW: SDL_Mixer or even the standard SDL audio functions are the worst. Try another.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    The truth is that i'm a complete newbie when it comes to game programming and I simply thought that an SDL book could be a good start, I'm reading Focus On SDL by Ernest Pazera.
    I do plan to learn more about the low level stuff but not atm. I don't know but maybe it would be better to do it the other way around and start with the scary stuff.
    Anyway thanks for your replies, now I see the logic in why I didn't hear much at all.

  6. #6
    ---
    Join Date
    May 2004
    Posts
    1,379
    SDL is fine to learn with. Ignore what I said about the audio functions if your just learning. Keep reading about SDL. I just started reading a DX9 book but I have put that on hold for the moment because I have a new GP2X on order. I plan on developing for it so I'm back to using SDL again.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    Yeah, I'll do just that (keep reading), I've seen one of those GP2X and they seem really nice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 01:58 AM
  2. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  3. DirectSound - multiple sounds
    By Magos in forum Game Programming
    Replies: 9
    Last Post: 03-03-2004, 04:33 PM
  4. Crossplatform Sound Library -- other than SDL and Allegro
    By frenchfry164 in forum Game Programming
    Replies: 4
    Last Post: 10-14-2003, 04:27 PM
  5. sounds?
    By BODYBUILDNERD in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 03:34 PM