godot/servers/audio_server.h

202 lines
5.3 KiB
C++
Raw Normal View History

2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* audio_server.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
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. */
/*************************************************************************/
#ifndef AUDIO_SERVER_H
#define AUDIO_SERVER_H
#include "variant.h"
#include "object.h"
2017-01-15 20:06:14 +01:00
#include "audio_frame.h"
#include "servers/audio/audio_effect.h"
2014-02-10 02:10:30 +01: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;
uint64_t _mix_amount;
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
protected:
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
void audio_server_process(int p_frames,int32_t *p_buffer,bool p_update_mix_time=true);
void update_mix_time(int p_frames);
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
public:
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
double get_mix_time() const; //useful for video -> audio sync
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
enum SpeakerMode {
SPEAKER_MODE_STEREO,
SPEAKER_SURROUND_51,
SPEAKER_SURROUND_71,
2014-02-10 02:10:30 +01:00
};
2017-01-15 20:06:14 +01:00
static AudioDriver *get_singleton();
void set_singleton();
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
virtual const char* get_name() const=0;
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
virtual Error init()=0;
virtual void start()=0;
virtual int get_mix_rate() const =0;
virtual SpeakerMode get_speaker_mode() const=0;
virtual void lock()=0;
virtual void unlock()=0;
virtual void finish()=0;
2014-02-10 02:10:30 +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-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-01-15 20:06:14 +01:00
MAX_DRIVERS=10
};
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
public:
2017-01-15 20:06:14 +01:00
static void add_driver(AudioDriver *p_driver);
static int get_driver_count();
static AudioDriver *get_driver(int p_driver);
};
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
class AudioServer : public Object {
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
GDCLASS( AudioServer, Object )
public:
enum BusMode {
BUS_MODE_STEREO,
BUS_MODE_SURROUND
2014-02-10 02:10:30 +01:00
};
2017-01-15 20:06:14 +01:00
//re-expose this her, as AudioDriver is not exposed to script
enum SpeakerMode {
SPEAKER_MODE_STEREO,
SPEAKER_SURROUND_51,
SPEAKER_SURROUND_71,
2014-02-10 02:10:30 +01:00
};
2017-01-15 20:06:14 +01:00
private:
uint32_t buffer_size;
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
struct Bus {
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
String name;
BusMode mode;
Vector<AudioFrame> buffer;
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
struct Effect {
Ref<AudioEffect> effect;
Ref<AudioEffectInstance> instance;
bool enabled;
};
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
Vector<Effect> effects;
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
float volume_db;
2014-02-10 02:10:30 +01:00
};
2017-01-15 20:06:14 +01:00
Vector<Bus> buses;
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
static void _bind_methods();
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
static AudioServer* singleton;
public:
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-15 20:06:14 +01:00
void set_bus_mode(int p_bus,BusMode p_mode);
BusMode get_bus_mode(int p_bus) const;
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
void set_bus_name(int p_bus,const String& p_name);
String get_bus_name(int p_bus) const;
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +01:00
void set_bus_volume_db(int p_bus,float p_volume_db);
float get_bus_volume_db(int p_bus) const;
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +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);
Ref<AudioEffect> get_bus_effect(int p_bus,int p_effect);
2014-02-10 02:10:30 +01:00
2017-01-15 20:06:14 +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-01-15 20:06:14 +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-01-15 20:06:14 +01:00
virtual void init();
virtual void finish();
virtual void update();
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();
2017-01-15 20:06:14 +01:00
virtual double get_mix_time() const; //useful for video -> audio sync
virtual double get_output_delay() const;
2014-02-10 02:10:30 +01:00
AudioServer();
virtual ~AudioServer();
};
2017-01-15 20:06:14 +01:00
VARIANT_ENUM_CAST( AudioServer::BusMode )
VARIANT_ENUM_CAST( AudioServer::SpeakerMode )
2014-02-10 02:10:30 +01:00
typedef AudioServer AS;
2017-01-15 20:06:14 +01:00
2014-02-10 02:10:30 +01:00
#endif // AUDIO_SERVER_H