diff options
Diffstat (limited to 'servers/audio_server.h')
-rw-r--r-- | servers/audio_server.h | 280 |
1 files changed, 95 insertions, 185 deletions
diff --git a/servers/audio_server.h b/servers/audio_server.h index 1482b40d4c..77aca39760 100644 --- a/servers/audio_server.h +++ b/servers/audio_server.h @@ -31,261 +31,171 @@ #include "variant.h" #include "object.h" +#include "audio_frame.h" +#include "servers/audio/audio_effect.h" -class AudioMixer { -protected: - void audio_mixer_chunk_call(int p_frames); -public: +class AudioDriver { - enum { - INVALID_CHANNEL=0xFFFFFFFF - }; + static AudioDriver *singleton; + uint64_t _last_mix_time; + uint64_t _mix_amount; + - typedef uint32_t ChannelID; +protected: - /* CHANNEL API */ + void audio_server_process(int p_frames,int32_t *p_buffer,bool p_update_mix_time=true); + void update_mix_time(int p_frames); - enum FilterType { - FILTER_NONE, - FILTER_LOWPASS, - FILTER_BANDPASS, - FILTER_HIPASS, - FILTER_NOTCH, - FILTER_PEAK, - FILTER_BANDLIMIT, ///< cutoff is LP resonace is HP - FILTER_LOW_SHELF, - FILTER_HIGH_SHELF +public: - }; - enum ReverbRoomType { + double get_mix_time() const; //useful for video -> audio sync - REVERB_SMALL, - REVERB_MEDIUM, - REVERB_LARGE, - REVERB_HALL, - MAX_REVERBS + enum SpeakerMode { + SPEAKER_MODE_STEREO, + SPEAKER_SURROUND_51, + SPEAKER_SURROUND_71, }; - virtual ChannelID channel_alloc(RID p_sample)=0; + static AudioDriver *get_singleton(); + void set_singleton(); - virtual void channel_set_volume(ChannelID p_channel, float p_gain)=0; - virtual void channel_set_pan(ChannelID p_channel, float p_pan, float p_depth=0,float height=0)=0; //pan and depth go from -1 to 1 - virtual void channel_set_filter(ChannelID p_channel, FilterType p_type, float p_cutoff, float p_resonance, float p_gain=1.0)=0; - virtual void channel_set_chorus(ChannelID p_channel, float p_chorus )=0; - virtual void channel_set_reverb(ChannelID p_channel, ReverbRoomType p_room_type, float p_reverb)=0; - virtual void channel_set_mix_rate(ChannelID p_channel, int p_mix_rate)=0; - virtual void channel_set_positional(ChannelID p_channel, bool p_positional)=0; + virtual const char* get_name() const=0; - virtual float channel_get_volume(ChannelID p_channel) const=0; - virtual float channel_get_pan(ChannelID p_channel) const=0; //pan and depth go from -1 to 1 - virtual float channel_get_pan_depth(ChannelID p_channel) const=0; //pan and depth go from -1 to 1 - virtual float channel_get_pan_height(ChannelID p_channel) const=0; //pan and depth go from -1 to 1 - virtual FilterType channel_get_filter_type(ChannelID p_channel) const=0; - virtual float channel_get_filter_cutoff(ChannelID p_channel) const=0; - virtual float channel_get_filter_resonance(ChannelID p_channel) const=0; - virtual float channel_get_filter_gain(ChannelID p_channel) const=0; - virtual float channel_get_chorus(ChannelID p_channel) const=0; - virtual ReverbRoomType channel_get_reverb_type(ChannelID p_channel) const=0; - virtual float channel_get_reverb(ChannelID p_channel) const=0; - - virtual int channel_get_mix_rate(ChannelID p_channel) const=0; - virtual bool channel_is_positional(ChannelID p_channel) const=0; - virtual bool channel_is_valid(ChannelID p_channel) const=0; + 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; + virtual float get_latency() { return 0; } - virtual void channel_free(ChannelID p_channel)=0; - virtual void set_mixer_volume(float p_volume)=0; - virtual ~AudioMixer() {} + AudioDriver(); + virtual ~AudioDriver() {} }; -class AudioServer : public Object { - GDCLASS( AudioServer, Object ); +class AudioDriverManager { - static AudioServer *singleton; -protected: -friend class AudioStream; -friend class EventStream; -friend class AudioMixer; + enum { - virtual AudioMixer *get_mixer()=0; - virtual void audio_mixer_chunk_callback(int p_frames)=0; + MAX_DRIVERS=10 + }; - static void _bind_methods(); + static AudioDriver *drivers[MAX_DRIVERS]; + static int driver_count; public: - - class EventStream { - protected: - AudioMixer *get_mixer() const; - public: - virtual void update(uint64_t p_usec)=0; - - virtual ~EventStream() {} - }; - - class AudioStream { - public: - virtual int get_channel_count() const=0; - virtual void set_mix_rate(int p_rate)=0; //notify the stream of the mix rate - virtual bool mix(int32_t *p_buffer,int p_frames)=0; - virtual void update()=0; - virtual bool can_update_mt() const { return true; } - virtual ~AudioStream() {} - }; + static void add_driver(AudioDriver *p_driver); + static int get_driver_count(); + static AudioDriver *get_driver(int p_driver); +}; - enum SampleFormat { +class AudioServer : public Object { - SAMPLE_FORMAT_PCM8, - SAMPLE_FORMAT_PCM16, - SAMPLE_FORMAT_IMA_ADPCM + GDCLASS( AudioServer, Object ) +public: + enum BusMode { + BUS_MODE_STEREO, + BUS_MODE_SURROUND }; - enum SampleLoopFormat { - SAMPLE_LOOP_NONE, - SAMPLE_LOOP_FORWARD, - SAMPLE_LOOP_PING_PONG // not supported in every platform - + //re-expose this her, as AudioDriver is not exposed to script + enum SpeakerMode { + SPEAKER_MODE_STEREO, + SPEAKER_SURROUND_51, + SPEAKER_SURROUND_71, }; +private: + uint32_t buffer_size; - /* SAMPLE API */ - - virtual RID sample_create(SampleFormat p_format, bool p_stereo, int p_length)=0; - - virtual void sample_set_description(RID p_sample, const String& p_description)=0; - virtual String sample_get_description(RID p_sample) const=0; - - virtual SampleFormat sample_get_format(RID p_sample) const=0; - virtual bool sample_is_stereo(RID p_sample) const=0; - virtual int sample_get_length(RID p_sample) const=0; - virtual const void* sample_get_data_ptr(RID p_sample) const=0; - - virtual void sample_set_signed_data(RID p_sample, const PoolVector<float>& p_buffer); - virtual void sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer)=0; - virtual PoolVector<uint8_t> sample_get_data(RID p_sample) const=0; + struct Bus { - virtual void sample_set_mix_rate(RID p_sample,int p_rate)=0; - virtual int sample_get_mix_rate(RID p_sample) const=0; + String name; + BusMode mode; + Vector<AudioFrame> buffer; - virtual void sample_set_loop_format(RID p_sample,SampleLoopFormat p_format)=0; - virtual SampleLoopFormat sample_get_loop_format(RID p_sample) const=0; + struct Effect { + Ref<AudioEffect> effect; + Ref<AudioEffectInstance> instance; + bool enabled; + }; - virtual void sample_set_loop_begin(RID p_sample,int p_pos)=0; - virtual int sample_get_loop_begin(RID p_sample) const=0; + Vector<Effect> effects; - virtual void sample_set_loop_end(RID p_sample,int p_pos)=0; - virtual int sample_get_loop_end(RID p_sample) const=0; - - - /* VOICE API */ - - enum FilterType { - FILTER_NONE, - FILTER_LOWPASS, - FILTER_BANDPASS, - FILTER_HIPASS, - FILTER_NOTCH, - FILTER_PEAK, - FILTER_BANDLIMIT, ///< cutoff is LP resonace is HP - FILTER_LOW_SHELF, - FILTER_HIGH_SHELF + float volume_db; }; - enum ReverbRoomType { - REVERB_SMALL, - REVERB_MEDIUM, - REVERB_LARGE, - REVERB_HALL - }; + Vector<Bus> buses; - virtual RID voice_create()=0; - virtual void voice_play(RID p_voice, RID p_sample)=0; + static void _bind_methods(); - virtual void voice_set_volume(RID p_voice, float p_volume)=0; - virtual void voice_set_pan(RID p_voice, float p_pan, float p_depth=0,float height=0)=0; //pan and depth go from -1 to 1 - virtual void voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance, float p_gain=0)=0; - virtual void voice_set_chorus(RID p_voice, float p_chorus )=0; - virtual void voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb)=0; - virtual void voice_set_mix_rate(RID p_voice, int p_mix_rate)=0; - virtual void voice_set_positional(RID p_voice, bool p_positional)=0; + static AudioServer* singleton; +public: - virtual float voice_get_volume(RID p_voice) const=0; - virtual float voice_get_pan(RID p_voice) const=0; //pan and depth go from -1 to 1 - virtual float voice_get_pan_depth(RID p_voice) const=0; //pan and depth go from -1 to 1 - virtual float voice_get_pan_height(RID p_voice) const=0; //pan and depth go from -1 to 1 - virtual FilterType voice_get_filter_type(RID p_voice) const=0; - virtual float voice_get_filter_cutoff(RID p_voice) const=0; - virtual float voice_get_filter_resonance(RID p_voice) const=0; - virtual float voice_get_chorus(RID p_voice) const=0; - virtual ReverbRoomType voice_get_reverb_type(RID p_voice) const=0; - virtual float voice_get_reverb(RID p_voice) const=0; - virtual int voice_get_mix_rate(RID p_voice) const=0; - virtual bool voice_is_positional(RID p_voice) const=0; + void set_bus_count(int p_count); + int get_bus_count() const; - virtual void voice_stop(RID p_voice)=0; - virtual bool voice_is_active(RID p_voice) const=0; + void set_bus_mode(int p_bus,BusMode p_mode); + BusMode get_bus_mode(int p_bus) const; - /* STREAM API */ + void set_bus_name(int p_bus,const String& p_name); + String get_bus_name(int p_bus) const; - virtual RID audio_stream_create(AudioStream *p_stream)=0; - virtual RID event_stream_create(EventStream *p_stream)=0; + void set_bus_volume_db(int p_bus,float p_volume_db); + float get_bus_volume_db(int p_bus) const; - virtual void stream_set_active(RID p_stream, bool p_active)=0; - virtual bool stream_is_active(RID p_stream) const=0; + 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); - virtual void stream_set_volume_scale(RID p_stream, float p_scale)=0; - virtual float stream_set_volume_scale(RID p_stream) const=0; + int get_bus_effect_count(int p_bus); + Ref<AudioEffect> get_bus_effect(int p_bus,int p_effect); - /* Audio Physics API */ + void swap_bus_effects(int p_bus,int p_effect,int p_by_effect); - virtual void free(RID p_id)=0; + 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; - virtual void init()=0; - virtual void finish()=0; - virtual void update()=0; + virtual void init(); + virtual void finish(); + virtual void update(); /* MISC config */ - virtual void lock()=0; - virtual void unlock()=0; - virtual int get_default_channel_count() const=0; - virtual int get_default_mix_rate() const=0; + virtual void lock(); + virtual void unlock(); - virtual void set_stream_global_volume_scale(float p_volume)=0; - virtual void set_fx_global_volume_scale(float p_volume)=0; - virtual void set_event_voice_global_volume_scale(float p_volume)=0; - virtual float get_stream_global_volume_scale() const=0; - virtual float get_fx_global_volume_scale() const=0; - virtual float get_event_voice_global_volume_scale() const=0; + virtual SpeakerMode get_speaker_mode() const; + virtual float get_mix_rate() const; - virtual uint32_t read_output_peak() const=0; + virtual float read_output_peak_db() const; static AudioServer *get_singleton(); - virtual double get_mix_time() const=0; //useful for video -> audio sync - virtual double get_output_delay() const=0; + virtual double get_mix_time() const; //useful for video -> audio sync + virtual double get_output_delay() const; AudioServer(); virtual ~AudioServer(); }; -VARIANT_ENUM_CAST( AudioServer::SampleFormat ); -VARIANT_ENUM_CAST( AudioServer::SampleLoopFormat ); -VARIANT_ENUM_CAST( AudioServer::FilterType ); -VARIANT_ENUM_CAST( AudioServer::ReverbRoomType ); +VARIANT_ENUM_CAST( AudioServer::BusMode ) +VARIANT_ENUM_CAST( AudioServer::SpeakerMode ) typedef AudioServer AS; + #endif // AUDIO_SERVER_H |