Legacy GM Sound Pitch(Drag'n Drop or very specific explanation)

Z

Ziliock

Guest
Hi there.I was wondering how can I change a little bit the pitch of a specific sound each time it plays.To avoid being too repetitive in the game experience
I'm a Drag'n Drop guy, so please be very specific if you only know how to do that in scripts/codes
Please try to tell me what I need to put in the events and actions and when to do so
 
C

CoderJoe

Guest
In code you can use audio_sound_pitch(index, pitch). So if your sound is named TheSound and you want the pitch to be higher do something like this:
audio_sound_pitch(TheSound, 2);

the number you put in for pitch will change the pitch, higher number are higher pitch, lower numbers are lower pitch. To change the pitch every time it plays simply have a variable that changes when the sound is played. Use this variable for the pitch number. Hope this helps a bit.
 

obscene

Member
To further explain, a pitch value of 1 is normal... .5 would be half speed, 2 would be double speed etc.

Also, when you play a sound you are basically creating an "instance" of that sound and so when you change pitches you generally might want to apply the pitch to that instance only.

Example:
var sound=audio_play_sound(snd_whatever);
audio_sound_pitch(sound,random_range(.9,1.1);
 
Z

Ziliock

Guest
To further explain, a pitch value of 1 is normal... .5 would be half speed, 2 would be double speed etc.

Also, when you play a sound you are basically creating an "instance" of that sound and so when you change pitches you generally might want to apply the pitch to that instance only.

Example:
var sound=audio_play_sound(snd_whatever);
audio_sound_pitch(sound,random_range(.9,1.1);
Thanks you! So:
In the events section I put:
var sound=audio_play_sound(name of my sound);
audio_sound_pitch(sound,random_range(.9,1.1);
But: Is it in the Execute code or execute script section?
 
Z

Ziliock

Guest
To further explain, a pitch value of 1 is normal... .5 would be half speed, 2 would be double speed etc.

Also, when you play a sound you are basically creating an "instance" of that sound and so when you change pitches you generally might want to apply the pitch to that instance only.

Example:
var sound=audio_play_sound(snd_whatever);
audio_sound_pitch(sound,random_range(.9,1.1);
What should I do about this?
Programacion1.png
 

obscene

Member
Sorry I couldn't remember the arguments and should have said that was just pseudocode.. If you look at the bottom right of your image you see soundid,priority,loops which are the 3 arguments the function expects. soundid is bold which indicates that's the argument your cursor is on. Add the other two arguments separated by commas and you'll see the error dissapear. Priority is any number just use 1. Loops is 0 if you don't want a loop and 1 if you do.

Also remember you can hit F1 and search for a function to find out how to use it correctly.
 
Z

Ziliock

Guest
Sorry I couldn't remember the arguments and should have said that was just pseudocode.. If you look at the bottom right of your image you see soundid,priority,loops which are the 3 arguments the function expects. soundid is bold which indicates that's the argument your cursor is on. Add the other two arguments separated by commas and you'll see the error dissapear. Priority is any number just use 1. Loops is 0 if you don't want a loop and 1 if you do.

Also remember you can hit F1 and search for a function to find out how to use it correctly.
What "other two arguments"?
It'll going to work when I do so?
 
Z

Ziliock

Guest
Code:
var sound=audio_play_sound(snd_explow, 0, false);
0 is the priority.
false (can be true/false) is whether the sound should loop or not.

Cheers!
Thanks you! I'll try it!
Can you explain me what does each thing like:
Visible variable(1) = visible
Visible variable(0) = No Visible
To help me to understand a little of GameMaker's codes:What do you mean with the "zero" and the "false"?
 
Z

Ziliock

Guest
Code:
var sound=audio_play_sound(snd_explow, 0, false);
0 is the priority.
false (can be true/false) is whether the sound should loop or not.

Cheers!
Now another error
The random_range is like in the Drag'n Drop? "1" is normal pitch. "0" is like no pitch? To give the sound the same value on + and - it need to be 0.5,1.5?
Programacion2.png
 

johnwo

Member
Can you explain me what does each thing like:
Visible variable(1) = visible
Visible variable(0) = No Visible
To help me to understand a little of GameMaker's codes:What do you mean with the "zero" and the "false"?
Code:
visible = false; // Object is now invisible
visible = true; // Object is now visible
To explain true/false/1/0:
Code:
true // A variable is true if the value of the variable is larger than 0

false // A variable is false if the value of the variable is equal to or smaller than 0
Hope that clarifies true/false/1/0 and the visible value.

Now another error
The random_range is like in the Drag'n Drop? "1" is normal pitch. "0" is like no pitch? To give the sound the same value on + and - it need to be 0.5,1.5?
The error is produced since you're missing a ending parenthesis.
Try:
Code:
audio_sound_pitch(sound, random_range(.9,1.1) );
All functions must have their arguments enclosed by parenthesis.

Example:
Code:
// Valid

function();
function(arg0,arg1);
function(arg0,function2(arg1,arg2));

// Invalid

function;
function(arg0,arg1;
function(arg0,function2(arg1,arg2 );
Hope that helps!

Cheers!
 
Z

Ziliock

Guest
Code:
visible = false; // Object is now invisible
visible = true; // Object is now visible
To explain true/false/1/0:
Code:
true // A variable is true if the value of the variable is larger than 0

false // A variable is false if the value of the variable is equal to or smaller than 0
Hope that clarifies true/false/1/0 and the visible value.



The error is produced since you're missing a ending parenthesis.
Try:
Code:
audio_sound_pitch(sound, random_range(.9,1.1) );
All functions must have their arguments enclosed by parenthesis.

Example:
Code:
// Valid

function();
function(arg0,arg1);
function(arg0,function2(arg1,arg2));

// Invalid

function;
function(arg0,arg1;
function(arg0,function2(arg1,arg2 );
Hope that helps!

Cheers!
Hey! Thaks you again!
I tried with (0.5,1.5) and the sounds sound strange.too acute
 
Z

Ziliock

Guest
Code:
visible = false; // Object is now invisible
visible = true; // Object is now visible
To explain true/false/1/0:
Code:
true // A variable is true if the value of the variable is larger than 0

false // A variable is false if the value of the variable is equal to or smaller than 0
Hope that clarifies true/false/1/0 and the visible value.



The error is produced since you're missing a ending parenthesis.
Try:
Code:
audio_sound_pitch(sound, random_range(.9,1.1) );
All functions must have their arguments enclosed by parenthesis.

Example:
Code:
// Valid

function();
function(arg0,arg1);
function(arg0,function2(arg1,arg2));

// Invalid

function;
function(arg0,arg1;
function(arg0,function2(arg1,arg2 );
Hope that helps!

Cheers!
Now with 0.9,1.1
I think the sound was replased somehow by other one
 
Z

Ziliock

Guest
Code:
visible = false; // Object is now invisible
visible = true; // Object is now visible
To explain true/false/1/0:
Code:
true // A variable is true if the value of the variable is larger than 0

false // A variable is false if the value of the variable is equal to or smaller than 0
Hope that clarifies true/false/1/0 and the visible value.



The error is produced since you're missing a ending parenthesis.
Try:
Code:
audio_sound_pitch(sound, random_range(.9,1.1) );
All functions must have their arguments enclosed by parenthesis.

Example:
Code:
// Valid

function();
function(arg0,arg1);
function(arg0,function2(arg1,arg2));

// Invalid

function;
function(arg0,arg1;
function(arg0,function2(arg1,arg2 );
Hope that helps!

Cheers!
What's wrong?
Programacion3.png
 
Z

Ziliock

Guest
I can't see any errors with the code.
I don't know either. It sounds too acute.Like a standard sound of windows XP
When the attack collides with the enemy I put this in the action's site:
.Create explosion object
.Destroy instance(self)
.Stop Sound snd_explow
.Play Sound snd_explow
.Execute code
 

johnwo

Member
.Create explosion object
.Destroy instance(self)
.Stop Sound snd_explow
.Play Sound snd_explow
.Execute code
Try making it:
  • Create explosion object
  • Destroy Instance (On self)
  • Execute Code
Since the code plays the sound, you don't have to start/stop it through Drag & Drop.

Hope it helps.
 
Z

Ziliock

Guest
Try making it:
  • Create explosion object
  • Destroy Instance (On self)
  • Execute Code
Since the code plays the sound, you don't have to start/stop it through Drag & Drop.

Hope it helps.
Not working
and the sound modification affects all the enemys for some reason
 
Z

Ziliock

Guest
I can't see any errors with the code.
Hey I fixed it!
Thanks a lot! Is because I saw that your sound example was writen like "snd_sound1" and mine're always "sound_sound1" so I changed the name of the sound and then in the code and that confused my PC somehow.But now it is fixed and working
 
Top