2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* audio_stream_ogg_vorbis.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "audio_stream_ogg_vorbis.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
size_t AudioStreamPlaybackOGGVorbis::_ov_read_func(void *p_dst, size_t p_data, size_t p_count, void *_f) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//printf("read to %p, %i bytes, %i nmemb, %p\n",p_dst,p_data,p_count,_f);
|
2017-03-05 15:44:50 +00:00
|
|
|
FileAccess *fa = (FileAccess *)_f;
|
|
|
|
size_t read_total = p_data * p_count;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (fa->eof_reached())
|
|
|
|
return 0;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint8_t *dst = (uint8_t *)p_dst;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int read = fa->get_buffer(dst, read_total);
|
|
|
|
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int AudioStreamPlaybackOGGVorbis::_ov_seek_func(void *_f, ogg_int64_t offs, int whence) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
//printf("seek to %p, offs %i, whence %i\n",_f,(int)offs,whence);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
#ifdef SEEK_SET
|
|
|
|
//printf("seek set defined\n");
|
2017-03-05 15:44:50 +00:00
|
|
|
FileAccess *fa = (FileAccess *)_f;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (whence == SEEK_SET) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
fa->seek(offs);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (whence == SEEK_CUR) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
fa->seek(fa->get_position() + offs);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (whence == SEEK_END) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
fa->seek_end(offs);
|
|
|
|
} else {
|
|
|
|
|
2017-12-05 14:41:38 +00:00
|
|
|
ERR_PRINT("Vorbis seek function failure: Unexpected value in _whence\n");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
int ret = fa->eof_reached() ? -1 : 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
//printf("returning %i\n",ret);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
#else
|
|
|
|
return -1; // no seeking
|
|
|
|
#endif
|
|
|
|
}
|
2015-09-09 21:50:52 +00:00
|
|
|
int AudioStreamPlaybackOGGVorbis::_ov_close_func(void *_f) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//printf("close %p\n",_f);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!_f)
|
|
|
|
return 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
FileAccess *fa = (FileAccess *)_f;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (fa->is_open())
|
|
|
|
fa->close();
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-09 21:50:52 +00:00
|
|
|
long AudioStreamPlaybackOGGVorbis::_ov_tell_func(void *_f) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//printf("close %p\n",_f);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
FileAccess *fa = (FileAccess *)_f;
|
2017-09-10 13:37:49 +00:00
|
|
|
return fa->get_position();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 12:04:25 +00:00
|
|
|
int AudioStreamPlaybackOGGVorbis::mix(int16_t *p_buffer, int p_frames) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
if (!playing)
|
|
|
|
return 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int total = p_frames;
|
2014-02-10 01:10:30 +00:00
|
|
|
while (true) {
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
int todo = p_frames;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (todo == 0 || todo < MIN_MIX) {
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2015-09-09 21:50:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#ifdef BIG_ENDIAN_ENABLED
|
2017-10-28 12:04:25 +00:00
|
|
|
long ret = ov_read(&vf, (char *)p_buffer, todo * stream_channels * sizeof(int16_t), 1, 2, 1, ¤t_section);
|
2017-03-05 15:44:50 +00:00
|
|
|
#else
|
2017-10-28 12:04:25 +00:00
|
|
|
long ret = ov_read(&vf, (char *)p_buffer, todo * stream_channels * sizeof(int16_t), 0, 2, 1, ¤t_section);
|
2017-03-05 15:44:50 +00:00
|
|
|
#endif
|
2015-09-09 21:50:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ret < 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
playing = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_EXPLAIN("Error reading OGG Vorbis File: " + file);
|
|
|
|
ERR_BREAK(ret < 0);
|
|
|
|
} else if (ret == 0) { // end of song, reload?
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ov_clear(&vf);
|
|
|
|
|
|
|
|
_close_file();
|
|
|
|
|
|
|
|
if (!has_loop()) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
playing = false;
|
|
|
|
repeats = 1;
|
2015-09-09 21:50:52 +00:00
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
f = FileAccess::open(file, FileAccess::READ);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks);
|
|
|
|
if (errv != 0) {
|
|
|
|
playing = false;
|
2017-01-15 21:15:47 +00:00
|
|
|
break; // :(
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
if (loop_restart_time) {
|
2017-03-05 15:44:50 +00:00
|
|
|
bool ok = ov_time_seek(&vf, loop_restart_time) == 0;
|
2015-09-09 21:50:52 +00:00
|
|
|
if (!ok) {
|
2017-03-05 15:44:50 +00:00
|
|
|
playing = false;
|
2015-09-09 21:50:52 +00:00
|
|
|
//ERR_EXPLAIN("loop restart time rejected");
|
|
|
|
ERR_PRINT("loop restart time rejected")
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
frames_mixed = stream_srate * loop_restart_time;
|
2015-09-09 21:50:52 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
frames_mixed = 0;
|
2015-09-09 21:50:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
repeats++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ret /= stream_channels;
|
|
|
|
ret /= sizeof(int16_t);
|
2015-09-09 21:50:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
frames_mixed += ret;
|
2015-09-09 21:50:52 +00:00
|
|
|
|
2017-10-28 12:04:25 +00:00
|
|
|
p_buffer += ret * stream_channels;
|
2017-03-05 15:44:50 +00:00
|
|
|
p_frames -= ret;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return total - p_frames;
|
2015-09-09 21:50:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
void AudioStreamPlaybackOGGVorbis::play(float p_from) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (playing)
|
|
|
|
stop();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (_load_stream() != OK)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
frames_mixed = 0;
|
|
|
|
playing = true;
|
|
|
|
if (p_from > 0) {
|
2017-09-21 03:31:36 +00:00
|
|
|
seek(p_from);
|
2015-09-09 21:50:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
void AudioStreamPlaybackOGGVorbis::_close_file() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (f) {
|
2015-09-09 21:50:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(f);
|
2017-03-05 15:44:50 +00:00
|
|
|
f = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
bool AudioStreamPlaybackOGGVorbis::is_playing() const {
|
|
|
|
return playing;
|
|
|
|
}
|
|
|
|
void AudioStreamPlaybackOGGVorbis::stop() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_clear_stream();
|
2017-03-05 15:44:50 +00:00
|
|
|
playing = false;
|
2015-09-09 21:50:52 +00:00
|
|
|
//_clear();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 03:31:36 +00:00
|
|
|
float AudioStreamPlaybackOGGVorbis::get_playback_position() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
int32_t frames = int32_t(frames_mixed);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (frames < 0)
|
2017-03-05 15:44:50 +00:00
|
|
|
frames = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return double(frames) / stream_srate;
|
|
|
|
}
|
|
|
|
|
2017-09-21 03:31:36 +00:00
|
|
|
void AudioStreamPlaybackOGGVorbis::seek(float p_time) {
|
2015-09-09 21:50:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!playing)
|
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
bool ok = ov_time_seek(&vf, p_time) == 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!ok);
|
2017-03-05 15:44:50 +00:00
|
|
|
frames_mixed = stream_srate * p_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String AudioStreamPlaybackOGGVorbis::get_stream_name() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
void AudioStreamPlaybackOGGVorbis::set_loop(bool p_enable) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
loops = p_enable;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
bool AudioStreamPlaybackOGGVorbis::has_loop() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return loops;
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
int AudioStreamPlaybackOGGVorbis::get_loop_count() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return repeats;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error AudioStreamPlaybackOGGVorbis::set_file(const String &p_file) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
file = p_file;
|
|
|
|
stream_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
Error err;
|
2017-03-05 15:44:50 +00:00
|
|
|
f = FileAccess::open(file, FileAccess::READ, &err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (err) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks);
|
|
|
|
switch (errv) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
case OV_EREAD: { // - A read from media returned an error.
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(f);
|
|
|
|
f = NULL;
|
|
|
|
ERR_FAIL_V(ERR_FILE_CANT_READ);
|
2015-09-09 21:50:52 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case OV_EVERSION: // - Vorbis version mismatch.
|
2015-09-09 21:50:52 +00:00
|
|
|
case OV_ENOTVORBIS: { // - Bitstream is not Vorbis data.
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(f);
|
|
|
|
f = NULL;
|
|
|
|
ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
|
2015-09-09 21:50:52 +00:00
|
|
|
} break;
|
|
|
|
case OV_EBADHEADER: { // - Invalid Vorbis bitstream header.
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(f);
|
|
|
|
f = NULL;
|
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT);
|
2015-09-09 21:50:52 +00:00
|
|
|
} break;
|
|
|
|
case OV_EFAULT: { // - Internal logic fault; indicates a bug or heap/stack corruption.
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(f);
|
|
|
|
f = NULL;
|
|
|
|
ERR_FAIL_V(ERR_BUG);
|
2015-09-09 21:50:52 +00:00
|
|
|
} break;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
const vorbis_info *vinfo = ov_info(&vf, -1);
|
|
|
|
stream_channels = vinfo->channels;
|
|
|
|
stream_srate = vinfo->rate;
|
|
|
|
length = ov_time_total(&vf, -1);
|
2015-09-09 21:50:52 +00:00
|
|
|
ov_clear(&vf);
|
|
|
|
memdelete(f);
|
2017-03-05 15:44:50 +00:00
|
|
|
f = NULL;
|
|
|
|
stream_valid = true;
|
2015-09-09 21:50:52 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error AudioStreamPlaybackOGGVorbis::_load_stream() {
|
2015-09-09 21:50:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!stream_valid, ERR_UNCONFIGURED);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
_clear_stream();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (file == "")
|
2015-09-09 21:50:52 +00:00
|
|
|
return ERR_INVALID_DATA;
|
|
|
|
|
|
|
|
Error err;
|
2017-03-05 15:44:50 +00:00
|
|
|
f = FileAccess::open(file, FileAccess::READ, &err);
|
2015-09-09 21:50:52 +00:00
|
|
|
if (err) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int errv = ov_open_callbacks(f, &vf, NULL, 0, _ov_callbacks);
|
|
|
|
switch (errv) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case OV_EREAD: { // - A read from media returned an error.
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(f);
|
|
|
|
f = NULL;
|
|
|
|
ERR_FAIL_V(ERR_FILE_CANT_READ);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case OV_EVERSION: // - Vorbis version mismatch.
|
2014-02-10 01:10:30 +00:00
|
|
|
case OV_ENOTVORBIS: { // - Bitstream is not Vorbis data.
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(f);
|
|
|
|
f = NULL;
|
|
|
|
ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case OV_EBADHEADER: { // - Invalid Vorbis bitstream header.
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(f);
|
|
|
|
f = NULL;
|
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case OV_EFAULT: { // - Internal logic fault; indicates a bug or heap/stack corruption.
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(f);
|
|
|
|
f = NULL;
|
|
|
|
ERR_FAIL_V(ERR_BUG);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
repeats = 0;
|
|
|
|
stream_loaded = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
float AudioStreamPlaybackOGGVorbis::get_length() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!stream_loaded) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (const_cast<AudioStreamPlaybackOGGVorbis *>(this)->_load_stream() != OK)
|
2014-02-10 01:10:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
void AudioStreamPlaybackOGGVorbis::_clear_stream() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!stream_loaded)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ov_clear(&vf);
|
|
|
|
_close_file();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
stream_loaded = false;
|
2015-10-19 21:47:49 +00:00
|
|
|
//stream_channels=1;
|
2017-03-05 15:44:50 +00:00
|
|
|
playing = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
void AudioStreamPlaybackOGGVorbis::set_paused(bool p_paused) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
paused = p_paused;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:45:02 +00:00
|
|
|
bool AudioStreamPlaybackOGGVorbis::is_paused() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return paused;
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
AudioStreamPlaybackOGGVorbis::AudioStreamPlaybackOGGVorbis() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
loops = false;
|
|
|
|
playing = false;
|
|
|
|
_ov_callbacks.read_func = _ov_read_func;
|
|
|
|
_ov_callbacks.seek_func = _ov_seek_func;
|
|
|
|
_ov_callbacks.close_func = _ov_close_func;
|
|
|
|
_ov_callbacks.tell_func = _ov_tell_func;
|
2014-02-10 01:10:30 +00:00
|
|
|
f = NULL;
|
2017-03-05 15:44:50 +00:00
|
|
|
stream_loaded = false;
|
|
|
|
stream_valid = false;
|
|
|
|
repeats = 0;
|
|
|
|
paused = true;
|
|
|
|
stream_channels = 0;
|
|
|
|
stream_srate = 0;
|
|
|
|
current_section = 0;
|
|
|
|
length = 0;
|
|
|
|
loop_restart_time = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 21:50:52 +00:00
|
|
|
AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_clear_stream();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
RES ResourceFormatLoaderAudioStreamOGGVorbis::load(const String &p_path, const String &p_original_path, Error *r_error) {
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_error)
|
2017-03-05 15:44:50 +00:00
|
|
|
*r_error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
AudioStreamOGGVorbis *ogg_stream = memnew(AudioStreamOGGVorbis);
|
|
|
|
ogg_stream->set_file(p_path);
|
|
|
|
return Ref<AudioStreamOGGVorbis>(ogg_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceFormatLoaderAudioStreamOGGVorbis::get_recognized_extensions(List<String> *p_extensions) const {
|
|
|
|
|
|
|
|
p_extensions->push_back("ogg");
|
|
|
|
}
|
|
|
|
String ResourceFormatLoaderAudioStreamOGGVorbis::get_resource_type(const String &p_path) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_path.get_extension().to_lower() == "ogg")
|
2014-02-10 01:10:30 +00:00
|
|
|
return "AudioStreamOGGVorbis";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool ResourceFormatLoaderAudioStreamOGGVorbis::handles_type(const String &p_type) const {
|
|
|
|
return (p_type == "AudioStream" || p_type == "AudioStreamOGG" || p_type == "AudioStreamOGGVorbis");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|