godot4-opus/src/GodotOpus.h

41 lines
809 B
C
Raw Normal View History

2024-01-16 15:58:59 +00:00
#pragma once
#include <godot_cpp/classes/node.hpp>
2024-01-16 15:58:59 +00:00
#include <godot_cpp/core/class_db.hpp>
#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 {
constexpr size_t SampleFrames{480};
class Opus : public Node
2024-01-16 15:58:59 +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);
void decode_and_play(Ref<AudioStreamGeneratorPlayback> buffer, PackedFloat32Array input);
2024-01-16 15:58:59 +00:00
private:
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;
};
}