DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

Tutorial - Doing ambient sounds in SDL
Page 1 of 1
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 17 Sep 2018

Topics: 163
Posts: 8192
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Mon May 18, 2009 6:48 pm
   Subject: Tutorial - Doing ambient sounds in SDL
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Bottom of Posts

If you've ever tried AReyeP's ambient sounds tutorial with the Wolf4SDL code, you'll get compile errors. The problem it has is with the code that uses the random numbers and tells the Ambient Sounds to play back. You'll be able to get the code working if you replace the "bad code" with this line:

::: CODE :::
PlaySoundLocGlobal ((sounds[US_RndT()%9]),player->tilex,player->tiley);


More than likely, you have floor/ceiling tiles working in the code, as well as the Rain/Snow/Weather effects. The code above really doesn't take advantage of all the power the PlaySoundLocGlobal command has. So for those of you interested, the code below does away with this shortcoming. Note that I have it running in the UpdateFace routine in WL_AGENT.CPP.


::: CODE :::
/*
===============
=
= UpdateFace
=
= Calls draw face if time to change
=
===============
*/
int facecount = 0;
int facetimes = 0;
int ambientcount = 0;

void UpdateFace (void)
{
int AmbientX,AmbientY;
       
      ambientcount += tics;
      if (ambientcount > 10l*70)
           {
           AmbientX = ((player->tilex)-1)+US_RndT()%3;
           AmbientY = ((player->tiley)-1)+US_RndT()%3;
           ambientcount=0;
           if (!SD_SoundPlaying())
        {
            int soundsin[9]={ AMBIENTINDOOR0SND,
                AMBIENTINDOOR1SND,
                AMBIENTINDOOR2SND,
                AMBIENTINDOOR3SND,
                AMBIENTINDOOR4SND,
                AMBIENTINDOOR5SND,
                AMBIENTINDOOR6SND,
                AMBIENTINDOOR7SND,
                AMBIENTINDOOR8SND
                };
            int soundsout[9]={ AMBIENTOUTDOOR0SND,
                AMBIENTOUTDOOR1SND,
                AMBIENTOUTDOOR2SND,
                AMBIENTOUTDOOR3SND,
                AMBIENTOUTDOOR4SND,
                AMBIENTOUTDOOR5SND,
                AMBIENTOUTDOOR6SND,
                AMBIENTOUTDOOR7SND,
                AMBIENTOUTDOOR8SND
                };

            if (*(mapsegs[2]+((player->tiley<<mapshift))+(player->tilex))>>8)
           PlaySoundLocGlobal ((soundsin[US_RndT()%9]),AmbientX,AmbientY);
           else
           PlaySoundLocGlobal ((soundsout[US_RndT()%9]),AmbientX,AmbientY);
            }
}
    if (SD_SoundPlaying() == GETGATLINGSND)
        return;

...
Let me explain to you what exactly this extra code is doing. First off, AmbientX and AmbientY are used as a position on the map, which is where the ambient sound is supposed to come from. It can come from an area Northwest of the player, an area Southeast of the player, or somewhere in-between. This has the code take advantage of SDL's stereo playback, where sounds can be heard from the left or right speaker. I've had it use the AmbientY variable too, for those who want to use Surround Sound. Wink

Now, my current number of ambient sounds to 9. The code assumes that the sound names listed in "soundsin" and "soundout" are actually used in WL_MAIN.CPP and AUDIO***.H, but it's easy enough to change the names. Smile

Lastly, I'll note the "mapsegs[2]" jargon I've added. This checks the square of the map the player is on, and sees if the ceiling isn't NULL, a.k.a. a ceiling tile is to be drawn above the player. If the condition is true (marking him as "indoors"), it uses a random sound from the "soundsin" array, which has "indoor" ambient sounds. If the condition is false, it uses a random sound from "soundsout", which has "outdoor" sounds in the array.

Hope you enjoy the code, and feel free to post optimizations. Smile
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Announcement: Wolf4SDL released
Author: Ripper
522 208765 Mon May 22, 2017 2:04 pm
Tricob View latest post
No new posts [help] Adding teleporters in wolf4sdl
Author: Mortimer
35 10853 Fri May 26, 2017 8:19 am
Military View latest post
No new posts [WOLF4SDL Help] Blake Stone Style doors
Author: Haasboy
3 2998 Sun Jul 20, 2008 7:56 am
Haasboy View latest post
No new posts [Help] Problem with Checkweaponchange function (wolf4sdl)
Author: Mortimer
4 3204 Sat May 17, 2008 11:26 am
Mortimer View latest post
No new posts [SDL] Apply 2nd ScaleFactor to selected (hi-res) vga gfx
Author: Andy_Nonymous
9 4477 Sun Apr 27, 2008 2:30 am
AlumiuN View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group