Sound in lite-c is the biggest problem !!!

Posted By: warkarma

Sound in lite-c is the biggest problem !!! - 05/25/09 17:03

Hi all again. I have some more problems like always. I am trying to make sound work in Lite-C but it just doesn't work right. The thing i am trying to do is to make left mouse button shut bullets (a lot of them nonstop) and the right mouse button to explode 1 time a sec. And then i press left mouse button in the beginning it sound goes only one time and after a few moments it start working the way i want it to work but then i try to press right mouse button the explosion doesn't work, but then i hold right mouse button the sound starts working properly but the bullet sound doesn't work again. Anyway try it for your self and if you know the answer how to fix this problem please let me know.

download from here:
http://rapidshare.com/files/237116491/Sound.rar.html
or
http://rapidshare.com/files/237116918/Sound.rar.html

the code:

#include <acknex.h>;
#include <default.c>;
BMAP* sight_png = "sight.png";
SOUND* shoot_wav = "gun_1.wav";
SOUND* explode_wav = "explode.wav";

function gunsound();

function gunsound()
{
while(1)
{
if(mouse_left)
{
snd_play(shoot_wav, 30, 1);
wait(-0.1);
}
if(mouse_right)
{
snd_play(explode_wav,30,-1);
wait(-1);
}
wait(1);
}
}

function main()
{
screen_size.x = 800; // set the screen size
screen_size.y = 600;
video_screen = 2; // Window mode

mouse_spot.x = bmap_width(sight_png) /2; // sets the mouse spot
mouse_spot.y = bmap_height(sight_png)/2;
mouse_map = sight_png; // mouse bitmap
mouse_mode = 1; //mouse mode

gunsound();
while(1)
{
vec_set(mouse_pos,mouse_cursor);
wait(1);
}
} // end main



Thank you for your time
Posted By: warkarma

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 17:50

I have made some progress. But i still can't have two sounds playing same time. The code:

#include <acknex.h>;
#include <default.c>;
BMAP* sight_png = "sight.png";
SOUND* shoot_wav = "gun_1.wav";
SOUND* explode_wav = "explode.wav";


function gunsound2();



function gunsound2()
{
while(1)
{
if(mouse_left)
{
SOUND* wavsound = snd_create("explode.wav");
var wavhandle = snd_play(wavsound,50,0);
wait(-1);
snd_remove(wavsound);
}
if(mouse_right)
{
SOUND* wavsound = snd_create("gun_1.wav");
var wavhandle = snd_play(wavsound,50,0);
wait(-0.1);
snd_remove(wavsound);
}
wait(1);
}
}

function main()
{
screen_size.x = 800; // set the screen size
screen_size.y = 600;
video_screen = 2; // Window mode

mouse_spot.x = bmap_width(sight_png) /2; // sets the mouse spot
mouse_spot.y = bmap_height(sight_png)/2;
mouse_map = sight_png; // mouse bitmap
mouse_mode = 1; //mouse mode


gunsound2();
while(1)
{
vec_set(mouse_pos,mouse_cursor);
wait(1);
}
} // end main


Please HELP !!!
Posted By: Quad

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 18:00

var wavhandle;
function gunsound2()
{
while(1)
{
if(mouse_left)
{
wavhandle = snd_play(explode_wav,50,0);
wait(-1);
snd_remove(wavsound);
}
if(mouse_right)
{
wavhandle = snd_play(shoot_wav,50,0);
wait(-0.1);

.............
Posted By: warkarma

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 18:17

Quadraxas.
Correct me if i am wrong.

The code:
function gunsound2()
{
while(1)
{
if(mouse_left)
{
wavhandle = snd_play(explode_wav,50,0);
wait(-1);
snd_remove(wavsound);
}
if(mouse_right)
{
wavhandle = snd_play(shoot_wav,50,0);
wait(-0.1);
snd_remove(wavsound);
}
wait(1);
}
}

It still waits for one sound to finish to start second one. And i need two sounds playing at the same time.
Posted By: Quad

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 18:25

try defining another handle and use that for second sound(or dont use handles at all.)

also you need to remove snd_remove(wavsound); lines.
Posted By: warkarma

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 18:31

Originally Posted By: Quadraxas
try defining another handle and use that for second sound(or dont use handles at all.)

also you need to remove snd_remove(wavsound); lines.


I have tried it and it still doesnt work right frown
var wavhandle;
var wavhandle2;

function gunsound2();

function gunsound2()
{
while(1)
{
if(mouse_left)
{
wavhandle = snd_play(explode_wav,50,2);
wait(-1);
// snd_remove(wavsound);
}
if(mouse_right)
{
wavhandle2 = snd_play(shoot_wav,50,-2);
wait(-0.1);
// snd_remove(wavsound);
}
wait(1);
}
}
Posted By: Quad

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 18:40

it should, when exactly it should play and it doesnt?
Posted By: warkarma

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 18:53

if you press left mouse button the explosion sound starts and while it is playing i am pressing right mouse button and it doesn't start till explosion sound is over
Posted By: flits

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 19:09

you need to put them in 2 diferent func because you wait(-1) in the same loop
Posted By: warkarma

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 19:12

Woooohoooo !!!! smile it WORKS
THANK YOU VERY MUCH FOR YOUR HELP ALL

THE FINAL CODE:


#include <acknex.h>;
#include <default.c>;
BMAP* sight_png = "sight.png";
SOUND* shoot_wav = "gun_1.wav";
SOUND* explode_wav = "explode.wav";

var wavhandle;
var wavhandle2;

function gunsound();
function gunsound2();

function gunsound()
{
while(1)
{
if(mouse_left)
{
wavhandle = snd_play(explode_wav,50,2);
wait(-1);
// snd_remove(wavsound);
}
wait(1);
}
}


function gunsound2()
{
while(1)
{
if(mouse_right)
{
wavhandle2 = snd_play(shoot_wav,50,-2);
wait(-0.1);
// snd_remove(wavsound);
}
wait(1);
}
}



function main()
{
screen_size.x = 800; // set the screen size
screen_size.y = 600;
video_screen = 2; // Window mode

mouse_spot.x = bmap_width(sight_png) /2; // sets the mouse spot
mouse_spot.y = bmap_height(sight_png)/2;
mouse_map = sight_png; // mouse bitmap
mouse_mode = 1; //mouse mode

gunsound();
gunsound2();
while(1)
{
vec_set(mouse_pos,mouse_cursor);
wait(1);
}
} // end main
Posted By: flits

Re: Sound in lite-c is the biggest problem !!! - 05/25/09 19:12

woot thats pretty fast
© 2024 lite-C Forums