-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTut34.cpp
53 lines (46 loc) · 1.31 KB
/
Tut34.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// C++ Sfml Made Easy Tutorial 34 - Recording Sounds
// CodingMadeEasy
#include<iostream>
#include<SFML/Audio.hpp>
#include<SFML/Graphics.hpp>
#define ScreenWidth 800
#define ScreenHeight 600
int main()
{
sf::RenderWindow Window(sf::VideoMode(ScreenWidth, ScreenHeight, 32), "SFML Made Easy");
sf::SoundBufferRecorder recorder;
sf::SoundBuffer soundBuffer;
sf::Sound sound;
bool playRecording = true;
while(Window.IsOpened())
{
sf::Event Event;
while(Window.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed || Event.Key.Code == sf::Key::Escape)
Window.Close();
if(Event.Key.Code == sf::Key::R)
{
if(sf::SoundRecorder::CanCapture())
recorder.Start();
else
std::cout << "Error" << std::endl;
}
if(Event.Key.Code == sf::Key::S && !playRecording)
{
recorder.Stop();
soundBuffer = recorder.GetBuffer();
sound.SetBuffer(soundBuffer);
playRecording = true;
}
}
Window.Clear();
if(playRecording)
{
sound.Play();
playRecording = false;
}
Window.Display();
}
return 0;
}