Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
2f524481c1
974 changed files with 295448 additions and 0 deletions
18
samples/sound/Makefile
Normal file
18
samples/sound/Makefile
Normal file
|
@ -0,0 +1,18 @@
|
|||
EXEC = sound
|
||||
OBJ = Sound.o
|
||||
|
||||
all: $(EXEC)
|
||||
|
||||
sound: $(OBJ)
|
||||
$(CC) $(LDFLAGS) -o $(EXECPATH)/$@ $(OBJ) -lsfml-audio -lsfml-system
|
||||
|
||||
%.o: %.cpp
|
||||
$(CC) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
@rm -rf *.o
|
||||
|
||||
mrproper: clean
|
||||
@rm -rf $(EXECPATH)/$(EXEC)
|
96
samples/sound/Sound.cpp
Normal file
96
samples/sound/Sound.cpp
Normal file
|
@ -0,0 +1,96 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Play a sound
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void PlaySound()
|
||||
{
|
||||
// Load a sound buffer from a wav file
|
||||
sf::SoundBuffer Buffer;
|
||||
if (!Buffer.LoadFromFile("datas/sound/footsteps.wav"))
|
||||
return;
|
||||
|
||||
// Display sound informations
|
||||
std::cout << "footsteps.wav :" << std::endl;
|
||||
std::cout << " " << Buffer.GetDuration() << " sec" << std::endl;
|
||||
std::cout << " " << Buffer.GetSampleRate() << " samples / sec" << std::endl;
|
||||
std::cout << " " << Buffer.GetChannelsCount() << " channels" << std::endl;
|
||||
|
||||
// Create a sound instance and play it
|
||||
sf::Sound Sound(Buffer);
|
||||
Sound.Play();
|
||||
|
||||
// Loop while the sound is playing
|
||||
while (Sound.GetStatus() == sf::Sound::Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec ";
|
||||
|
||||
// Leave some CPU time for other processes
|
||||
sf::Sleep(0.1f);
|
||||
}
|
||||
std::cout << std::endl << std::endl;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Play a music
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void PlayMusic()
|
||||
{
|
||||
// Load an ogg music file
|
||||
sf::Music Music;
|
||||
if (!Music.OpenFromFile("datas/sound/lepidoptera.ogg"))
|
||||
return;
|
||||
|
||||
// Display music informations
|
||||
std::cout << "lepidoptera.ogg :" << std::endl;
|
||||
std::cout << " " << Music.GetDuration() << " sec" << std::endl;
|
||||
std::cout << " " << Music.GetSampleRate() << " samples / sec" << std::endl;
|
||||
std::cout << " " << Music.GetChannelsCount() << " channels" << std::endl;
|
||||
|
||||
// Play it
|
||||
Music.Play();
|
||||
|
||||
// Loop while the music is playing
|
||||
while (Music.GetStatus() == sf::Music::Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Music.GetPlayingOffset() << " sec ";
|
||||
|
||||
// Leave some CPU time for other processes
|
||||
sf::Sleep(0.1f);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Play a sound
|
||||
PlaySound();
|
||||
|
||||
// Play a music
|
||||
PlayMusic();
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
std::cout << "Press enter to exit..." << std::endl;
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue