Browse Source

More tweaks for wasm and sdl

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.5.0
falkTX 2 years ago
parent
commit
0445589595
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 34 additions and 17 deletions
  1. +5
    -1
      source/Makefile.deps.mk
  2. +14
    -12
      source/backend/engine/CarlaEngineSDL.cpp
  3. +1
    -1
      source/tests/Makefile
  4. +14
    -3
      source/tests/carla-engine-sdl.c

+ 5
- 1
source/Makefile.deps.mk View File

@@ -394,7 +394,11 @@ QT5_FLAGS = $(shell $(PKG_CONFIG) --cflags Qt5Core Qt5Gui Qt5Widgets)
QT5_LIBS = $(shell $(PKG_CONFIG) --libs Qt5Core Qt5Gui Qt5Widgets)
endif

ifeq ($(HAVE_SDL2),true)
ifeq ($(WASM),true)
HAVE_SDL = true
SDL_FLAGS = -sUSE_SDL=2
SDL_LIBS = -sUSE_SDL=2
else ifeq ($(HAVE_SDL2),true)
HAVE_SDL = true
SDL_FLAGS = $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --cflags sdl2)
SDL_LIBS = $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs sdl2)


+ 14
- 12
source/backend/engine/CarlaEngineSDL.cpp View File

@@ -21,16 +21,12 @@
#include "CarlaStringList.hpp"
#include "CarlaBackendUtils.hpp"

#include "SDL.h"
#include <SDL.h>

#ifndef HAVE_SDL2
typedef Uint32 SDL_AudioDeviceID;
#endif

#if defined(HAVE_SDL2) && !defined(CARLA_OS_WASM)
# define HAVE_SDL2_CALLS
#endif

CARLA_BACKEND_START_NAMESPACE

// -------------------------------------------------------------------------------------------------------------------
@@ -52,12 +48,12 @@ static void initAudioDevicesIfNeeded()
#ifdef HAVE_SDL2
SDL_InitSubSystem(SDL_INIT_AUDIO);

# ifdef HAVE_SDL2_CALLS
const int numDevices = SDL_GetNumAudioDevices(0);

for (int i=0; i<numDevices; ++i)
gDeviceNames.append(SDL_GetAudioDeviceName(i, 0));
# endif
#else
SDL_Init(SDL_INIT_AUDIO);
#endif
}

@@ -114,7 +110,11 @@ public:
requested.callback = carla_sdl_process_callback;
requested.userdata = this;

#ifdef HAVE_SDL2_CALLS
#ifdef HAVE_SDL2
SDL_SetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME, clientName);
// SDL_SetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME, );
SDL_SetHint(SDL_HINT_AUDIO_RESAMPLING_MODE, "2");

const char* const deviceName = pData->options.audioDevice != nullptr && pData->options.audioDevice[0] != '\0'
? pData->options.audioDevice
: nullptr;
@@ -136,7 +136,7 @@ public:

if (received.channels == 0)
{
#ifdef HAVE_SDL2_CALLS
#ifdef HAVE_SDL2
SDL_CloseAudioDevice(fDeviceId);
#else
SDL_CloseAudio();
@@ -164,12 +164,14 @@ public:

pData->graph.create(0, fAudioOutCount, 0, 0);

#ifdef HAVE_SDL2_CALLS
#ifdef HAVE_SDL2
SDL_PauseAudioDevice(fDeviceId, 0);
#else
SDL_PauseAudio(0);
#endif
carla_stdout("open fAudioOutCount %d %d %d", fAudioOutCount, received.samples, received.freq);
carla_stdout("open fAudioOutCount %d %d %d | %d vs %d",
fAudioOutCount, received.samples, received.freq,
received.format, requested.format);

patchbayRefresh(true, false, false);

@@ -195,7 +197,7 @@ public:
if (fDeviceId != 0)
{
// SDL_PauseAudioDevice(fDeviceId, 1);
#ifdef HAVE_SDL2_CALLS
#ifdef HAVE_SDL2
SDL_CloseAudioDevice(fDeviceId);
#else
SDL_CloseAudio();


+ 1
- 1
source/tests/Makefile View File

@@ -146,7 +146,7 @@ carla-engine-sdl$(APP_EXT): $(OBJDIR)/carla-engine-sdl.c.o
$(MODULEDIR)/water.a \
$(MODULEDIR)/ysfx.a \
$(MODULEDIR)/zita-resampler.a \
-lSDL --preload-file foolme.mp3 -sALLOW_MEMORY_GROWTH \
$(SDL_LIBS) --preload-file foolme.mp3 -sALLOW_MEMORY_GROWTH \
-o $@

# ---------------------------------------------------------------------------------------------------------------------


+ 14
- 3
source/tests/carla-engine-sdl.c View File

@@ -26,10 +26,12 @@
static void engine_idle_loop(void* const arg)
{
const CarlaHostHandle handle = arg;
carla_engine_idle(handle);

/*
static int counter = 0;
if (++counter == 100)
{
carla_engine_idle(handle);
counter = 0;
const uint64_t frame = carla_get_current_transport_frame(handle);
printf("engine_idle_loop | play frame %llu | audio peaks %f %f\n",
@@ -37,6 +39,7 @@ static void engine_idle_loop(void* const arg)
carla_get_output_peak_value(handle, 0, true),
carla_get_output_peak_value(handle, 0, false));
}
*/
}

int main(void)
@@ -70,18 +73,26 @@ int main(void)
if (!engine_init)
return 1;

const bool plugin_added = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Music", "audiofile", 0, NULL, PLUGIN_OPTIONS_NULL);
const bool plugin_added = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Music", "audiofile", 0, NULL, 0x0);
printf("carla_add_plugin: %d\n", plugin_added);

if (!plugin_added)
goto close;

const bool plugin_added2 = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Gain", "audiogain_s", 0, NULL, 0x0);
printf("carla_add_plugin2: %d\n", plugin_added2);

if (!plugin_added2)
goto close;

const uint32_t current_plugins_count = carla_get_current_plugin_count(handle);
printf("carla_get_current_plugin_count: %u\n", current_plugins_count);

if (current_plugins_count != 1)
if (current_plugins_count != 2)
goto close;

carla_set_parameter_value(handle, 1, 0, 1.0f); // gain

carla_patchbay_connect(handle, false, 1, 3, 3, 1);
carla_patchbay_connect(handle, false, 1, 4, 3, 2);



Loading…
Cancel
Save