Skip to content

Commit 1a29b79

Browse files
Merge pull request #20 from MrValentine7777/documentation-reviews
Updated Pull request targetting [Base]
2 parents bb7ab08 + de92242 commit 1a29b79

File tree

6 files changed

+71
-55
lines changed

6 files changed

+71
-55
lines changed

articles/monogame/howto/audio/HowTo_ChangePitchAndVolume.md

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,89 @@
11
---
22
title: How to adjust Pitch and Volume
33
description: Demonstrates how to manipulate the pitch and volume of sound effects as they play.
4+
requireMSLicense: true
45
---
56

6-
# Adjusting Pitch and Volume
7+
The **[SoundEffect.Play](xref:Microsoft.Xna.Framework.Audio.SoundEffect.Play)** method allows you to specify the pitch and volume of a sound to play. However, after you call **[Play](xref:Microsoft.Xna.Framework.Audio.SoundEffect.Play)**, you cannot modify the sound. Using **[SoundEffectInstance](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance)** for a given **[SoundEffect](xref:Microsoft.Xna.Framework.Audio.SoundEffect)** allows you to change the **pitch** and **volume** of a sound at any time during playback.
78

8-
The [SoundEffect.Play](xref:Microsoft.Xna.Framework.Audio.SoundEffect.Play) method allows you to specify the pitch and volume of a sound to play. However, after you call [Play](xref:Microsoft.Xna.Framework.Audio.SoundEffect.Play), you cannot modify the sound. Using [SoundEffectInstance](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance) for a given [SoundEffect](xref:Microsoft.Xna.Framework.Audio.SoundEffect) allows you to change the pitch and volume of a sound at any time during playback.
9+
> [!NOTE]
10+
> The pitch of a sound changes the frequency of the sound, which in turn changes the speed of the sound. The volume of a sound changes the amplitude of the sound, which in turn changes the loudness of the sound.
911
1012
## Change Pitch and Volume of Sound
1113

12-
1. Declare [SoundEffect](xref:Microsoft.Xna.Framework.Audio.SoundEffect) and [Stream](http://msdn.microsoft.com/en-us/library/system.io.stream.aspx) by using the method shown in [Playing a Sound](HowTo_PlayASound.md). In addition to the method described in [Playing a Sound](HowTo_PlayASound.md), declare [SoundEffectInstance](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance).
14+
1. Declare a **[SoundEffect](xref:Microsoft.Xna.Framework.Audio.SoundEffect)** and a [Stream](http://msdn.microsoft.com/en-us/library/system.io.stream.aspx) file by using the method shown in [Playing a Sound](HowTo_PlayASound.md). In addition to the method described in [Playing a Sound](HowTo_PlayASound.md), declare a **[SoundEffectInstance](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance)** and a **Sound Effect** field member. We also create two float fields for **pitch** and **volume** to store the pitch and volume of the sound effect and assign initial values to them.
1315

1416
```csharp
15-
SoundEffectInstance soundInstance;
17+
// place these usings at the top of the file
18+
using System.IO;
19+
using Microsoft.Xna.Framework;
20+
using Microsoft.Xna.Framework.Audio;
21+
using Microsoft.Xna.Framework.Graphics;
22+
using Microsoft.Xna.Framework.Input;
23+
24+
// place these fields at the top of the class
25+
private SoundEffect soundEffect;
26+
private SoundEffectInstance soundEffectInstance;
27+
private float pitch = 0.75f;
28+
private float volume = 0.5f;
1629
```
1730

18-
2. In the [Game.LoadContent](xref:Microsoft.Xna.Framework.Game.LoadContent) method, set the SoundEffectInstance object to the return value of [SoundEffect.CreateInstance](xref:Microsoft.Xna.Framework.Audio.SoundEffect.CreateInstance).
31+
> [!NOTE]
32+
> Usings are declared at the top of the file to ensure that the necessary namespaces are available to the class. The fields are declared at the top of the class to ensure that they are accessible to all methods in the class.
33+
34+
2. In the [Game.LoadContent](xref:Microsoft.Xna.Framework.Game.LoadContent) method, set the **SoundEffectInstance** object to the return value of [SoundEffect.CreateInstance](xref:Microsoft.Xna.Framework.Audio.SoundEffect.CreateInstance).
35+
36+
3. In the **[Game.LoadContent](xref:Microsoft.Xna.Framework.Game.LoadContent)** method, set the **SoundEffectInstance** object to the return value of **[SoundEffect.CreateInstance](xref:Microsoft.Xna.Framework.Audio.SoundEffect.CreateInstance)**. We also optionally define a variable **soundFile** to store the location of the sound file being used with the **[TitleContainer.OpenStream](xref:Microsoft.Xna.Framework.TitleContainer#Microsoft_Xna_Framework_TitleContainer_OpenStream_System_String_)** method, which is accessed with the **using** keyword, and include a field member variable called **soundEffect**, to hold the stream.
1937

2038
```csharp
21-
soundfile = TitleContainer.OpenStream(@"Content\tx0_fire1.wav");
39+
using Stream soundfile = TitleContainer.OpenStream(@"Content\Sound__FileName.wav");
2240
soundEffect = SoundEffect.FromStream(soundfile);
2341
soundInstance = soundEffect.CreateInstance();
2442
```
2543

26-
3. Adjust the sound to the desired level using the [SoundEffectInstance.Pitch](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance.Pitch) and [SoundEffectInstance.Volume](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance.Volume) properties.
44+
4. Adjust the sound to the desired level using the [SoundEffectInstance.Pitch](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance.Pitch) and [SoundEffectInstance.Volume](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance.Volume) properties.
2745

2846
```csharp
2947
// Play Sound
30-
soundInstance.Play();
48+
soundEffectInstance.Play();
3149
```
3250

33-
4. Play the sound using [SoundEffectInstance.Play](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance.Play).
51+
> [!NOTE]
52+
> An instance will play once, to loop the sound, you can use the **[SoundEffectInstance.IsLooped](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance.IsLooped)** property to set the sound to loop. Also note that the sound will not repeat until the sound has finished playing. You can utilise the **[SoundEffectInstance.State](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance.State)** property to check if the sound is playing, paused or stopped. Use the **[SoundEffectInstance.Stop](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance.Stop)** method to stop the sound.
53+
54+
## An Extended Example
55+
56+
1. Below the **[Game.Draw](xref:Microsoft.Xna.Framework.Game#Microsoft_Xna_Framework_Game_Draw_Microsoft_Xna_Framework_GameTime_)** method, create a new method called **IsKeyPressed**, which will check if a specified key is pressed and return a boolean value of true if it has been pressed.
3457

3558
```csharp
36-
// Pitch takes values from -1 to 1
37-
soundInstance.Pitch = pitch;
38-
39-
// Volume only takes values from 0 to 1
40-
soundInstance.Volume = volume;
41-
```
59+
private bool IsKeyPressed(Keys key)
60+
{
61+
return Keyboard.GetState().IsKeyDown(key);
62+
}
63+
64+
```
65+
66+
2. In the **[Game.Update](xref:Microsoft.Xna.Framework.Game#Microsoft_Xna_Framework_Game_Update_Microsoft_Xna_Framework_GameTime_)** method, check if the **Space** key is pressed and adjust the pitch and volume of the sound effect accordingly. The pitch and volume values are adjusted by +0.1f each time the **Space key** is pressed. The pitch values are clamped to a minimum value of -1.0f and a maximum value of 1.0f, and the volume values are then clamped to a minimum value of 0f and a maximum value of 1.0f. This is done to ensure that the pitch and volume values are within valid ranges.
67+
68+
```csharp
69+
// Check if the SpaceKey is pressed and play the instance
70+
if (IsKeyPressed(Keys.Space))
71+
{
72+
pitch += 0.1f;
73+
volume += 0.1f;
74+
pitch = MathHelper.Clamp(pitch, -1.0f, 1.0f);
75+
volume = MathHelper.Clamp(volume, 0f, 1.0f);
76+
soundEffectInstance.Pitch = pitch;
77+
soundEffectInstance.Volume = volume;
78+
soundEffectInstance.Play();
79+
}
80+
```
81+
82+
> [!NOTE]
83+
> The **MathHelper.Clamp** method is used to ensure that the pitch and volume values are within the valid range. The pitch value is clamped between -1 and 1, while the volume value is clamped between 0 and 1.
84+
85+
> [!NOTE]
86+
> The check for the keypress does not prevent the call to the method repeating so any value entered may peak the value in a singe key press. To prevent this, you can add a delay to the key press check, or use a boolean value to check if the key has been pressed and released.
4287

4388
## Concepts
4489

@@ -63,9 +108,3 @@ Provides a loaded sound resource.
63108
[SoundEffectInstance Class](xref:Microsoft.Xna.Framework.Audio.SoundEffectInstance)
64109

65110
Provides a single playing, paused, or stopped instance of a [SoundEffect](xref:Microsoft.Xna.Framework.Audio.SoundEffect) sound.
66-
67-
---
68-
69-
© 2012 Microsoft Corporation. All rights reserved.
70-
71-
© 2023 The MonoGame Foundation.

articles/monogame/howto/content_pipeline/HowTo_Add_XML.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ description: Describes how to add custom game data as an XML file through the Co
44
requireMSLicense: true
55
---
66

7-
## Adding XML files to game content
8-
97
Custom game data that is expressed in an XML format can be easily integrated into your game through the MonoGame Content Pipeline.
108

119
This example demonstrates the procedure for integrating custom XML data into the content project of a simple game for the Windows platform.
@@ -17,7 +15,7 @@ Within the MonoGame solution, you create a new Windows Game Library project.
1715
1. Right-click the solution node, point to `Add`, click `New Project`, and then select the `MonoGame Game Library` template.
1816

1917
> [!TIP]
20-
> A `MonoGame Game Library` project is created instead of a Content Pipeline Extension Library project so that the class we will define can be used by both the [Content Importer](xref:Microsoft.Xna.Framework.Content.Pipeline.ContentImporter-1) that runs at build-time and the [Content Loader](xref:Microsoft.Xna.Framework.Content.ContentManager#Microsoft_Xna_Framework_Content_ContentManager_Load__1_System_String_) at game runtime.
18+
> A `MonoGame Game Library` project is created instead of a Content Pipeline Extension Library project so that the class we will define can be used by both the [Content Importer](https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.ContentImporter-1.html) that runs at build-time and the [Content Loader](xref:Microsoft.Xna.Framework.Content.ContentManager#Microsoft_Xna_Framework_Content_ContentManager_Load__1_System_String_) at game runtime.
2119
2220
2. In the `Name` box, type `MyDataTypes`, and then click `OK`.
2321

articles/monogame/howto/graphics/HowTo_Create_a_RenderTarget.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The example is very basic but the principles are the same, when drawing to a Ren
1313
5. Draw your game as normal.
1414
6. Draw the Render Texture to the screen in the position we desire (e.g. in the lower corner for a mini-map), most likely on top of your game graphics.
1515

16-
> TIP
16+
> [!TIP]
1717
> The technique is very useful, especially if you are doing split-screen gaming and need to draw multiple camera views.
1818
1919
## Requirements

articles/monogame/howto/graphics/HowTo_RenderModel.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
---
22
title: How to render a Model using a Basic Effect
3-
description: Demonstrates how to rotate a group of sprites around a single point.
3+
description: Demonstrates how to load and render a model using the MonoGame Content Pipeline.
4+
requireMSLicense: true
45
---
56

6-
# Rendering a Model with a Basic Effect
7-
8-
Demonstrates how to load and render a model using the MonoGame Content Pipeline. It is assumed that an existing Windows game project is loaded in MonoGame. In this example, the project is called "CPModel."
7+
> It is assumed that an existing Windows game project is loaded in MonoGame. In this example, the project is called "CPModel."
98
109
This example has three main parts: importing and processing the model, drawing the resultant managed object as a model with full lighting effect in the game, and enabling movement of the model with a game pad.
1110

@@ -150,11 +149,5 @@ Development is complete so you are ready to build and run the game. Control the
150149

151150
## See Also
152151

153-
[Adding Content to a Game](../Content_Pipeline/HowTo_LoadContent.md)
152+
[Adding Content to a Game](../Content_Pipeline/HowTo_GameContent_Add.md)
154153
[Using Input](../input/index.md)
155-
156-
---
157-
158-
© 2012 Microsoft Corporation. All rights reserved.
159-
160-
© 2023 The MonoGame Foundation.

articles/monogame/whatis/content_pipeline/index.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
---
22
title: What is the Content pipeline?
3-
description: The basics of the content pipeline for MonoGame!
3+
description: The topics in this section describe how to add and load content such as textures, meshes, sounds, and data in your game.
4+
requireMSLicense: true
45
---
56

6-
# Adding Content to a Game
7-
8-
The topics in this section describe how to add and load content such as textures, meshes, sounds, and data in your game.
9-
107
## In This Section
118

129
[What Is Content?](CP_Overview.md)
1310

1411
Describes the purpose of the MonoGame Content Pipeline and how it helps you add art and data assets to your game.
1512

16-
[Loading Content](../../howto/Content_Pipeline/HowTo_LoadContent.md)
13+
[Loading Content](../../howto/Content_Pipeline/HowTo_GameContent_Add.md)
1714

1815
Demonstrates how to load content such as models, textures, sounds, and effects.
1916

@@ -54,9 +51,3 @@ Describes the valid tags and values for Sprite-Font (.spritefont) XML files used
5451
[What are the XML Elements for XMLImporter?](CP_XML_Elements.md)
5552

5653
The base elements that are recognized by XmlImporter Class.
57-
58-
---
59-
60-
© 2012 Microsoft Corporation. All rights reserved.
61-
62-
© 2023 The MonoGame Foundation.

articles/monogame/whatis/index.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
---
2-
title: What is
2+
title: "What Is" Articles for MonoGame
33
description: A series of articles to answer common questions related to MonoGame operation!
4+
requireMSLicense: true
45
---
56

6-
# "What Is" Articles for MonoGame
7-
8-
These articles provide a brief introduction into graphics pipeline functionality.
9-
107
## In This Section
118

129
[WhatIs Audio?](WhatIs_Audio.md)
@@ -47,6 +44,4 @@ An overview of the MonoGame Class Library reference, containing all the API call
4744

4845
---
4946

50-
© 2012 Microsoft Corporation. All rights reserved.
51-
5247
© 2023 The MonoGame Foundation.

0 commit comments

Comments
 (0)