diff options
author | reduz <reduzio@gmail.com> | 2022-07-21 01:00:58 +0200 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2022-07-23 07:31:17 +0200 |
commit | d1ddee225830b28171de031bd1f1918ced21b38f (patch) | |
tree | 59fbad7454e47cfc0f746842108d3d6e10b83a40 /modules/vorbis/audio_stream_ogg_vorbis.h | |
parent | 976cb7ea9f59813f99e06c4c345c19ff68c2c591 (diff) |
Implement BPM support
Based on #62896, only implements the BPM support part.
* Implements BPM support in the AudioStreamOGG/MP3 importers.
* Can select BPM/Bar Size and total beats in a song file, as well as edit looping points.
* Looping is now BPM aware
* Added a special importer UI for configuring this.
* Added a special preview showing the audio waveform as well as the playback position in the resource picker.
* Renamed `AudioStream::instance` to `instantiate` for correctness.
Diffstat (limited to 'modules/vorbis/audio_stream_ogg_vorbis.h')
-rw-r--r-- | modules/vorbis/audio_stream_ogg_vorbis.h | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.h index b09ef9ff5d..22c2eb4d73 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.h +++ b/modules/vorbis/audio_stream_ogg_vorbis.h @@ -45,6 +45,12 @@ class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { bool active = false; int loops = 0; + enum { + FADE_SIZE = 256 + }; + AudioFrame loop_fade[FADE_SIZE]; + int loop_fade_remaining = FADE_SIZE; + vorbis_info info; vorbis_comment comment; vorbis_dsp_state dsp_state; @@ -66,6 +72,7 @@ class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { Ref<OGGPacketSequencePlayback> vorbis_data_playback; Ref<AudioStreamOGGVorbis> vorbis_stream; + int _mix_frames(AudioFrame *p_buffer, int p_frames); int _mix_frames_vorbis(AudioFrame *p_buffer, int p_frames); // Allocates vorbis data structures. Returns true upon success, false on failure. @@ -85,6 +92,8 @@ public: virtual float get_playback_position() const override; virtual void seek(float p_time) override; + virtual void tag_used_streams() override; + AudioStreamPlaybackOGGVorbis() {} ~AudioStreamPlaybackOGGVorbis(); }; @@ -107,17 +116,30 @@ class AudioStreamOGGVorbis : public AudioStream { Ref<OGGPacketSequence> packet_sequence; + double bpm = 0; + int beat_count = 0; + int bar_beats = 4; + protected: static void _bind_methods(); public: void set_loop(bool p_enable); - bool has_loop() const; + virtual bool has_loop() const override; void set_loop_offset(float p_seconds); float get_loop_offset() const; - virtual Ref<AudioStreamPlayback> instance_playback() override; + void set_bpm(double p_bpm); + virtual double get_bpm() const override; + + void set_beat_count(int p_beat_count); + virtual int get_beat_count() const override; + + void set_bar_beats(int p_bar_beats); + virtual int get_bar_beats() const override; + + virtual Ref<AudioStreamPlayback> instantiate_playback() override; virtual String get_stream_name() const override; void set_packet_sequence(Ref<OGGPacketSequence> p_packet_sequence); |