summaryrefslogtreecommitdiff
path: root/modules/vorbis
diff options
context:
space:
mode:
Diffstat (limited to 'modules/vorbis')
-rw-r--r--modules/vorbis/audio_stream_ogg_vorbis.cpp43
-rw-r--r--modules/vorbis/audio_stream_ogg_vorbis.h12
-rw-r--r--modules/vorbis/resource_importer_ogg_vorbis.cpp18
3 files changed, 45 insertions, 28 deletions
diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp
index 8315eea614..792103cd31 100644
--- a/modules/vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp
@@ -74,7 +74,7 @@ int AudioStreamPlaybackOggVorbis::_mix_internal(AudioFrame *p_buffer, int p_fram
if (beat_length_frames >= 0) {
/**
* Length determined by beat length
- * This code is commented out because, in practice, it is prefered that the fade
+ * This code is commented out because, in practice, it is preferred that the fade
* is done by the transitioner and this stream just goes on until it ends while fading out.
*
* End fade implementation is left here for reference in case at some point this feature
@@ -153,8 +153,11 @@ int AudioStreamPlaybackOggVorbis::_mix_frames_vorbis(AudioFrame *p_buffer, int p
return -1;
}
- ERR_FAIL_COND_V_MSG((err = vorbis_synthesis(&block, packet)), 0, "Error during vorbis synthesis " + itos(err));
- ERR_FAIL_COND_V_MSG((err = vorbis_synthesis_blockin(&dsp_state, &block)), 0, "Error during vorbis block processing " + itos(err));
+ err = vorbis_synthesis(&block, packet);
+ ERR_FAIL_COND_V_MSG(err != 0, 0, "Error during vorbis synthesis " + itos(err));
+
+ err = vorbis_synthesis_blockin(&dsp_state, &block);
+ ERR_FAIL_COND_V_MSG(err != 0, 0, "Error during vorbis block processing " + itos(err));
have_packets_left = !packet->e_o_s;
}
@@ -223,7 +226,7 @@ bool AudioStreamPlaybackOggVorbis::_alloc_vorbis() {
return true;
}
-void AudioStreamPlaybackOggVorbis::start(float p_from_pos) {
+void AudioStreamPlaybackOggVorbis::start(double p_from_pos) {
ERR_FAIL_COND(!ready);
loop_fade_remaining = FADE_SIZE;
active = true;
@@ -244,15 +247,15 @@ int AudioStreamPlaybackOggVorbis::get_loop_count() const {
return loops;
}
-float AudioStreamPlaybackOggVorbis::get_playback_position() const {
- return float(frames_mixed) / vorbis_data->get_sampling_rate();
+double AudioStreamPlaybackOggVorbis::get_playback_position() const {
+ return double(frames_mixed) / (double)vorbis_data->get_sampling_rate();
}
void AudioStreamPlaybackOggVorbis::tag_used_streams() {
vorbis_stream->tag_used(get_playback_position());
}
-void AudioStreamPlaybackOggVorbis::seek(float p_time) {
+void AudioStreamPlaybackOggVorbis::seek(double p_time) {
ERR_FAIL_COND(!ready);
ERR_FAIL_COND(vorbis_stream.is_null());
if (!active) {
@@ -290,11 +293,15 @@ void AudioStreamPlaybackOggVorbis::seek(float p_time) {
headers_remaining = 3;
}
if (!headers_remaining) {
- ERR_FAIL_COND_MSG((err = vorbis_synthesis(&block, packet)), "Error during vorbis synthesis " + itos(err));
- ERR_FAIL_COND_MSG((err = vorbis_synthesis_blockin(&dsp_state, &block)), "Error during vorbis block processing " + itos(err));
+ err = vorbis_synthesis(&block, packet);
+ ERR_FAIL_COND_MSG(err != 0, "Error during vorbis synthesis " + itos(err));
+
+ err = vorbis_synthesis_blockin(&dsp_state, &block);
+ ERR_FAIL_COND_MSG(err != 0, "Error during vorbis block processing " + itos(err));
int samples_out = vorbis_synthesis_pcmout(&dsp_state, nullptr);
- ERR_FAIL_COND_MSG((err = vorbis_synthesis_read(&dsp_state, samples_out)), "Error during vorbis read updating " + itos(err));
+ err = vorbis_synthesis_read(&dsp_state, samples_out);
+ ERR_FAIL_COND_MSG(err != 0, "Error during vorbis read updating " + itos(err));
samples_in_page += samples_out;
@@ -341,12 +348,16 @@ void AudioStreamPlaybackOggVorbis::seek(float p_time) {
headers_remaining = 3;
}
if (!headers_remaining) {
- ERR_FAIL_COND_MSG((err = vorbis_synthesis(&block, packet)), "Error during vorbis synthesis " + itos(err));
- ERR_FAIL_COND_MSG((err = vorbis_synthesis_blockin(&dsp_state, &block)), "Error during vorbis block processing " + itos(err));
+ err = vorbis_synthesis(&block, packet);
+ ERR_FAIL_COND_MSG(err != 0, "Error during vorbis synthesis " + itos(err));
+
+ err = vorbis_synthesis_blockin(&dsp_state, &block);
+ ERR_FAIL_COND_MSG(err != 0, "Error during vorbis block processing " + itos(err));
int samples_out = vorbis_synthesis_pcmout(&dsp_state, nullptr);
int read_samples = samples_to_burn > samples_out ? samples_out : samples_to_burn;
- ERR_FAIL_COND_MSG((err = vorbis_synthesis_read(&dsp_state, samples_out)), "Error during vorbis read updating " + itos(err));
+ err = vorbis_synthesis_read(&dsp_state, samples_out);
+ ERR_FAIL_COND_MSG(err != 0, "Error during vorbis read updating " + itos(err));
samples_to_burn -= read_samples;
if (samples_to_burn <= 0) {
@@ -462,15 +473,15 @@ bool AudioStreamOggVorbis::has_loop() const {
return loop;
}
-void AudioStreamOggVorbis::set_loop_offset(float p_seconds) {
+void AudioStreamOggVorbis::set_loop_offset(double p_seconds) {
loop_offset = p_seconds;
}
-float AudioStreamOggVorbis::get_loop_offset() const {
+double AudioStreamOggVorbis::get_loop_offset() const {
return loop_offset;
}
-float AudioStreamOggVorbis::get_length() const {
+double AudioStreamOggVorbis::get_length() const {
ERR_FAIL_COND_V(packet_sequence.is_null(), 0);
return packet_sequence->get_length();
}
diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.h
index 0350e1f761..3aa99971be 100644
--- a/modules/vorbis/audio_stream_ogg_vorbis.h
+++ b/modules/vorbis/audio_stream_ogg_vorbis.h
@@ -83,14 +83,14 @@ protected:
virtual float get_stream_sampling_rate() override;
public:
- virtual void start(float p_from_pos = 0.0) override;
+ virtual void start(double p_from_pos = 0.0) override;
virtual void stop() override;
virtual bool is_playing() const override;
virtual int get_loop_count() const override; //times it looped
- virtual float get_playback_position() const override;
- virtual void seek(float p_time) override;
+ virtual double get_playback_position() const override;
+ virtual void seek(double p_time) override;
virtual void tag_used_streams() override;
@@ -127,8 +127,8 @@ public:
void set_loop(bool p_enable);
virtual bool has_loop() const override;
- void set_loop_offset(float p_seconds);
- float get_loop_offset() const;
+ void set_loop_offset(double p_seconds);
+ double get_loop_offset() const;
void set_bpm(double p_bpm);
virtual double get_bpm() const override;
@@ -145,7 +145,7 @@ public:
void set_packet_sequence(Ref<OggPacketSequence> p_packet_sequence);
Ref<OggPacketSequence> get_packet_sequence() const;
- virtual float get_length() const override; //if supported, otherwise return 0
+ virtual double get_length() const override; //if supported, otherwise return 0
virtual bool is_monophonic() const override;
diff --git a/modules/vorbis/resource_importer_ogg_vorbis.cpp b/modules/vorbis/resource_importer_ogg_vorbis.cpp
index bf5f7206b8..a491c3d3fb 100644
--- a/modules/vorbis/resource_importer_ogg_vorbis.cpp
+++ b/modules/vorbis/resource_importer_ogg_vorbis.cpp
@@ -110,15 +110,18 @@ Ref<AudioStreamOggVorbis> ResourceImporterOggVorbis::import_ogg_vorbis(const Str
size_t packet_count = 0;
bool done = false;
while (!done) {
- ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
+ err = ogg_sync_check(&sync_state);
+ ERR_FAIL_COND_V_MSG(err != 0, Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
while (ogg_sync_pageout(&sync_state, &page) != 1) {
if (cursor >= len) {
done = true;
break;
}
- ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
+ err = ogg_sync_check(&sync_state);
+ ERR_FAIL_COND_V_MSG(err != 0, Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
char *sync_buf = ogg_sync_buffer(&sync_state, OGG_SYNC_BUFFER_SIZE);
- ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
+ err = ogg_sync_check(&sync_state);
+ ERR_FAIL_COND_V_MSG(err != 0, Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
ERR_FAIL_COND_V(cursor > len, Ref<AudioStreamOggVorbis>());
size_t copy_size = len - cursor;
if (copy_size > OGG_SYNC_BUFFER_SIZE) {
@@ -127,12 +130,14 @@ Ref<AudioStreamOggVorbis> ResourceImporterOggVorbis::import_ogg_vorbis(const Str
memcpy(sync_buf, &file_data[cursor], copy_size);
ogg_sync_wrote(&sync_state, copy_size);
cursor += copy_size;
- ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
+ err = ogg_sync_check(&sync_state);
+ ERR_FAIL_COND_V_MSG(err != 0, Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
}
if (done) {
break;
}
- ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
+ err = ogg_sync_check(&sync_state);
+ ERR_FAIL_COND_V_MSG(err != 0, Ref<AudioStreamOggVorbis>(), "Ogg sync error " + itos(err));
// Have a page now.
if (!initialized_stream) {
@@ -142,7 +147,8 @@ Ref<AudioStreamOggVorbis> ResourceImporterOggVorbis::import_ogg_vorbis(const Str
initialized_stream = true;
}
ogg_stream_pagein(&stream_state, &page);
- ERR_FAIL_COND_V_MSG((err = ogg_stream_check(&stream_state)), Ref<AudioStreamOggVorbis>(), "Ogg stream error " + itos(err));
+ err = ogg_stream_check(&stream_state);
+ ERR_FAIL_COND_V_MSG(err != 0, Ref<AudioStreamOggVorbis>(), "Ogg stream error " + itos(err));
int desync_iters = 0;
Vector<Vector<uint8_t>> packet_data;