2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* audio_driver_javascript.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef AUDIO_DRIVER_JAVASCRIPT_H
|
|
|
|
#define AUDIO_DRIVER_JAVASCRIPT_H
|
|
|
|
|
2017-01-16 18:19:45 +00:00
|
|
|
#include "servers/audio_server.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-02 11:49:00 +00:00
|
|
|
#include "core/os/mutex.h"
|
|
|
|
#include "core/os/thread.h"
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
class AudioDriverJavaScript : public AudioDriver {
|
2020-10-02 11:49:00 +00:00
|
|
|
private:
|
2020-06-29 16:51:53 +00:00
|
|
|
float *internal_buffer = nullptr;
|
2017-10-27 01:34:49 +00:00
|
|
|
|
2020-06-29 16:51:53 +00:00
|
|
|
int buffer_length = 0;
|
2020-10-02 11:49:00 +00:00
|
|
|
int mix_rate = 0;
|
|
|
|
int channel_count = 0;
|
2018-10-08 18:46:21 +00:00
|
|
|
|
2020-10-02 11:49:00 +00:00
|
|
|
#ifndef NO_THREADS
|
|
|
|
Mutex mutex;
|
|
|
|
Thread *thread = nullptr;
|
|
|
|
bool quit = false;
|
|
|
|
bool needs_process = true;
|
|
|
|
|
|
|
|
static void _audio_thread_func(void *p_data);
|
|
|
|
#endif
|
2020-10-23 16:33:20 +00:00
|
|
|
static void _audio_driver_process_start();
|
|
|
|
static void _audio_driver_process_end();
|
|
|
|
static void _audio_driver_process_capture(float p_sample);
|
|
|
|
void _audio_driver_process();
|
2020-10-02 11:49:00 +00:00
|
|
|
|
2020-10-23 16:33:20 +00:00
|
|
|
public:
|
2020-06-29 16:51:53 +00:00
|
|
|
static bool is_available();
|
2018-10-08 18:46:21 +00:00
|
|
|
void process_capture(float sample);
|
|
|
|
|
2017-11-05 22:48:13 +00:00
|
|
|
static AudioDriverJavaScript *singleton;
|
2017-10-27 01:34:49 +00:00
|
|
|
|
2020-08-06 14:20:05 +00:00
|
|
|
const char *get_name() const override;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-08-06 14:20:05 +00:00
|
|
|
Error init() override;
|
|
|
|
void start() override;
|
2019-01-20 13:25:15 +00:00
|
|
|
void resume();
|
2020-08-06 14:20:05 +00:00
|
|
|
float get_latency() override;
|
|
|
|
int get_mix_rate() const override;
|
|
|
|
SpeakerMode get_speaker_mode() const override;
|
|
|
|
void lock() override;
|
|
|
|
void unlock() override;
|
|
|
|
void finish() override;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-08-06 14:20:05 +00:00
|
|
|
Error capture_start() override;
|
|
|
|
Error capture_stop() override;
|
2018-10-08 18:46:21 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
AudioDriverJavaScript();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|