Path: blob/master/servers/audio/effects/audio_effect_record.h
10278 views
/**************************************************************************/1/* audio_effect_record.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/os/thread.h"33#include "scene/resources/audio_stream_wav.h"34#include "servers/audio/audio_effect.h"35#include "servers/audio_server.h"3637class AudioEffectRecord;3839class AudioEffectRecordInstance : public AudioEffectInstance {40GDCLASS(AudioEffectRecordInstance, AudioEffectInstance);41friend class AudioEffectRecord;4243bool is_recording;44Thread io_thread;4546Vector<AudioFrame> ring_buffer;47Vector<float> recording_data;4849unsigned int ring_buffer_pos;50unsigned int ring_buffer_mask;51unsigned int ring_buffer_read_pos;5253void _io_thread_process();54void _io_store_buffer();55static void _thread_callback(void *_instance);56void _init_recording();57void _update_buffer();58static void _update(void *userdata);5960public:61void init();62void finish();63virtual void process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) override;64virtual bool process_silence() const override;65};6667class AudioEffectRecord : public AudioEffect {68GDCLASS(AudioEffectRecord, AudioEffect);6970friend class AudioEffectRecordInstance;7172enum {73IO_BUFFER_SIZE_MS = 150074};7576Ref<AudioEffectRecordInstance> current_instance;7778AudioStreamWAV::Format format;7980void ensure_thread_stopped();8182protected:83static void _bind_methods();8485public:86Ref<AudioEffectInstance> instantiate() override;87void set_recording_active(bool p_record);88bool is_recording_active() const;89void set_format(AudioStreamWAV::Format p_format);90AudioStreamWAV::Format get_format() const;91Ref<AudioStreamWAV> get_recording() const;92AudioEffectRecord();93~AudioEffectRecord();94};959697