summaryrefslogtreecommitdiffstats
path: root/include/xas/spatial.h
blob: af10ef4d9a7f1d5b699038dde1d01229127a2133 (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef _XAS_SPATIAL_H
#define _XAS_SPATIAL_H

#include <xas/synth.h>
#include <xas/bank.h>
#include <xas/audio.h>

#define XAS_SPATIAL_DEFAULT_OBSERVER_WIDTH   0.18f
#define XAS_SPATIAL_DEFAULT_RADIUS         4000.0f /* metres */
#define XAS_SPATIAL_DEFAULT_MEDIUM_SPEED    343.0f /* m/s */
#define XAS_SPATIAL_DEFAULT_OBJECT_SPEED      0.0f /* m/s */
#define XAS_SPATIAL_DEFAULT_CONE_ANGLE       35.0f /* degrees */

#define XAS_SPATIAL_OBJECT_NONE    0
#define XAS_SPATIAL_OBJECT_MANAGED (1 << 0)

typedef struct _xas_spatial_coord {
    float x, y, z;
} xas_spatial_coord;

typedef struct _xas_spatial_cone {
    xas_spatial_coord apex,
                        rotation;

    float angle;
} xas_spatial_cone;

typedef struct _xas_spatial_observer {
    xas_spatial_coord point,
                        rotation;

    float width;
} xas_spatial_observer;

typedef struct _xas_spatial_object xas_spatial_object;

struct _xas_spatial_object {
    float distance_l,
          distance_r;

    size_t delay_l,
           delay_r;

    ssize_t shift_l,
            shift_r;

    xas_audio_stream *source;
    void *ctx;
    int flags;

    xas_spatial_coord point,
                        heading;

    float speed;

    xas_spatial_object *next;
};

typedef struct _xas_spatial_buffer {
    size_t index,
           size;
} xas_spatial_buffer;

typedef struct _xas_spatial_scene {
    xas_audio_format format;

    xas_spatial_observer observer;

    xas_spatial_coord speaker_l,
                        speaker_r;

    float speed,
          radius;

    xas_spatial_object *first,
                         *last;

    xas_spatial_buffer *buffer;
} xas_spatial_scene;

xas_spatial_scene *xas_spatial_scene_new(xas_audio_format format,
                                             xas_spatial_coord speaker_l,
                                             xas_spatial_coord speaker_r);

void xas_spatial_scene_destroy(xas_spatial_scene *scene);

void xas_spatial_scene_set_observer(xas_spatial_scene *scene,
                                      xas_spatial_coord point,
                                      xas_spatial_coord rotation,
                                      float width);

void xas_spatial_scene_set_speaker_coords(xas_spatial_scene *scene,
                                            xas_spatial_coord speaker_l,
                                            xas_spatial_coord speaker_r);

int xas_spatial_scene_set_speed(xas_spatial_scene *scene, float speed);

int xas_spatial_scene_set_radius(xas_spatial_scene *scene, float radius);

xas_spatial_object *xas_spatial_scene_add_object(xas_spatial_scene *scene,
                                                     xas_spatial_coord point,
                                                     xas_audio_stream *source,
                                                     void *ctx);

xas_spatial_object *xas_spatial_scene_add_synth(xas_spatial_scene *scene,
                                                    xas_spatial_coord point,
                                                    enum xas_synth_type type);

xas_spatial_object *xas_spatial_scene_add_bank_player(xas_spatial_scene *scene,
                                                          xas_spatial_coord point,
                                                          xas_bank *bank);

xas_spatial_object *xas_spatial_scene_add_vox(xas_spatial_scene *scene,
                                                  xas_spatial_coord point,
                                                  const char *text2wave_path);

void xas_spatial_scene_position_object(xas_spatial_scene *scene,
                                         xas_spatial_object *object,
                                         xas_spatial_coord point);

int xas_spatial_object_start(xas_spatial_object *object);

int xas_spatial_object_stop(xas_spatial_object *object);

void xas_spatial_object_get_point(xas_spatial_object *object,
                                    xas_spatial_coord *point);

float xas_spatial_object_get_speed(xas_spatial_object *object);

void xas_spatial_object_set_speed(xas_spatial_object *object, float speed);

void xas_spatial_object_get_heading(xas_spatial_object *object,
                                      xas_spatial_coord *heading);

void xas_spatial_object_set_heading(xas_spatial_object *object,
                                      xas_spatial_coord heading);

xas_audio_stream *xas_spatial_scene_stream_new(xas_spatial_scene *scene,
                                                   size_t buffer_size);

#endif /* _XAS_SPATIAL_H */