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