2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* audio_server.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef AUDIO_SERVER_H
|
|
|
|
#define AUDIO_SERVER_H
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/math/audio_frame.h"
|
|
|
|
#include "core/object.h"
|
|
|
|
#include "core/os/os.h"
|
|
|
|
#include "core/variant.h"
|
2017-01-15 20:06:14 +01:00
|
|
|
#include "servers/audio/audio_effect.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-13 18:34:22 +02:00
|
|
|
class AudioDriverDummy;
|
2018-02-27 08:54:56 +01:00
|
|
|
class AudioStream;
|
|
|
|
class AudioStreamSample;
|
2017-09-13 18:34:22 +02:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
class AudioDriver {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
static AudioDriver *singleton;
|
|
|
|
uint64_t _last_mix_time;
|
2019-04-27 17:22:47 +02:00
|
|
|
uint64_t _last_mix_frames;
|
2017-01-15 20:06:14 +01:00
|
|
|
|
2018-06-21 02:02:02 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
uint64_t prof_ticks;
|
|
|
|
uint64_t prof_time;
|
|
|
|
#endif
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
protected:
|
2019-07-09 19:11:11 +02:00
|
|
|
PoolVector<int32_t> capture_buffer;
|
|
|
|
unsigned int capture_position;
|
|
|
|
unsigned int capture_size;
|
2018-07-04 03:08:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true);
|
2017-01-15 20:06:14 +01:00
|
|
|
void update_mix_time(int p_frames);
|
2019-07-09 19:11:11 +02:00
|
|
|
void capture_buffer_init(int driver_buffer_frames);
|
|
|
|
void capture_buffer_write(int32_t sample);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-06-21 02:02:02 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
_FORCE_INLINE_ void start_counting_ticks() { prof_ticks = OS::get_singleton()->get_ticks_usec(); }
|
|
|
|
_FORCE_INLINE_ void stop_counting_ticks() { prof_time += OS::get_singleton()->get_ticks_usec() - prof_ticks; }
|
|
|
|
#else
|
|
|
|
_FORCE_INLINE_ void start_counting_ticks() {}
|
|
|
|
_FORCE_INLINE_ void stop_counting_ticks() {}
|
|
|
|
#endif
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
public:
|
2019-04-27 17:22:47 +02:00
|
|
|
double get_time_since_last_mix() const; //useful for video -> audio sync
|
|
|
|
double get_time_to_next_mix() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
enum SpeakerMode {
|
|
|
|
SPEAKER_MODE_STEREO,
|
2017-08-22 23:27:17 +02:00
|
|
|
SPEAKER_SURROUND_31,
|
2017-01-15 20:06:14 +01:00
|
|
|
SPEAKER_SURROUND_51,
|
|
|
|
SPEAKER_SURROUND_71,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-08-29 21:47:44 +02:00
|
|
|
static const int DEFAULT_MIX_RATE = 44100;
|
|
|
|
static const int DEFAULT_OUTPUT_LATENCY = 15;
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
static AudioDriver *get_singleton();
|
|
|
|
void set_singleton();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual const char *get_name() const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual Error init() = 0;
|
|
|
|
virtual void start() = 0;
|
|
|
|
virtual int get_mix_rate() const = 0;
|
|
|
|
virtual SpeakerMode get_speaker_mode() const = 0;
|
2018-03-25 05:43:51 +02:00
|
|
|
virtual Array get_device_list();
|
|
|
|
virtual String get_device();
|
|
|
|
virtual void set_device(String device) {}
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void lock() = 0;
|
|
|
|
virtual void unlock() = 0;
|
|
|
|
virtual void finish() = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-07-04 03:08:43 +02:00
|
|
|
virtual Error capture_start() { return FAILED; }
|
|
|
|
virtual Error capture_stop() { return FAILED; }
|
2018-07-25 20:35:52 +02:00
|
|
|
virtual void capture_set_device(const String &p_name) {}
|
|
|
|
virtual String capture_get_device() { return "Default"; }
|
2018-07-04 03:08:43 +02:00
|
|
|
virtual Array capture_get_device_list(); // TODO: convert this and get_device_list to PoolStringArray
|
2018-02-27 08:54:56 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
virtual float get_latency() { return 0; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-22 23:27:17 +02:00
|
|
|
SpeakerMode get_speaker_mode_by_total_channels(int p_channels) const;
|
|
|
|
int get_total_channels_by_speaker_mode(SpeakerMode) const;
|
|
|
|
|
2019-07-09 19:11:11 +02:00
|
|
|
PoolVector<int32_t> get_capture_buffer() { return capture_buffer; }
|
|
|
|
unsigned int get_capture_position() { return capture_position; }
|
|
|
|
unsigned int get_capture_size() { return capture_size; }
|
2018-02-27 08:54:56 +01:00
|
|
|
|
2019-10-12 00:40:43 +02:00
|
|
|
void clear_capture_buffer() { capture_buffer.resize(0); }
|
|
|
|
|
2018-06-21 02:02:02 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
uint64_t get_profiling_time() const { return prof_time; }
|
|
|
|
void reset_profiling_time() { prof_time = 0; }
|
|
|
|
#endif
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
AudioDriver();
|
|
|
|
virtual ~AudioDriver() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
class AudioDriverManager {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
enum {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MAX_DRIVERS = 10
|
2017-01-15 20:06:14 +01:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
static AudioDriver *drivers[MAX_DRIVERS];
|
|
|
|
static int driver_count;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-13 18:34:22 +02:00
|
|
|
static AudioDriverDummy dummy_driver;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-01-15 20:06:14 +01:00
|
|
|
static void add_driver(AudioDriver *p_driver);
|
2017-09-13 18:34:22 +02:00
|
|
|
static void initialize(int p_driver);
|
2017-01-15 20:06:14 +01:00
|
|
|
static int get_driver_count();
|
|
|
|
static AudioDriver *get_driver(int p_driver);
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-25 18:30:40 +01:00
|
|
|
class AudioBusLayout;
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
class AudioServer : public Object {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-03-19 19:35:57 +01:00
|
|
|
GDCLASS(AudioServer, Object);
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
public:
|
2019-05-30 13:47:18 +02:00
|
|
|
//re-expose this here, as AudioDriver is not exposed to script
|
2017-01-15 20:06:14 +01:00
|
|
|
enum SpeakerMode {
|
|
|
|
SPEAKER_MODE_STEREO,
|
2017-08-22 23:27:17 +02:00
|
|
|
SPEAKER_SURROUND_31,
|
2017-01-15 20:06:14 +01:00
|
|
|
SPEAKER_SURROUND_51,
|
|
|
|
SPEAKER_SURROUND_71,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2017-01-21 23:00:25 +01:00
|
|
|
|
|
|
|
enum {
|
2017-03-05 16:44:50 +01:00
|
|
|
AUDIO_DATA_INVALID_ID = -1
|
2017-01-21 23:00:25 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
typedef void (*AudioCallback)(void *p_userdata);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
private:
|
2019-04-27 17:22:47 +02:00
|
|
|
uint64_t mix_time;
|
|
|
|
int mix_size;
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
uint32_t buffer_size;
|
2017-01-21 23:00:25 +01:00
|
|
|
uint64_t mix_count;
|
|
|
|
uint64_t mix_frames;
|
2018-06-21 02:02:02 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
uint64_t prof_time;
|
|
|
|
#endif
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-07-08 17:12:18 +02:00
|
|
|
float channel_disable_threshold_db;
|
2017-01-21 23:00:25 +01:00
|
|
|
uint32_t channel_disable_frames;
|
|
|
|
|
2018-03-18 02:43:32 +01:00
|
|
|
int channel_count;
|
2017-01-21 23:00:25 +01:00
|
|
|
int to_mix;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-06-03 01:01:42 +02:00
|
|
|
float global_rate_scale;
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
struct Bus {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-21 23:00:25 +01:00
|
|
|
StringName name;
|
|
|
|
bool solo;
|
|
|
|
bool mute;
|
|
|
|
bool bypass;
|
|
|
|
|
2017-08-18 23:19:12 +02:00
|
|
|
bool soloed;
|
|
|
|
|
2017-01-21 23:00:25 +01:00
|
|
|
//Each channel is a stereo pair.
|
|
|
|
struct Channel {
|
|
|
|
bool used;
|
|
|
|
bool active;
|
|
|
|
AudioFrame peak_volume;
|
|
|
|
Vector<AudioFrame> buffer;
|
|
|
|
Vector<Ref<AudioEffectInstance> > effect_instances;
|
|
|
|
uint64_t last_mix_with_audio;
|
2017-03-05 16:44:50 +01:00
|
|
|
Channel() {
|
|
|
|
last_mix_with_audio = 0;
|
|
|
|
used = false;
|
|
|
|
active = false;
|
|
|
|
peak_volume = AudioFrame(0, 0);
|
|
|
|
}
|
2017-01-21 23:00:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Channel> channels;
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
struct Effect {
|
|
|
|
Ref<AudioEffect> effect;
|
|
|
|
bool enabled;
|
2018-06-21 02:02:02 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
uint64_t prof_time;
|
|
|
|
#endif
|
2017-01-15 20:06:14 +01:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
Vector<Effect> effects;
|
|
|
|
float volume_db;
|
2017-01-21 23:00:25 +01:00
|
|
|
StringName send;
|
|
|
|
int index_cache;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector<Vector<AudioFrame> > temp_buffer; //temp_buffer for each level
|
|
|
|
Vector<Bus *> buses;
|
|
|
|
Map<StringName, Bus *> bus_map;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-21 23:00:25 +01:00
|
|
|
void _update_bus_effects(int p_bus);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static AudioServer *singleton;
|
2017-01-21 23:00:25 +01:00
|
|
|
|
|
|
|
// TODO create an audiodata pool to optimize memory
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<void *, uint32_t> audio_data;
|
2017-01-21 23:00:25 +01:00
|
|
|
size_t audio_data_total_mem;
|
|
|
|
size_t audio_data_max_mem;
|
|
|
|
|
|
|
|
Mutex *audio_data_lock;
|
|
|
|
|
2018-07-17 03:43:47 +02:00
|
|
|
float output_latency;
|
|
|
|
uint64_t output_latency_ticks;
|
|
|
|
|
2018-03-18 02:43:32 +01:00
|
|
|
void init_channels_and_buffers();
|
|
|
|
|
2017-01-21 23:00:25 +01:00
|
|
|
void _mix_step();
|
|
|
|
|
2018-02-27 08:54:56 +01:00
|
|
|
#if 0
|
|
|
|
struct AudioInBlock {
|
|
|
|
|
|
|
|
Ref<AudioStreamSample> audio_stream;
|
|
|
|
int current_position;
|
|
|
|
bool loops;
|
|
|
|
};
|
|
|
|
|
|
|
|
Map<StringName, AudioInBlock *> audio_in_block_map;
|
|
|
|
Vector<AudioInBlock *> audio_in_blocks;
|
|
|
|
#endif
|
|
|
|
|
2017-01-21 23:00:25 +01:00
|
|
|
struct CallbackItem {
|
|
|
|
|
|
|
|
AudioCallback callback;
|
|
|
|
void *userdata;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator<(const CallbackItem &p_item) const {
|
|
|
|
return (callback == p_item.callback ? userdata < p_item.userdata : callback < p_item.callback);
|
2017-01-21 23:00:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Set<CallbackItem> callbacks;
|
2018-10-10 15:58:29 +02:00
|
|
|
Set<CallbackItem> update_callbacks;
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
friend class AudioDriver;
|
2017-01-21 23:00:25 +01:00
|
|
|
void _driver_process(int p_frames, int32_t *p_buffer);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2017-01-21 23:00:25 +01:00
|
|
|
static void _bind_methods();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-08-22 23:27:17 +02:00
|
|
|
_FORCE_INLINE_ int get_channel_count() const {
|
|
|
|
switch (get_speaker_mode()) {
|
|
|
|
case SPEAKER_MODE_STEREO: return 1;
|
|
|
|
case SPEAKER_SURROUND_31: return 2;
|
|
|
|
case SPEAKER_SURROUND_51: return 3;
|
|
|
|
case SPEAKER_SURROUND_71: return 4;
|
|
|
|
}
|
|
|
|
ERR_FAIL_V(1);
|
|
|
|
}
|
|
|
|
|
2017-01-21 23:00:25 +01:00
|
|
|
//do not use from outside audio thread
|
2018-11-13 22:16:33 +01:00
|
|
|
bool thread_has_channel_mix_buffer(int p_bus, int p_buffer) const;
|
2017-03-05 16:44:50 +01:00
|
|
|
AudioFrame *thread_get_channel_mix_buffer(int p_bus, int p_buffer);
|
2017-01-21 23:00:25 +01:00
|
|
|
int thread_get_mix_buffer_size() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
int thread_find_bus_index(const StringName &p_name);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
void set_bus_count(int p_count);
|
|
|
|
int get_bus_count() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-24 03:12:08 +01:00
|
|
|
void remove_bus(int p_index);
|
2017-03-05 16:44:50 +01:00
|
|
|
void add_bus(int p_at_pos = -1);
|
2017-01-24 03:12:08 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void move_bus(int p_bus, int p_to_pos);
|
2017-01-24 03:12:08 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bus_name(int p_bus, const String &p_name);
|
2017-01-15 20:06:14 +01:00
|
|
|
String get_bus_name(int p_bus) const;
|
2017-07-10 22:51:29 +02:00
|
|
|
int get_bus_index(const StringName &p_bus_name) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-12-07 17:38:40 +01:00
|
|
|
int get_bus_channels(int p_bus) const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bus_volume_db(int p_bus, float p_volume_db);
|
2017-01-15 20:06:14 +01:00
|
|
|
float get_bus_volume_db(int p_bus) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bus_send(int p_bus, const StringName &p_send);
|
2017-01-21 23:00:25 +01:00
|
|
|
StringName get_bus_send(int p_bus) const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bus_solo(int p_bus, bool p_enable);
|
2017-01-21 23:00:25 +01:00
|
|
|
bool is_bus_solo(int p_bus) const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bus_mute(int p_bus, bool p_enable);
|
2017-01-21 23:00:25 +01:00
|
|
|
bool is_bus_mute(int p_bus) const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bus_bypass_effects(int p_bus, bool p_enable);
|
2017-01-21 23:00:25 +01:00
|
|
|
bool is_bus_bypassing_effects(int p_bus) const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void add_bus_effect(int p_bus, const Ref<AudioEffect> &p_effect, int p_at_pos = -1);
|
|
|
|
void remove_bus_effect(int p_bus, int p_effect);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
int get_bus_effect_count(int p_bus);
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<AudioEffect> get_bus_effect(int p_bus, int p_effect);
|
2019-04-10 17:57:03 +02:00
|
|
|
Ref<AudioEffectInstance> get_bus_effect_instance(int p_bus, int p_effect, int p_channel = 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void swap_bus_effects(int p_bus, int p_effect, int p_by_effect);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bus_effect_enabled(int p_bus, int p_effect, bool p_enabled);
|
|
|
|
bool is_bus_effect_enabled(int p_bus, int p_effect) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float get_bus_peak_volume_left_db(int p_bus, int p_channel) const;
|
|
|
|
float get_bus_peak_volume_right_db(int p_bus, int p_channel) const;
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool is_bus_channel_active(int p_bus, int p_channel) const;
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2019-06-03 01:01:42 +02:00
|
|
|
void set_global_rate_scale(float p_scale);
|
|
|
|
float get_global_rate_scale() const;
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
virtual void init();
|
|
|
|
virtual void finish();
|
2018-06-21 02:02:02 +02:00
|
|
|
virtual void update();
|
2017-01-25 18:30:40 +01:00
|
|
|
virtual void load_default_bus_layout();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/* MISC config */
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
virtual void lock();
|
|
|
|
virtual void unlock();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
virtual SpeakerMode get_speaker_mode() const;
|
|
|
|
virtual float get_mix_rate() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
virtual float read_output_peak_db() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static AudioServer *get_singleton();
|
|
|
|
|
2019-04-27 17:22:47 +02:00
|
|
|
virtual double get_output_latency() const;
|
|
|
|
virtual double get_time_to_next_mix() const;
|
2019-04-27 19:05:16 +02:00
|
|
|
virtual double get_time_since_last_mix() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void *audio_data_alloc(uint32_t p_data_len, const uint8_t *p_from_data = NULL);
|
|
|
|
void audio_data_free(void *p_data);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
|
|
|
size_t audio_data_get_total_memory_usage() const;
|
|
|
|
size_t audio_data_get_max_memory_usage() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void add_callback(AudioCallback p_callback, void *p_userdata);
|
|
|
|
void remove_callback(AudioCallback p_callback, void *p_userdata);
|
2017-01-21 23:00:25 +01:00
|
|
|
|
2018-10-10 15:58:29 +02:00
|
|
|
void add_update_callback(AudioCallback p_callback, void *p_userdata);
|
|
|
|
void remove_update_callback(AudioCallback p_callback, void *p_userdata);
|
|
|
|
|
2017-03-13 16:45:27 +01:00
|
|
|
void set_bus_layout(const Ref<AudioBusLayout> &p_bus_layout);
|
2017-01-25 18:30:40 +01:00
|
|
|
Ref<AudioBusLayout> generate_bus_layout() const;
|
|
|
|
|
2018-03-25 05:43:51 +02:00
|
|
|
Array get_device_list();
|
|
|
|
String get_device();
|
|
|
|
void set_device(String device);
|
|
|
|
|
2019-07-09 19:11:11 +02:00
|
|
|
Error capture_start();
|
|
|
|
Error capture_stop();
|
|
|
|
|
2018-07-04 03:08:43 +02:00
|
|
|
Array capture_get_device_list();
|
2018-07-25 20:35:52 +02:00
|
|
|
String capture_get_device();
|
|
|
|
void capture_set_device(const String &p_name);
|
2018-07-17 03:43:47 +02:00
|
|
|
|
2019-07-09 19:11:11 +02:00
|
|
|
PoolVector<int32_t> get_capture_buffer();
|
|
|
|
unsigned int get_capture_position();
|
|
|
|
unsigned int get_capture_size();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
AudioServer();
|
|
|
|
virtual ~AudioServer();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VARIANT_ENUM_CAST(AudioServer::SpeakerMode)
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-25 18:30:40 +01:00
|
|
|
class AudioBusLayout : public Resource {
|
|
|
|
|
2019-03-19 19:35:57 +01:00
|
|
|
GDCLASS(AudioBusLayout, Resource);
|
2017-01-25 18:30:40 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
friend class AudioServer;
|
2017-01-25 18:30:40 +01:00
|
|
|
|
|
|
|
struct Bus {
|
|
|
|
|
|
|
|
StringName name;
|
|
|
|
bool solo;
|
|
|
|
bool mute;
|
|
|
|
bool bypass;
|
|
|
|
|
|
|
|
struct Effect {
|
|
|
|
Ref<AudioEffect> effect;
|
|
|
|
bool enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Effect> effects;
|
|
|
|
|
|
|
|
float volume_db;
|
|
|
|
StringName send;
|
|
|
|
|
|
|
|
Bus() {
|
2017-03-05 16:44:50 +01:00
|
|
|
solo = false;
|
|
|
|
mute = false;
|
|
|
|
bypass = false;
|
|
|
|
volume_db = 0;
|
2017-01-25 18:30:40 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Bus> buses;
|
|
|
|
|
|
|
|
protected:
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2017-01-25 18:30:40 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
AudioBusLayout();
|
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
typedef AudioServer AS;
|
|
|
|
|
|
|
|
#endif // AUDIO_SERVER_H
|