Merge pull request #12691 from eska014/webaudio
Fix WebAudio and HTML5 build
This commit is contained in:
@@ -6,7 +6,6 @@ javascript_files = [
|
||||
"os_javascript.cpp",
|
||||
"audio_driver_javascript.cpp",
|
||||
"javascript_main.cpp",
|
||||
"audio_server_javascript.cpp",
|
||||
"power_javascript.cpp",
|
||||
"javascript_eval.cpp",
|
||||
]
|
||||
@@ -19,7 +18,7 @@ javascript_objects = []
|
||||
for x in javascript_files:
|
||||
javascript_objects.append(env_javascript.Object(x))
|
||||
|
||||
env.Append(LINKFLAGS=["-s", "EXPORTED_FUNCTIONS=\"['_main','_audio_server_mix_function','_main_after_fs_sync','_send_notification']\""])
|
||||
env.Append(LINKFLAGS=["-s", "EXPORTED_FUNCTIONS=\"['_main','_main_after_fs_sync','_send_notification']\""])
|
||||
|
||||
# output file name without file extension
|
||||
basename = "godot" + env["PROGSUFFIX"]
|
||||
|
||||
@@ -30,29 +30,19 @@
|
||||
#include "audio_driver_javascript.h"
|
||||
|
||||
#include <emscripten.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_NUMBER_INTERFACES 3
|
||||
#define MAX_NUMBER_OUTPUT_DEVICES 6
|
||||
|
||||
/* Structure for passing information to callback function */
|
||||
|
||||
//AudioDriverJavaScript* AudioDriverJavaScript::s_ad=NULL;
|
||||
|
||||
AudioDriverJavaScript *AudioDriverJavaScript::singleton_js = NULL;
|
||||
|
||||
const char *AudioDriverJavaScript::get_name() const {
|
||||
|
||||
return "JavaScript";
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
void js_audio_driver_mix_function(int p_frames) {
|
||||
extern "C" EMSCRIPTEN_KEEPALIVE void js_audio_driver_mix_function(int p_frames) {
|
||||
|
||||
//print_line("MIXI! "+itos(p_frames));
|
||||
AudioDriverJavaScript::singleton_js->mix_to_js(p_frames);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::mix_to_js(int p_frames) {
|
||||
|
||||
@@ -65,11 +55,11 @@ void AudioDriverJavaScript::mix_to_js(int p_frames) {
|
||||
|
||||
audio_server_process(p_frames, stream_buffer);
|
||||
for (int i = 0; i < tomix * internal_buffer_channels; i++) {
|
||||
internal_buffer[i] = float(stream_buffer[i] >> 16) * 32768.0;
|
||||
internal_buffer[i] = float(stream_buffer[i] >> 16) / 32768.0;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
EM_ASM_({
|
||||
EM_ASM_ARGS({
|
||||
var data = HEAPF32.subarray($0 / 4, $0 / 4 + $2 * 2);
|
||||
|
||||
for (var channel = 0; channel < _as_output_buffer.numberOfChannels; channel++) {
|
||||
@@ -95,29 +85,24 @@ Error AudioDriverJavaScript::init() {
|
||||
|
||||
void AudioDriverJavaScript::start() {
|
||||
|
||||
internal_buffer_channels = 2;
|
||||
internal_buffer = memnew_arr(float, INTERNAL_BUFFER_SIZE *internal_buffer_channels);
|
||||
stream_buffer = memnew_arr(int32_t, INTERNAL_BUFFER_SIZE * 4); //max 4 channels
|
||||
|
||||
/* clang-format off */
|
||||
EM_ASM(
|
||||
_as_audioctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
|
||||
audio_server_mix_function = Module.cwrap('js_audio_driver_mix_function', 'void', ['number']);
|
||||
);
|
||||
|
||||
int buffer_latency = 16384;
|
||||
EM_ASM_( {
|
||||
_as_script_node = _as_audioctx.createScriptProcessor($0, 0, 2);
|
||||
mix_rate = EM_ASM_INT({
|
||||
_as_audioctx = new (window.AudioContext || window.webkitAudioContext);
|
||||
_as_script_node = _as_audioctx.createScriptProcessor($0, 0, $1);
|
||||
_as_script_node.connect(_as_audioctx.destination);
|
||||
console.log(_as_script_node.bufferSize);
|
||||
var jsAudioDriverMixFunction = cwrap('js_audio_driver_mix_function', null, ['number']);
|
||||
|
||||
_as_script_node.onaudioprocess = function(audioProcessingEvent) {
|
||||
// The output buffer contains the samples that will be modified and played
|
||||
// The output buffer contains the samples that will be modified and played
|
||||
_as_output_buffer = audioProcessingEvent.outputBuffer;
|
||||
audio_server_mix_function(_as_output_buffer.getChannelData(0).length);
|
||||
}
|
||||
}, buffer_latency);
|
||||
jsAudioDriverMixFunction([_as_output_buffer.getChannelData(0).length]);
|
||||
};
|
||||
return _as_audioctx.sampleRate;
|
||||
}, INTERNAL_BUFFER_SIZE, internal_buffer_channels);
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
@@ -152,6 +137,7 @@ void AudioDriverJavaScript::finish() {
|
||||
|
||||
AudioDriverJavaScript::AudioDriverJavaScript() {
|
||||
|
||||
mix_rate = 44100;
|
||||
internal_buffer_channels = 2;
|
||||
mix_rate = DEFAULT_MIX_RATE;
|
||||
singleton_js = this;
|
||||
}
|
||||
|
||||
@@ -32,20 +32,15 @@
|
||||
|
||||
#include "servers/audio_server.h"
|
||||
|
||||
#include "os/mutex.h"
|
||||
|
||||
class AudioDriverJavaScript : public AudioDriver {
|
||||
|
||||
enum {
|
||||
INTERNAL_BUFFER_SIZE = 4096,
|
||||
STREAM_SCALE_BITS = 12
|
||||
|
||||
};
|
||||
|
||||
int mix_rate;
|
||||
float *internal_buffer;
|
||||
int internal_buffer_channels;
|
||||
int internal_buffer_size;
|
||||
int32_t *stream_buffer;
|
||||
|
||||
public:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,229 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* audio_server_javascript.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
#ifndef AUDIO_SERVER_JAVASCRIPT_H
|
||||
#define AUDIO_SERVER_JAVASCRIPT_H
|
||||
|
||||
// FIXME: Needs to be ported to the new AudioServer API in 3.0
|
||||
#if 0
|
||||
#include "servers/audio_server.h"
|
||||
|
||||
class AudioServerJavascript : public AudioServer {
|
||||
|
||||
GDCLASS(AudioServerJavascript,AudioServer);
|
||||
|
||||
enum {
|
||||
INTERNAL_BUFFER_SIZE=4096,
|
||||
STREAM_SCALE_BITS=12
|
||||
|
||||
};
|
||||
|
||||
AudioMixer *get_mixer();
|
||||
void audio_mixer_chunk_callback(int p_frames);
|
||||
|
||||
struct Sample {
|
||||
SampleFormat format;
|
||||
SampleLoopFormat loop_format;
|
||||
int loop_begin;
|
||||
int loop_end;
|
||||
int length;
|
||||
int index;
|
||||
int mix_rate;
|
||||
bool stereo;
|
||||
|
||||
Vector<float> tmp_data;
|
||||
};
|
||||
|
||||
mutable RID_Owner<Sample> sample_owner;
|
||||
int sample_base;
|
||||
|
||||
struct Voice {
|
||||
int index;
|
||||
float volume;
|
||||
float pan;
|
||||
float pan_depth;
|
||||
float pan_height;
|
||||
|
||||
float chorus;
|
||||
ReverbRoomType reverb_type;
|
||||
float reverb;
|
||||
|
||||
int mix_rate;
|
||||
int sample_mix_rate;
|
||||
bool positional;
|
||||
|
||||
bool active;
|
||||
|
||||
};
|
||||
|
||||
mutable RID_Owner<Voice> voice_owner;
|
||||
|
||||
int voice_base;
|
||||
|
||||
struct Stream {
|
||||
bool active;
|
||||
List<Stream*>::Element *E;
|
||||
AudioStream *audio_stream;
|
||||
EventStream *event_stream;
|
||||
float volume_scale;
|
||||
};
|
||||
|
||||
List<Stream*> active_audio_streams;
|
||||
|
||||
//List<Stream*> event_streams;
|
||||
|
||||
float * internal_buffer;
|
||||
int internal_buffer_channels;
|
||||
int32_t * stream_buffer;
|
||||
|
||||
mutable RID_Owner<Stream> stream_owner;
|
||||
|
||||
float stream_volume;
|
||||
float stream_volume_scale;
|
||||
|
||||
float event_voice_scale;
|
||||
float fx_volume_scale;
|
||||
|
||||
|
||||
void driver_process_chunk(int p_frames);
|
||||
|
||||
int webaudio_mix_rate;
|
||||
|
||||
|
||||
static AudioServerJavascript *singleton;
|
||||
public:
|
||||
|
||||
void mix_to_js(int p_frames);
|
||||
/* SAMPLE API */
|
||||
|
||||
virtual RID sample_create(SampleFormat p_format, bool p_stereo, int p_length);
|
||||
|
||||
virtual void sample_set_description(RID p_sample, const String& p_description);
|
||||
virtual String sample_get_description(RID p_sample) const;
|
||||
|
||||
virtual SampleFormat sample_get_format(RID p_sample) const;
|
||||
virtual bool sample_is_stereo(RID p_sample) const;
|
||||
virtual int sample_get_length(RID p_sample) const;
|
||||
virtual const void* sample_get_data_ptr(RID p_sample) const;
|
||||
|
||||
|
||||
virtual void sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer);
|
||||
virtual PoolVector<uint8_t> sample_get_data(RID p_sample) const;
|
||||
|
||||
virtual void sample_set_mix_rate(RID p_sample,int p_rate);
|
||||
virtual int sample_get_mix_rate(RID p_sample) const;
|
||||
|
||||
virtual void sample_set_loop_format(RID p_sample,SampleLoopFormat p_format);
|
||||
virtual SampleLoopFormat sample_get_loop_format(RID p_sample) const;
|
||||
|
||||
virtual void sample_set_loop_begin(RID p_sample,int p_pos);
|
||||
virtual int sample_get_loop_begin(RID p_sample) const;
|
||||
|
||||
virtual void sample_set_loop_end(RID p_sample,int p_pos);
|
||||
virtual int sample_get_loop_end(RID p_sample) const;
|
||||
|
||||
|
||||
/* VOICE API */
|
||||
|
||||
virtual RID voice_create();
|
||||
|
||||
virtual void voice_play(RID p_voice, RID p_sample);
|
||||
|
||||
virtual void voice_set_volume(RID p_voice, float p_volume);
|
||||
virtual void voice_set_pan(RID p_voice, float p_pan, float p_depth=0,float height=0); //pan and depth go from -1 to 1
|
||||
virtual void voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance, float p_gain=0);
|
||||
virtual void voice_set_chorus(RID p_voice, float p_chorus );
|
||||
virtual void voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb);
|
||||
virtual void voice_set_mix_rate(RID p_voice, int p_mix_rate);
|
||||
virtual void voice_set_positional(RID p_voice, bool p_positional);
|
||||
|
||||
virtual float voice_get_volume(RID p_voice) const;
|
||||
virtual float voice_get_pan(RID p_voice) const; //pan and depth go from -1 to 1
|
||||
virtual float voice_get_pan_depth(RID p_voice) const; //pan and depth go from -1 to 1
|
||||
virtual float voice_get_pan_height(RID p_voice) const; //pan and depth go from -1 to 1
|
||||
virtual FilterType voice_get_filter_type(RID p_voice) const;
|
||||
virtual float voice_get_filter_cutoff(RID p_voice) const;
|
||||
virtual float voice_get_filter_resonance(RID p_voice) const;
|
||||
virtual float voice_get_chorus(RID p_voice) const;
|
||||
virtual ReverbRoomType voice_get_reverb_type(RID p_voice) const;
|
||||
virtual float voice_get_reverb(RID p_voice) const;
|
||||
|
||||
virtual int voice_get_mix_rate(RID p_voice) const;
|
||||
virtual bool voice_is_positional(RID p_voice) const;
|
||||
|
||||
virtual void voice_stop(RID p_voice);
|
||||
virtual bool voice_is_active(RID p_voice) const;
|
||||
|
||||
/* STREAM API */
|
||||
|
||||
virtual RID audio_stream_create(AudioStream *p_stream);
|
||||
virtual RID event_stream_create(EventStream *p_stream);
|
||||
|
||||
virtual void stream_set_active(RID p_stream, bool p_active);
|
||||
virtual bool stream_is_active(RID p_stream) const;
|
||||
|
||||
virtual void stream_set_volume_scale(RID p_stream, float p_scale);
|
||||
virtual float stream_set_volume_scale(RID p_stream) const;
|
||||
|
||||
/* Audio Physics API */
|
||||
|
||||
virtual void free(RID p_id);
|
||||
|
||||
virtual void init();
|
||||
virtual void finish();
|
||||
virtual void update();
|
||||
|
||||
/* MISC config */
|
||||
|
||||
virtual void lock();
|
||||
virtual void unlock();
|
||||
virtual int get_default_channel_count() const;
|
||||
virtual int get_default_mix_rate() const;
|
||||
|
||||
virtual void set_stream_global_volume_scale(float p_volume);
|
||||
virtual void set_fx_global_volume_scale(float p_volume);
|
||||
virtual void set_event_voice_global_volume_scale(float p_volume);
|
||||
|
||||
virtual float get_stream_global_volume_scale() const;
|
||||
virtual float get_fx_global_volume_scale() const;
|
||||
virtual float get_event_voice_global_volume_scale() const;
|
||||
|
||||
virtual uint32_t read_output_peak() const;
|
||||
|
||||
static AudioServer *get_singleton();
|
||||
|
||||
virtual double get_mix_time() const; //useful for video -> audio sync
|
||||
virtual double get_output_delay() const;
|
||||
|
||||
|
||||
AudioServerJavascript();
|
||||
};
|
||||
|
||||
#endif // AUDIO_SERVER_JAVASCRIPT_H
|
||||
#endif
|
||||
@@ -31,7 +31,6 @@
|
||||
#define OS_JAVASCRIPT_H
|
||||
|
||||
#include "audio_driver_javascript.h"
|
||||
#include "audio_server_javascript.h"
|
||||
#include "drivers/unix/os_unix.h"
|
||||
#include "javascript_eval.h"
|
||||
#include "main/input_default.h"
|
||||
|
||||
Reference in New Issue
Block a user