summaryrefslogtreecommitdiff
path: root/examples/sound_capture
diff options
context:
space:
mode:
authorJames Cowgill <james410@cowgill.org.uk>2014-12-09 20:21:40 +0000
committerJames Cowgill <james410@cowgill.org.uk>2014-12-09 20:21:40 +0000
commitfa21c65d0c764705cfc377bf0d0de08fac26874e (patch)
treedbc9e87bbd8684d15e79fc0c8b7a8985389c3b35 /examples/sound_capture
parentdd835931261c340acd5f0409341d13fa2670423e (diff)
Imported Upstream version 2.2.0+dfsg
Diffstat (limited to 'examples/sound_capture')
-rw-r--r--examples/sound_capture/CMakeLists.txt20
-rw-r--r--examples/sound_capture/SoundCapture.cpp190
2 files changed, 105 insertions, 105 deletions
diff --git a/examples/sound_capture/CMakeLists.txt b/examples/sound_capture/CMakeLists.txt
index ac75c3c..e62b3b3 100644
--- a/examples/sound_capture/CMakeLists.txt
+++ b/examples/sound_capture/CMakeLists.txt
@@ -1,10 +1,10 @@
-
-set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sound_capture)
-
-# all source files
-set(SRC ${SRCROOT}/SoundCapture.cpp)
-
-# define the sound-capture target
-sfml_add_example(sound-capture
- SOURCES ${SRC}
- DEPENDS sfml-audio sfml-system)
+
+set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sound_capture)
+
+# all source files
+set(SRC ${SRCROOT}/SoundCapture.cpp)
+
+# define the sound-capture target
+sfml_add_example(sound-capture
+ SOURCES ${SRC}
+ DEPENDS sfml-audio sfml-system)
diff --git a/examples/sound_capture/SoundCapture.cpp b/examples/sound_capture/SoundCapture.cpp
index a6946ac..02f2db2 100644
--- a/examples/sound_capture/SoundCapture.cpp
+++ b/examples/sound_capture/SoundCapture.cpp
@@ -1,95 +1,95 @@
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#include <SFML/Audio.hpp>
-#include <iomanip>
-#include <iostream>
-
-
-////////////////////////////////////////////////////////////
-/// Entry point of application
-///
-/// \return Application exit code
-///
-////////////////////////////////////////////////////////////
-int main()
-{
- // Check that the device can capture audio
- if (sf::SoundRecorder::isAvailable() == false)
- {
- std::cout << "Sorry, audio capture is not supported by your system" << std::endl;
- return EXIT_SUCCESS;
- }
-
- // Choose the sample rate
- unsigned int sampleRate;
- std::cout << "Please choose the sample rate for sound capture (44100 is CD quality) : ";
- std::cin >> sampleRate;
- std::cin.ignore(10000, '\n');
-
- // Wait for user input...
- std::cout << "Press enter to start recording audio";
- std::cin.ignore(10000, '\n');
-
- // Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer
- sf::SoundBufferRecorder recorder;
-
- // Audio capture is done in a separate thread, so we can block the main thread while it is capturing
- recorder.start(sampleRate);
- std::cout << "Recording... press enter to stop";
- std::cin.ignore(10000, '\n');
- recorder.stop();
-
- // Get the buffer containing the captured data
- const sf::SoundBuffer& buffer = recorder.getBuffer();
-
- // Display captured sound informations
- std::cout << "Sound information :" << std::endl;
- std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
- std::cout << " " << buffer.getSampleRate() << " samples / seconds" << std::endl;
- std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
-
- // Choose what to do with the recorded sound data
- char choice;
- std::cout << "What do you want to do with captured sound (p = play, s = save) ? ";
- std::cin >> choice;
- std::cin.ignore(10000, '\n');
-
- if (choice == 's')
- {
- // Choose the filename
- std::string filename;
- std::cout << "Choose the file to create : ";
- std::getline(std::cin, filename);
-
- // Save the buffer
- buffer.saveToFile(filename);
- }
- else
- {
- // Create a sound instance and play it
- sf::Sound sound(buffer);
- sound.play();
-
- // Wait until finished
- while (sound.getStatus() == sf::Sound::Playing)
- {
- // Display the playing position
- std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.getPlayingOffset().asSeconds() << " sec";
- std::cout << std::flush;
-
- // Leave some CPU time for other threads
- sf::sleep(sf::milliseconds(100));
- }
- }
-
- // Finished !
- std::cout << std::endl << "Done !" << std::endl;
-
- // Wait until the user presses 'enter' key
- std::cout << "Press enter to exit..." << std::endl;
- std::cin.ignore(10000, '\n');
-
- return EXIT_SUCCESS;
-}
+
+////////////////////////////////////////////////////////////
+// Headers
+////////////////////////////////////////////////////////////
+#include <SFML/Audio.hpp>
+#include <iomanip>
+#include <iostream>
+
+
+////////////////////////////////////////////////////////////
+/// Entry point of application
+///
+/// \return Application exit code
+///
+////////////////////////////////////////////////////////////
+int main()
+{
+ // Check that the device can capture audio
+ if (sf::SoundRecorder::isAvailable() == false)
+ {
+ std::cout << "Sorry, audio capture is not supported by your system" << std::endl;
+ return EXIT_SUCCESS;
+ }
+
+ // Choose the sample rate
+ unsigned int sampleRate;
+ std::cout << "Please choose the sample rate for sound capture (44100 is CD quality): ";
+ std::cin >> sampleRate;
+ std::cin.ignore(10000, '\n');
+
+ // Wait for user input...
+ std::cout << "Press enter to start recording audio";
+ std::cin.ignore(10000, '\n');
+
+ // Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer
+ sf::SoundBufferRecorder recorder;
+
+ // Audio capture is done in a separate thread, so we can block the main thread while it is capturing
+ recorder.start(sampleRate);
+ std::cout << "Recording... press enter to stop";
+ std::cin.ignore(10000, '\n');
+ recorder.stop();
+
+ // Get the buffer containing the captured data
+ const sf::SoundBuffer& buffer = recorder.getBuffer();
+
+ // Display captured sound informations
+ std::cout << "Sound information:" << std::endl;
+ std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
+ std::cout << " " << buffer.getSampleRate() << " samples / seconds" << std::endl;
+ std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
+
+ // Choose what to do with the recorded sound data
+ char choice;
+ std::cout << "What do you want to do with captured sound (p = play, s = save) ? ";
+ std::cin >> choice;
+ std::cin.ignore(10000, '\n');
+
+ if (choice == 's')
+ {
+ // Choose the filename
+ std::string filename;
+ std::cout << "Choose the file to create: ";
+ std::getline(std::cin, filename);
+
+ // Save the buffer
+ buffer.saveToFile(filename);
+ }
+ else
+ {
+ // Create a sound instance and play it
+ sf::Sound sound(buffer);
+ sound.play();
+
+ // Wait until finished
+ while (sound.getStatus() == sf::Sound::Playing)
+ {
+ // Display the playing position
+ std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.getPlayingOffset().asSeconds() << " sec";
+ std::cout << std::flush;
+
+ // Leave some CPU time for other threads
+ sf::sleep(sf::milliseconds(100));
+ }
+ }
+
+ // Finished!
+ std::cout << std::endl << "Done!" << std::endl;
+
+ // Wait until the user presses 'enter' key
+ std::cout << "Press enter to exit..." << std::endl;
+ std::cin.ignore(10000, '\n');
+
+ return EXIT_SUCCESS;
+}