Added FdBufferExperiments: Proof of concept plugin for resizing buffers on server
parent
2d2e5b7fa7
commit
b4bcc2f1c6
@ -0,0 +1,114 @@
|
|||||||
|
####### added the eingenmf
|
||||||
|
set(FLUID_DECOMP_DIR ../../fluid_decomposition)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
"${FLUID_DECOMP_DIR}"
|
||||||
|
"${FLUID_DECOMP_DIR}/include"
|
||||||
|
"${FLUID_DECOMP_DIR}/3rdparty"
|
||||||
|
)
|
||||||
|
|
||||||
|
####### original SC Cmake file starts here
|
||||||
|
set(FILENAME "fdBufferExperiments.cpp") #specify the .cpp file here
|
||||||
|
cmake_minimum_required (VERSION 2.8)
|
||||||
|
get_filename_component(PROJECT ${FILENAME} NAME_WE) #automatically sets project name from the filename
|
||||||
|
message(STATUS "Project name is ${PROJECT}")
|
||||||
|
project (${PROJECT})
|
||||||
|
|
||||||
|
include_directories(${SC_PATH}/include/plugin_interface)
|
||||||
|
include_directories(${SC_PATH}/include/common)
|
||||||
|
include_directories(${SC_PATH}/common)
|
||||||
|
|
||||||
|
set(CMAKE_SHARED_MODULE_PREFIX "")
|
||||||
|
if(APPLE OR WIN32)
|
||||||
|
set(CMAKE_SHARED_MODULE_SUFFIX ".scx")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(SUPERNOVA "Build plugins for supernova" OFF)
|
||||||
|
if (SUPERNOVA)
|
||||||
|
include_directories(${SC_PATH}/external_libraries/nova-tt)
|
||||||
|
# actually just boost.atomic
|
||||||
|
include_directories(${SC_PATH}/external_libraries/boost)
|
||||||
|
include_directories(${SC_PATH}/external_libraries/boost_lockfree)
|
||||||
|
include_directories(${SC_PATH}/external_libraries/boost-lockfree)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(CPP11 "Build with c++11." ON)
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
|
set(CMAKE_COMPILER_IS_CLANG 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
|
||||||
|
add_definitions(-fvisibility=hidden)
|
||||||
|
|
||||||
|
include (CheckCCompilerFlag)
|
||||||
|
include (CheckCXXCompilerFlag)
|
||||||
|
|
||||||
|
CHECK_C_COMPILER_FLAG(-msse HAS_SSE)
|
||||||
|
CHECK_CXX_COMPILER_FLAG(-msse HAS_CXX_SSE)
|
||||||
|
|
||||||
|
if (HAS_SSE)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse")
|
||||||
|
endif()
|
||||||
|
if (HAS_CXX_SSE)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
CHECK_C_COMPILER_FLAG(-msse2 HAS_SSE2)
|
||||||
|
CHECK_CXX_COMPILER_FLAG(-msse2 HAS_CXX_SSE2)
|
||||||
|
|
||||||
|
if (HAS_SSE2)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
|
||||||
|
endif()
|
||||||
|
if (HAS_CXX_SSE2)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
CHECK_C_COMPILER_FLAG(-mfpmath=sse HAS_FPMATH_SSE)
|
||||||
|
CHECK_CXX_COMPILER_FLAG(-mfpmath=sse HAS_CXX_FPMATH_SSE)
|
||||||
|
|
||||||
|
if (HAS_FPMATH_SSE)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpmath=sse")
|
||||||
|
endif()
|
||||||
|
if (HAS_CXX_FPMATH_SSE)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NATIVE)
|
||||||
|
add_definitions(-march=native)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CPP11)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
if(CMAKE_COMPILER_IS_CLANG)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if(MINGW)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstackrealign")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
####### added the fluid_decomposition
|
||||||
|
add_library(
|
||||||
|
${PROJECT}
|
||||||
|
MODULE
|
||||||
|
${FILENAME}
|
||||||
|
"${FLUID_DECOMP_DIR}/3rdparty/HISSTools_FFT/HISSTools_FFT.cpp"
|
||||||
|
)
|
||||||
|
if(SUPERNOVA)
|
||||||
|
add_library(${PROJECT}_supernova MODULE ${FILENAME})
|
||||||
|
set_property(TARGET ${PROJECT}_supernova
|
||||||
|
PROPERTY COMPILE_DEFINITIONS SUPERNOVA)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
TARGET
|
||||||
|
${PROJECT}
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory "../../release-packaging/${PROJECT}/plugins"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT}> "../../release-packaging/${PROJECT}/plugins"
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries (${PROJECT} "-framework Accelerate")
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
//Can I reallocate buffers on the server? Yes I can.
|
||||||
|
#include "SC_PlugIn.h"
|
||||||
|
|
||||||
|
static InterfaceTable *ft;
|
||||||
|
|
||||||
|
//Can we do buffer resizing in a BufGen. I think so.
|
||||||
|
//Goal here is to mimic the NMF case, allowing
|
||||||
|
//the dst buffer to be resized accordingly (and not need to
|
||||||
|
// precalculate the number of frames in advance lang-side
|
||||||
|
void BufferMatch(World *world, struct SndBuf *srcBuf, struct sc_msg_iter *msg)
|
||||||
|
{
|
||||||
|
size_t srcFrameCount = srcBuf->frames;
|
||||||
|
size_t srcChanCount = srcBuf->channels;
|
||||||
|
|
||||||
|
long dstBufNum = msg->geti();
|
||||||
|
size_t rank = msg->geti();
|
||||||
|
|
||||||
|
if (dstBufNum == -1){
|
||||||
|
Print("BufferMatch is not happy because there is no output buffer specified.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//This sequence follows what I saw in SC_SequenceCommand.cpp. Pretty much.
|
||||||
|
//Get the NRT thread mirror buffer
|
||||||
|
SndBuf* dstBufNRT = World_GetNRTBuf(world, dstBufNum);
|
||||||
|
//Call the allocation function on that
|
||||||
|
SCErr err = ft->fBufAlloc(dstBufNRT, srcChanCount * rank, srcFrameCount,srcBuf->samplerate);
|
||||||
|
//If we were posh, we'd check for errors
|
||||||
|
//Norhing will happen, unless we (a) assign the allocated data back to the main buffer pool (b?) Tell the server the buffer has changed
|
||||||
|
//Get the RT buffer
|
||||||
|
SndBuf* dstBuf = World_GetBuf(world, dstBufNum);
|
||||||
|
//Assign value to our NRT buffer pointer's value
|
||||||
|
*dstBuf = *dstBufNRT;
|
||||||
|
//Ping the server
|
||||||
|
world->mSndBufUpdates[dstBufNum].writes ++ ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//typedef void (*BufGenFunc)(struct World *world, struct SndBuf *buf, struct sc_msg_iter *msg);
|
||||||
|
|
||||||
|
|
||||||
|
PluginLoad(BufferFunTime) {
|
||||||
|
ft = inTable;
|
||||||
|
DefineBufGen("BufMatch", BufferMatch);
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
s.reboot
|
||||||
|
|
||||||
|
//Quickie test of buffer allocation working
|
||||||
|
//Read a sound file
|
||||||
|
a = Buffer.read(s,"/Users/owen/Desktop/denoise_stn/sources/01-mix.wav");
|
||||||
|
//Pass buffer to this, along with a rank. It will allocate a new buffer,
|
||||||
|
//size it appropriately (in our server code) and return the new object
|
||||||
|
f = FDBufferExperiments.allocMatch(s,a,rank:5);
|
||||||
|
//Make sure everything is kosher:
|
||||||
|
a.query
|
||||||
|
f.query
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
// adds an instance method to the Buffer class
|
||||||
|
FDBufferExperiments {
|
||||||
|
|
||||||
|
*allocMatch{|server, srcbuf, rank=1|
|
||||||
|
var dstbuf,srcbufnum;
|
||||||
|
"Rank" + rank.postln;
|
||||||
|
srcbufnum = srcbuf.bufnum;
|
||||||
|
|
||||||
|
server = server ? Server.default;
|
||||||
|
dstbuf = Buffer.new(server:server,numFrames:0,numChannels:1);
|
||||||
|
|
||||||
|
server.listSendMsg(
|
||||||
|
[\b_gen, srcbufnum, "BufMatch",dstbuf.bufnum, rank]
|
||||||
|
);
|
||||||
|
^dstbuf;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue