Skip to content

Commit 20f213b

Browse files
committed
Added a FLAC file to the Sound example to cover all three supported formats.
1 parent 23cc8cf commit 20f213b

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

.gitattributes

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cmake/toolchains/android.toolchain.cmake -text -eol
77
*.jpg -text -eol
88
*.wav -text -eol
99
*.ogg -text -eol
10+
*.flac -text -eol
1011
*.tff -text -eol
1112
*.icns -text -eol
12-
*.rtf -text -eol
13+
*.rtf -text -eol

examples/sound/Sound.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <SFML/Audio.hpp>
66
#include <iomanip>
77
#include <iostream>
8+
#include <string>
89

910

1011
////////////////////////////////////////////////////////////
@@ -46,15 +47,15 @@ void playSound()
4647
/// Play a music
4748
///
4849
////////////////////////////////////////////////////////////
49-
void playMusic()
50+
void playMusic(const std::string& filename)
5051
{
5152
// Load an ogg music file
5253
sf::Music music;
53-
if (!music.openFromFile("resources/orchestral.ogg"))
54+
if (!music.openFromFile("resources/" + filename))
5455
return;
5556

5657
// Display music informations
57-
std::cout << "orchestral.ogg:" << std::endl;
58+
std::cout << filename << ":" << std::endl;
5859
std::cout << " " << music.getDuration().asSeconds() << " seconds" << std::endl;
5960
std::cout << " " << music.getSampleRate() << " samples / sec" << std::endl;
6061
std::cout << " " << music.getChannelCount() << " channels" << std::endl;
@@ -72,7 +73,7 @@ void playMusic()
7273
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << music.getPlayingOffset().asSeconds() << " sec ";
7374
std::cout << std::flush;
7475
}
75-
std::cout << std::endl;
76+
std::cout << std::endl << std::endl;
7677
}
7778

7879

@@ -87,8 +88,11 @@ int main()
8788
// Play a sound
8889
playSound();
8990

90-
// Play a music
91-
playMusic();
91+
// Play music from an ogg file
92+
playMusic("orchestral.ogg");
93+
94+
// Play music from a flac file
95+
playMusic("ding.flac");
9296

9397
// Wait until the user presses 'enter' key
9498
std::cout << "Press enter to exit..." << std::endl;

examples/sound/resources/ding.flac

60.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)