-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound_test.cpp
114 lines (101 loc) · 2.67 KB
/
sound_test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "sound_controller.hpp"
#include <sge/exception.hpp>
#include <sge/systems/audio_loader.hpp>
#include <sge/systems/audio_player_default.hpp>
#include <sge/audio/loader_capabilities_field.hpp>
#include <sge/audio/loader.hpp>
#include <sge/extension_set.hpp>
#include <sge/systems/instance.hpp>
#include <sge/systems/list.hpp>
#include <sge/parse/json/object.hpp>
#include <sge/parse/json/parse_stream.hpp>
#include <sge/parse/json/find_member_exn.hpp>
#include <sge/parse/json/array.hpp>
#include <sge/time/timer.hpp>
#include <sge/time/second.hpp>
#include <sge/audio/vector.hpp>
#include <fcppt/text.hpp>
#include <fcppt/io/cout.hpp>
#include <fcppt/io/cerr.hpp>
#include <fcppt/io/istringstream.hpp>
#include <fcppt/exception.hpp>
#include <fcppt/from_std_string.hpp>
#include <fcppt/math/vector/basic_impl.hpp>
#include <exception>
#include <iostream>
#include <ostream>
#include <cstddef>
int main()
try
{
fcppt::io::istringstream ss(
fcppt::from_std_string(
"{\n"
" \"sounds\" : {\n"
" \"events\" : { \"skid\" : \"skid.wav\", \"motor\" : \"motor.wav\" }\n"
" }\n"
"}\n"));
fcppt::io::cout
<< FCPPT_TEXT("File looks like \n")
<< ss.str()
<< FCPPT_TEXT("\n");
sge::parse::json::object o;
if (!sge::parse::json::parse_stream(ss,o))
{
fcppt::io::cerr << FCPPT_TEXT("parse_stream failed\n");
return EXIT_FAILURE;
}
sge::systems::instance sys(
sge::systems::list()
(
sge::systems::audio_loader(
sge::audio::loader_capabilities_field::null(),
{FCPPT_TEXT("wav"),FCPPT_TEXT("ogg")}))
(sge::systems::audio_player_default()));
insula::sound_controller music(
sge::parse::json::find_member_exn<sge::parse::json::object>(
o.members,
FCPPT_TEXT("sounds")),
sys.audio_loader(),
sys.audio_player());
fcppt::io::cout << FCPPT_TEXT("Ok, playing the nonpositional event sound \"motor\"\n");
music.play(
FCPPT_TEXT("motor"));
sge::time::timer end_timer(
sge::time::second(
10));
sge::time::timer play_timer(
sge::time::second(
2));
bool played_sound = false;
while (true)
{
if (end_timer.expired())
break;
if (play_timer.expired() && !played_sound)
{
fcppt::io::cout << FCPPT_TEXT("Playing sound \"skid\", positional\n");
music.play_positional(
FCPPT_TEXT("skid"),
sge::audio::sound::positional_parameters()
.position(
sge::audio::vector(-3,0,0)));
played_sound = true;
}
}
}
catch(sge::exception const &e)
{
fcppt::io::cerr << e.string() << FCPPT_TEXT('\n');
return EXIT_FAILURE;
}
catch (fcppt::exception const &e)
{
fcppt::io::cerr << e.string() << FCPPT_TEXT('\n');
return EXIT_FAILURE;
}
catch(std::exception const &e)
{
std::cerr << e.what() << FCPPT_TEXT('\n');
return EXIT_FAILURE;
}