@@ -35,6 +35,12 @@ int main(void)
3535
3636 float timePlayed = 0.0f ; // Time played normalized [0.0f..1.0f]
3737 bool pause = false; // Music playing paused
38+
39+ float pan = 0.0f ; // Default audio pan center [-1.0f..1.0f]
40+ SetMusicPan (music , pan );
41+
42+ float volume = 0.8f ; // Default audio volume [0.0f..1.0f]
43+ SetMusicVolume (music , volume );
3844
3945 SetTargetFPS (30 ); // Set our game to run at 30 frames-per-second
4046 //--------------------------------------------------------------------------------------
@@ -61,6 +67,34 @@ int main(void)
6167 if (pause ) PauseMusicStream (music );
6268 else ResumeMusicStream (music );
6369 }
70+
71+ // Set audio pan
72+ if (IsKeyDown (KEY_LEFT ))
73+ {
74+ pan -= 0.05f ;
75+ if (pan < -1.0f ) pan = -1.0f ;
76+ SetMusicPan (music , pan );
77+ }
78+ else if (IsKeyDown (KEY_RIGHT ))
79+ {
80+ pan += 0.05f ;
81+ if (pan > 1.0f ) pan = 1.0f ;
82+ SetMusicPan (music , pan );
83+ }
84+
85+ // Set audio volume
86+ if (IsKeyDown (KEY_DOWN ))
87+ {
88+ volume -= 0.05f ;
89+ if (volume < 0.0f ) volume = 0.0f ;
90+ SetMusicVolume (music , volume );
91+ }
92+ else if (IsKeyDown (KEY_UP ))
93+ {
94+ volume += 0.05f ;
95+ if (volume > 1.0f ) volume = 1.0f ;
96+ SetMusicVolume (music , volume );
97+ }
6498
6599 // Get normalized time played for current music stream
66100 timePlayed = GetMusicTimePlayed (music )/GetMusicTimeLength (music );
@@ -75,13 +109,23 @@ int main(void)
75109 ClearBackground (RAYWHITE );
76110
77111 DrawText ("MUSIC SHOULD BE PLAYING!" , 255 , 150 , 20 , LIGHTGRAY );
112+
113+ DrawText ("LEFT-RIGHT for PAN CONTROL" , 320 , 74 , 10 , DARKBLUE );
114+ DrawRectangle (300 , 100 , 200 , 12 , LIGHTGRAY );
115+ DrawRectangleLines (300 , 100 , 200 , 12 , GRAY );
116+ DrawRectangle (300 + (pan + 1.0 )/2.0f * 200 - 5 , 92 , 10 , 28 , DARKGRAY );
78117
79118 DrawRectangle (200 , 200 , 400 , 12 , LIGHTGRAY );
80119 DrawRectangle (200 , 200 , (int )(timePlayed * 400.0f ), 12 , MAROON );
81120 DrawRectangleLines (200 , 200 , 400 , 12 , GRAY );
82121
83122 DrawText ("PRESS SPACE TO RESTART MUSIC" , 215 , 250 , 20 , LIGHTGRAY );
84123 DrawText ("PRESS P TO PAUSE/RESUME MUSIC" , 208 , 280 , 20 , LIGHTGRAY );
124+
125+ DrawText ("UP-DOWN for VOLUME CONTROL" , 320 , 334 , 10 , DARKGREEN );
126+ DrawRectangle (300 , 360 , 200 , 12 , LIGHTGRAY );
127+ DrawRectangleLines (300 , 360 , 200 , 12 , GRAY );
128+ DrawRectangle (300 + volume * 200 - 5 , 352 , 10 , 28 , DARKGRAY );
85129
86130 EndDrawing ();
87131 //----------------------------------------------------------------------------------
0 commit comments