godot4-opus/src/GodotOpus.h

48 lines
985 B
C
Raw Permalink 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"
#include "speex/speex_resampler.h"
2024-01-16 15:58:59 +00:00
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();
void update_mix_rate(size_t input, size_t output);
PackedByteArray encode(PackedVector2Array input);
PackedVector2Array decode(PackedByteArray input);
void decode_and_play(Ref<AudioStreamGeneratorPlayback> buffer, PackedByteArray input);
2024-01-16 15:58:59 +00:00
private:
PackedVector2Array m_encodeSampleBuffer;
PackedVector2Array m_decodeSampleBuffer;
size_t m_outputMixRate{44100};
size_t m_inputMixRate{44100};
2024-01-16 15:58:59 +00:00
OpusEncoder* m_encoder;
OpusDecoder* m_decoder;
SpeexResamplerState* m_encodeResampler;
SpeexResamplerState* m_decodeResampler;
2024-01-16 15:58:59 +00:00
};
}