Commit 8f8b89dc authored by Sreekanth Arikatla's avatar Sreekanth Arikatla

ENH: Add audio testing examples in sandbox

Add audio testing examples in sandbox. Add resources to the data folder
parent dbdd4ff2
......@@ -16,5 +16,4 @@ imstk_add_external_project( SFML
#DEPENDENCIES ""
#RELATIVE_INCLUDE_PATH ""
#VERBOSE
)
)
\ No newline at end of file
b8303ca5a68bd728fb313cbc6ffc88b33ba4668b00a6e708a945336fd726b8af47bb6bc33e36979b4587cf4a06595f4083c6d2ba9eedcf4ff0ba1426a86dfe16
\ No newline at end of file
356a8e10d5ed4da394e57d8cb46aeef552f18af12732a32fbac540ac908f3c18c8f4e1a41b1ce4e91ef21d227a0b4f8acd3efd8d7b4f6503d119935d59c47170
\ No newline at end of file
......@@ -28,6 +28,7 @@ add_executable(${PROJECT_NAME} main.cpp)
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME}
SimulationManager
SFML
)
#-----------------------------------------------------------------------------
......@@ -48,6 +49,7 @@ list(APPEND FILE_LIST
spheres/,REGEX:.*
spring/,REGEX:.*
tetBeads/,REGEX:.*
sound/,REGEX:.*
textured_organs/,REGEX:.*
textured_organs/texture_set_1/,REGEX:.*
textured_organs/texture_set_2/,REGEX:.*
......
......@@ -97,6 +97,9 @@
#include <string>
#include <vtkJPEGReader.h>
// Audio
#include <SFML/Audio.hpp>
// global variables
const std::string phantomOmni1Name = "Phantom1";
const std::string phantomOmni2Name = "Phantom2";
......@@ -3334,6 +3337,94 @@ void testRigidBody()
sdk->startSimulation(false);
}
// Example modified from SFML/Examples
void testSound(const std::string& filename)
{
// Load a sound buffer from a .wav file
sf::SoundBuffer buffer;
if (!buffer.loadFromFile(filename))
{
LOG(WARNING) << "testSound: Could not open the input sound file: " << filename;
return;
}
// Display sound informations
std::cout << filename << std::endl;
std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
std::cout << " " << buffer.getSampleRate() << " samples / sec" << std::endl;
std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
// Create a sound instance and play it
sf::Sound sound(buffer);
sound.setPosition(0., 0., 0.);
sound.setMinDistance(5.);
sound.setAttenuation(10.);
sound.play();
Vec3d listnerPos(-5., -5., -5.);
// Loop while the sound is playing
while (sound.getStatus() == sf::Sound::Playing)
{
// Leave some CPU time for other processes
sf::sleep(sf::milliseconds(100));
// Move the listener away
listnerPos += Vec3d(.2, .2, .2);
sf::Listener::setPosition(listnerPos.x(), listnerPos.y(), listnerPos.z());
// Display the playing position
std::cout << "\rPlaying... " << sound.getPlayingOffset().asSeconds() << " sec ";
std::cout << std::flush;
}
std::cout << "\n" << std::endl;
}
// Example modified from SFML/Examples
void playMusic(const std::string& filename)
{
// Load an ogg music file
sf::Music music;
if (!music.openFromFile(filename))
{
LOG(WARNING) << "playMusic: Could not open the input music file: " << filename;
return;
}
// Display music informations
std::cout << filename << ":" << std::endl;
std::cout << " " << music.getDuration().asSeconds() << " seconds" << std::endl;
std::cout << " " << music.getSampleRate() << " samples / sec" << std::endl;
std::cout << " " << music.getChannelCount() << " channels" << std::endl;
// Play it
music.play();
// Loop while the music is playing
while (music.getStatus() == sf::Music::Playing)
{
// Leave some CPU time for other processes
sf::sleep(sf::milliseconds(100));
// Display the playing position
std::cout << "\rPlaying... " << music.getPlayingOffset().asSeconds() << " sec ";
std::cout << std::flush;
}
std::cout << "\n" << std::endl;
}
void testAudio()
{
std::cout << "--Testing audio--\n\n";
// Test a sound
testSound(iMSTK_DATA_ROOT "/sound/canary.wav");
// Test music from an .ogg file
playMusic(iMSTK_DATA_ROOT "/sound/orchestral.ogg");
}
int main()
{
std::cout << "****************\n"
......@@ -3402,6 +3493,7 @@ int main()
/*------------------
Test Misc.
------------------*/
testAudio();
//testScenesManagement();
//testVectorPlotters();
//testVirtualCoupling();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment