2024-01-16 15:58:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
2024-01-17 07:29:33 +00:00
|
|
|
#include <godot_cpp/classes/node.hpp>
|
2024-01-16 15:58:59 +00:00
|
|
|
#include <godot_cpp/core/class_db.hpp>
|
2024-01-17 07:29:33 +00:00
|
|
|
#include <godot_cpp/classes/audio_stream_generator.hpp>
|
|
|
|
#include <godot_cpp/classes/audio_stream_generator_playback.hpp>
|
2024-01-16 15:58:59 +00:00
|
|
|
|
|
|
|
#include "opus.h"
|
|
|
|
|
|
|
|
namespace godot {
|
|
|
|
|
2024-01-17 07:29:33 +00:00
|
|
|
constexpr size_t SampleFrames{480};
|
|
|
|
|
|
|
|
class Opus : public Node
|
2024-01-16 15:58:59 +00:00
|
|
|
{
|
2024-01-17 07:29:33 +00:00
|
|
|
GDCLASS(Opus, Node);
|
2024-01-16 15:58:59 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
Opus();
|
|
|
|
~Opus();
|
|
|
|
|
|
|
|
PackedFloat32Array encode(PackedVector2Array input);
|
|
|
|
PackedVector2Array decode(PackedFloat32Array input);
|
2024-01-17 07:29:33 +00:00
|
|
|
|
|
|
|
void decode_and_play(Ref<AudioStreamGeneratorPlayback> buffer, PackedFloat32Array input);
|
|
|
|
|
2024-01-16 15:58:59 +00:00
|
|
|
private:
|
2024-01-17 07:29:33 +00:00
|
|
|
std::vector<float> m_encodeInputBuffer;
|
|
|
|
std::vector<float> m_decodeOutputBuffer;
|
|
|
|
std::vector<unsigned char> m_encodeOutputBuffer;
|
|
|
|
|
2024-01-16 15:58:59 +00:00
|
|
|
OpusEncoder* m_encoder;
|
|
|
|
OpusDecoder* m_decoder;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|